Skip to content

NoopSpanHandle

The disabled-state SpanHandle: every call is a safe no-op.

A single shared instance is reused (NoopSpanHandle::instance()) so instrumenting a call site costs no allocation whether telemetry is globally off, a trace category is filtered out, or no real tracer has been wired up yet.

final class NoopSpanHandle implements SpanHandle

ImplementsSpanHandle
SourceTelemetry/NoopSpanHandle.php
MethodDescription
addEvent(string $name, array $attributes = []): staticDiscards the event and returns $this.
end(): voidDoes nothing; there is no span to end.
instance(): NoopSpanHandleThe shared no-op span handle, created on first call and reused for the rest of the process.
recordException(Throwable $e): staticDiscards the exception and returns $this; nothing is exported.
setAttribute(string $key, mixed $value): staticDiscards the attribute and returns $this.
setAttributes(array $attributes): staticDiscards the attributes and returns $this.
setStatusError(?string $description = null): staticDiscards the error status and returns $this.
spanId(): ?stringAlways null — a no-op span has no trace context.
traceId(): ?stringAlways null — a no-op span has no trace context.
updateName(string $name): staticDiscards the new name and returns $this.

public function addEvent(string $name, array $attributes = []): static

Discards the event and returns $this.

ParameterTypeDescription
$namestring
$attributesarray

Returns static

public function end(): void

Does nothing; there is no span to end.

public static function instance(): NoopSpanHandle

The shared no-op span handle, created on first call and reused for the rest of the process.

Safe to hand out freely: it is stateless, owns no span lifecycle, and every call on it is discarded.

Returns NoopSpanHandle

public function recordException(Throwable $e): static

Discards the exception and returns $this; nothing is exported.

ParameterTypeDescription
$eThrowable

Returns static

public function setAttribute(string $key, mixed $value): static

Discards the attribute and returns $this.

ParameterTypeDescription
$keystring
$valuemixed

Returns static

public function setAttributes(array $attributes): static

Discards the attributes and returns $this.

ParameterTypeDescription
$attributesarray

Returns static

public function setStatusError(?string $description = null): static

Discards the error status and returns $this.

ParameterTypeDescription
$description?``string

Returns static

public function spanId(): ?string

Always null — a no-op span has no trace context.

Returns ?``string

public function traceId(): ?string

Always null — a no-op span has no trace context.

Returns ?``string

public function updateName(string $name): static

Discards the new name and returns $this.

ParameterTypeDescription
$namestring

Returns static