Context
FinalYes
Telemetry context carrier holding the active span and baggage.
Follows the OpenTelemetry context model: a Context either carries the currently active span (its SpanContext) — making the next span its child within the same trace — or carries none, making the next span a new trace root. Trace id is always derived from the active span; it is never stored independently.
Example usage:
$context = Context::root();
$context = $context->withActiveSpan($span->context());
echo $context->traceId()?->toHex();
Properties
- $activeSpan : SpanContext|null
- $baggage : Baggage
- $suppressed : bool
Methods
- __construct() : mixed
- activeSpan() : SpanContext|null
- activeSpanId() : SpanId|null
- fromArray() : self
- isRootContext() : bool
- isTracingSuppressed() : bool
- Whether tracing is suppressed within this context: spans are created non-recording (never sampled, never exported). Metrics and logs are unaffected, matching OpenTelemetry's tracing-scoped suppression.
-
normalize()
: array{activeSpan: null|array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags: array{byte: int}, traceState: array{entries: array
}}, baggage: array{entries: array }} - root() : self
- traceId() : TraceId|null
- withActiveSpan() : self
- withBaggage() : self
- withoutActiveSpan() : self
- withoutSuppressedTracing() : self
- withSuppressedTracing() : self
Properties
$activeSpan read-only
public
SpanContext|null
$activeSpan
= null
$baggage read-only
public
Baggage
$baggage
= new Baggage()
$suppressed read-only
public
bool
$suppressed
= false
Methods
__construct()
public
__construct([SpanContext|null $activeSpan = null ][, Baggage $baggage = new Baggage() ][, bool $suppressed = false ]) : mixed
Parameters
- $activeSpan : SpanContext|null = null
- $baggage : Baggage = new Baggage()
- $suppressed : bool = false
activeSpan()
public
activeSpan() : SpanContext|null
Return values
SpanContext|nullactiveSpanId()
public
activeSpanId() : SpanId|null
Return values
SpanId|nullfromArray()
public
static fromArray(array{activeSpan: null|array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags?: array{byte: int}, traceState?: array{entries: array}}, baggage: array{entries: array}} $data) : self
Parameters
-
$data
: array{activeSpan: null|array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags?: array{byte: int}, traceState?: array{entries: array
}}, baggage: array{entries: array }}
Return values
selfisRootContext()
public
isRootContext() : bool
Return values
boolisTracingSuppressed()
Whether tracing is suppressed within this context: spans are created non-recording (never sampled, never exported). Metrics and logs are unaffected, matching OpenTelemetry's tracing-scoped suppression.
public
isTracingSuppressed() : bool
Return values
boolnormalize()
public
normalize() : array{activeSpan: null|array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags: array{byte: int}, traceState: array{entries: array}}, baggage: array{entries: array}}
Return values
array{activeSpan: null|array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags: array{byte: int}, traceState: array{entries: arrayroot()
public
static root() : self
Return values
selftraceId()
public
traceId() : TraceId|null
Return values
TraceId|nullwithActiveSpan()
public
withActiveSpan(SpanContext $span) : self
Parameters
- $span : SpanContext
Return values
selfwithBaggage()
public
withBaggage(Baggage $baggage) : self
Parameters
- $baggage : Baggage
Return values
selfwithoutActiveSpan()
public
withoutActiveSpan() : self
Return values
selfwithoutSuppressedTracing()
public
withoutSuppressedTracing() : self
Return values
selfwithSuppressedTracing()
public
withSuppressedTracing() : self