Skip to content

Trace

Static facade for the telemetry subsystem (mirrors Log).

Configuration: TelemetryBootstrap::configureFromConfig() builds the real provider from telemetry.* settings once per worker (called from Kernel::bootstrap()). Until that has run — or if it declined because telemetry is disabled, the SDK isn’t installed, or construction failed — every method below resolves to a shared no-op handle, so instrumenting a call site is always safe regardless of configuration state: use Quiote\Telemetry\Trace; $span = Trace::span(‘Quiote.Routing’, ‘match’); try { … } finally { $span->end(); }

final class Trace

SourceTelemetry/Trace.php
MethodDescription
current(): SpanHandleThe currently active span, or a no-op handle if none is open.
enabled(): boolWhether telemetry is switched on process-wide.
metrics(): MeterHandleThe handle for recording histograms, counters and gauges.
reset(): voidClears all telemetry state process-wide, via TraceRegistry::reset(): the enabled flag, the category map and its memoized resolutions, and the tracer/meter provider singletons.
setCategories(array<string, bool> $map): void
setCategoryEnabled(string $categoryPrefix, bool $enabled): voidEnable/disable a dot-namespaced trace category prefix (e.g.
setDefaultCategoryEnabled(bool $enabled): voidDefault for a category with no matching entry on its prefix chain.
setEnabled(bool $enabled): voidTurns telemetry on or off process-wide, via TraceRegistry.
span(string $category, string $name, array<string, mixed> $attributes = [], SpanKind $kind = Quiote\Telemetry\SpanKind::Internal): SpanHandleOpen a span.

public static function current(): SpanHandle

The currently active span, or a no-op handle if none is open.

This is a borrowed reference: the returned handle does not own the span’s lifecycle (ownsLifecycle: false), so letting it go out of scope — including as a bare expression like Trace::current()->recordException($e)->setStatusError(...);, whose temporary is destructed at the end of that statement — never ends the real span. Only whoever actually created it via Trace::span() can end it (explicitly, or via that handle’s own destructor). Getting this wrong previously caused a real, hard-to-spot bug: see the class docblock on OtelSpanHandle.

Returns SpanHandle

public static function enabled(): bool

Whether telemetry is switched on process-wide.

Says nothing about whether a real provider has been wired up — a true here with no provider still yields no-op handles.

Returns bool

public static function metrics(): MeterHandle

The handle for recording histograms, counters and gauges.

Returns the shared no-op meter when telemetry is disabled or no meter provider has been installed, so a call site can record unconditionally. Otherwise it is the worker-lifetime OtelMeterHandle cached in TraceRegistry, which keeps its per-instrument-name cache warm across calls.

Returns MeterHandle

public static function reset(): void

Clears all telemetry state process-wide, via TraceRegistry::reset(): the enabled flag, the category map and its memoized resolutions, and the tracer/meter provider singletons.

For test isolation and 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

Enable/disable a dot-namespaced trace category prefix (e.g.

“Quiote.Routing”), mirroring Log::setLevel() — except a disabled prefix cascades unconditionally to every descendant category, it cannot be re-enabled by a more specific child entry. Configured in index.php alongside Log::setLevels(...), not via settings.xml.

ParameterTypeDescription
$categoryPrefixstring
$enabledbool

public static function setDefaultCategoryEnabled(bool $enabled): void

Default for a category with no matching entry on its prefix chain.

True unless set otherwise.

ParameterTypeDescription
$enabledbool

public static function setEnabled(bool $enabled): void

Turns telemetry on or off process-wide, via TraceRegistry.

The master switch every method here consults first: while off, Trace::span()/Trace::current()/Trace::metrics() return shared no-op handles without touching the provider at all. Category settings and the installed providers are left as they are, so flipping it back on resumes with the same configuration.

ParameterTypeDescription
$enabledbool

public static function span(string $category, string $name, array<string, mixed> $attributes = [], SpanKind $kind = Quiote\Telemetry\SpanKind::Internal): SpanHandle

Open a span.

ParameterTypeDescription
$categorystring
$namestring
$attributesarray``<``string``, ``mixed``>
$kindSpanKind

Returns SpanHandle