Skip to content

TelemetryProviderFactory

Assembles the TracerProvider and MeterProvider: the resource describing this service, the sampler, the span processor, and the metric reader.

Takes its exporters from a TelemetryExporterFactory rather than building them, so which exporter is in use and how the providers are wired around it stay separable — a caller can assemble providers over an in-memory exporter without any OTLP configuration existing.

final readonly class TelemetryProviderFactory

Since3.2.0
SourceTelemetryProviderFactory.php

public function __construct(TelemetryConfig $config, TelemetryExporterFactory $exporters): mixed

ParameterTypeDescription
$configTelemetryConfig
$exportersTelemetryExporterFactory

Returns mixed

MethodDescription
meterProvider(ResourceInfo $resource): MeterProviderInterfaceBuilds a MeterProvider over $resource, reading through an ExportingReader wrapped around the configured metric exporter.
resource(): ResourceInfoThe resource every span and metric is attributed to: service name, optional namespace, and whatever telemetry.resource adds, merged over the SDK’s own detected defaults.
sampler(): SamplerInterfaceHead-based sampling, wrapped so a span can force itself to be recorded.
tracerProvider(ResourceInfo $resource): TracerProviderInterfaceBuilds a TracerProvider over $resource and the configured sampler.

public function meterProvider(ResourceInfo $resource): MeterProviderInterface

Builds a MeterProvider over $resource, reading through an ExportingReader wrapped around the configured metric exporter.

Sampling does not apply to metrics.

ParameterTypeDescription
$resourceResourceInfo

Returns MeterProviderInterface

public function resource(): ResourceInfo

The resource every span and metric is attributed to: service name, optional namespace, and whatever telemetry.resource adds, merged over the SDK’s own detected defaults.

Returns ResourceInfo

public function sampler(): SamplerInterface

Head-based sampling, wrapped so a span can force itself to be recorded.

Metrics are never sampled — this only affects the TracerProvider.

Returns SamplerInterface

public function tracerProvider(ResourceInfo $resource): TracerProviderInterface

Builds a TracerProvider over $resource and the configured sampler.

Spans go through a SimpleSpanProcessor when telemetry.export_mode is simple (each span exported as it ends, which tests rely on) and a BatchSpanProcessor otherwise.

ParameterTypeDescription
$resourceResourceInfo

Returns TracerProviderInterface