Skip to content

TraceRegistry

Process-global store of telemetry configuration AND (once TelemetryBootstrap has run) the worker-lifetime tracer/meter provider singletons.

Deliberately free of any dependency on Config/the context/bootstrap (mirrors LogRegistry, which plays the same role for sinks) so it can be configured in index.php before Kernel::run() and is safe to call during bootstrap itself.

The TracerProviderInterface/MeterProviderInterface type hints below reference optional open-telemetry/* classes — those packages are suggest-only, never a hard dependency. PHP resolves parameter/return types lazily at call time, not at class-load time, so this file loads safely even when the SDK isn’t installed; TraceRegistry::setProviders() and the accessors below are simply never called in that case (guarded by TelemetryBootstrap’s own class_exists() check).

final class TraceRegistry

SourceTelemetry/TraceRegistry.php
MethodDescription
hasRealProvider(): boolWhether TraceRegistry::setProviders() has installed a real tracer provider.
isCategoryEnabled(string $category): boolWhether spans in $category should be recorded.
isEnabled(): boolWhether the process-wide master switch is on.
meter(): ?MeterInterfaceThe single shared Meter instance for the worker’s lifetime, or null if unconfigured.
meterHandle(): ?OtelMeterHandleThe single shared OtelMeterHandle for the worker’s lifetime — cached here (rather than rebuilt per Trace::metrics() call) so its internal per-instrument-name cache (histograms/counters/gauges) survives across calls instead of recreating SDK instrument objects every time.
meterProvider(): ?MeterProviderInterfaceThe installed meter provider, or null when none has been configured for this worker.
reset(): voidReset all configuration and drop the provider singletons.
setCategories(array<string, bool> $map): void
setCategoryEnabled(string $categoryPrefix, bool $enabled): voidEnables or disables a dot-namespaced category prefix, and discards the memoized per-category resolutions so the change takes effect immediately.
setDefaultCategoryEnabled(bool $enabled): voidSets the answer TraceRegistry::isCategoryEnabled() gives a category with no matching entry anywhere on its prefix chain, and discards the memoized resolutions so the change takes effect immediately.
setEnabled(bool $enabled): voidSets the process-wide master switch for telemetry.
setProviders(TracerProviderInterface $tracerProvider, MeterProviderInterface $meterProvider): voidInstall the worker-lifetime provider singletons.
tracer(): ?TracerInterfaceThe single shared Tracer instance for the worker’s lifetime, or null if unconfigured.
tracerProvider(): ?TracerProviderInterfaceThe installed tracer provider, or null when none has been configured for this worker.

public static function hasRealProvider(): bool

Whether TraceRegistry::setProviders() has installed a real tracer provider.

False whenever telemetry was never configured, was disabled, the OpenTelemetry SDK is not installed, or provider construction failed — which is why callers such as Trace::current() check it before touching any OTel class.

Returns bool

public static function isCategoryEnabled(string $category): bool

Whether spans in $category should be recorded.

Deliberately NOT the same algorithm as LogRegistry::resolveLevel(): logging lets a more specific child override its parent (longest-prefix-wins); this is a cascade instead — a disabled ancestor (or the category itself) wins unconditionally, so a descendant’s own explicit true cannot re-enable it. That’s what makes disabling a category a real “turn off this whole * subtree” kill switch rather than an exercise in enumerating every leaf. Only once nothing on the chain is disabled does longest-prefix matching against explicit true entries apply, falling back to $defaultCategoryEnabled. Memoized per exact category string.

ParameterTypeDescription
$categorystring

Returns bool

public static function isEnabled(): bool

Whether the process-wide master switch is on.

Off until something sets it.

Returns bool

public static function meter(): ?MeterInterface

The single shared Meter instance for the worker’s lifetime, or null if unconfigured.

Returns ?``MeterInterface

public static function meterHandle(): ?OtelMeterHandle

The single shared OtelMeterHandle for the worker’s lifetime — cached here (rather than rebuilt per Trace::metrics() call) so its internal per-instrument-name cache (histograms/counters/gauges) survives across calls instead of recreating SDK instrument objects every time.

Returns ?OtelMeterHandle

public static function meterProvider(): ?MeterProviderInterface

The installed meter provider, or null when none has been configured for this worker.

Callers wanting a meter should use TraceRegistry::meter(), which caches the single shared instance.

Returns ?``MeterProviderInterface

public static function reset(): void

Reset all configuration and drop the provider singletons.

For test isolation/reconfiguration (simulating a fresh worker); not used on the request path.

public static function setCategories(array<string, bool> $map): void

category-prefix => enabled

ParameterTypeDescription
$maparray``<``string``, ``bool``>category-prefix => enabled

public static function setCategoryEnabled(string $categoryPrefix, bool $enabled): void

Enables or disables a dot-namespaced category prefix, and discards the memoized per-category resolutions so the change takes effect immediately.

A false entry cascades unconditionally over the whole subtree beneath the prefix; see TraceRegistry::isCategoryEnabled() for the full resolution rules.

ParameterTypeDescription
$categoryPrefixstring
$enabledbool

public static function setDefaultCategoryEnabled(bool $enabled): void

Sets the answer TraceRegistry::isCategoryEnabled() gives a category with no matching entry anywhere on its prefix chain, and discards the memoized resolutions so the change takes effect immediately.

True until set otherwise, so categories record unless something opts them out.

ParameterTypeDescription
$enabledbool

public static function setEnabled(bool $enabled): void

Sets the process-wide master switch for telemetry.

Only stores the flag; providers, categories and their memoized resolutions are untouched, so turning telemetry back on resumes with the same configuration. Trace consults this before every operation.

ParameterTypeDescription
$enabledbool

public static function setProviders(TracerProviderInterface $tracerProvider, MeterProviderInterface $meterProvider): void

Install the worker-lifetime provider singletons.

Called exactly once per worker by TelemetryBootstrap::configureFromConfig().

ParameterTypeDescription
$tracerProviderTracerProviderInterface
$meterProviderMeterProviderInterface

public static function tracer(): ?TracerInterface

The single shared Tracer instance for the worker’s lifetime, or null if unconfigured.

Returns ?``TracerInterface

public static function tracerProvider(): ?TracerProviderInterface

The installed tracer provider, or null when none has been configured for this worker.

Callers wanting a tracer should use TraceRegistry::tracer(), which caches the single shared instance.

Returns ?``TracerProviderInterface