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
Methods
- __construct() : mixed
- activeSpan() : SpanContext|null
- activeSpanId() : SpanId|null
- fromArray() : self
- isRootContext() : bool
-
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
Properties
$activeSpan read-only
public
SpanContext|null
$activeSpan
= null
$baggage read-only
public
Baggage
$baggage
= new Baggage()
Methods
__construct()
public
__construct([SpanContext|null $activeSpan = null ][, Baggage $baggage = new Baggage() ]) : mixed
Parameters
- $activeSpan : SpanContext|null = null
- $baggage : Baggage = new Baggage()
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
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