Flow PHP

Context

FinalYes

Telemetry context carrier holding trace information and baggage.

Context is the main carrier for propagating telemetry data across process boundaries and through the application. It holds:

  • A TraceId that correlates all spans in a trace
  • An optional active SpanId for the currently executing span
  • Baggage for arbitrary key-value data propagation

Example usage:

$context = Context::create();
$context = $context->withActiveSpan(SpanId::generate());
echo $context->traceId->toHex();

Properties

$baggage  : Baggage
$traceId  : TraceId

Methods

__construct()  : mixed
activeSpanId()  : null|SpanId
Get the currently active span ID, if any.
create()  : self
Create a new Context with a fresh TraceId.
fromArray()  : self
Create a Context from a normalized array representation.
isRootContext()  : bool
Check if this is a root context (no active span).
normalize()  : array{traceId: array{hex: string}, baggage: array{entries: array}, activeSpanId: null|array{hex: string}}
Normalize the Context to an array representation for serialization.
withActiveSpan()  : self
Create a new Context with the specified active span.
withBaggage()  : self
Create a new Context with the specified baggage.
withoutActiveSpan()  : self
Create a new Context with no active span.
withTraceId()  : self
Create a new Context with the specified TraceId.

Properties

Methods

activeSpanId()

Get the currently active span ID, if any.

public activeSpanId() : null|SpanId
Return values
null|SpanId

The active span ID, or null if no span is active

create()

Create a new Context with a fresh TraceId.

public static create() : self
Return values
self

fromArray()

Create a Context from a normalized array representation.

public static fromArray(array{traceId: array{hex: string}, baggage: array{entries: array}, activeSpanId: null|array{hex: string}} $data) : self
Parameters
$data : array{traceId: array{hex: string}, baggage: array{entries: array}, activeSpanId: null|array{hex: string}}

Normalized Context data

Return values
self

isRootContext()

Check if this is a root context (no active span).

public isRootContext() : bool

A root context has no active span, meaning any new span created in this context would be a root span.

Return values
bool

normalize()

Normalize the Context to an array representation for serialization.

public normalize() : array{traceId: array{hex: string}, baggage: array{entries: array}, activeSpanId: null|array{hex: string}}
Return values
array{traceId: array{hex: string}, baggage: array{entries: array}, activeSpanId: null|array{hex: string}}

withActiveSpan()

Create a new Context with the specified active span.

public withActiveSpan(SpanId $spanId) : self
Parameters
$spanId : SpanId

The span ID to set as active

Return values
self

New Context instance with the active span set

withBaggage()

Create a new Context with the specified baggage.

public withBaggage(Baggage $baggage) : self
Parameters
$baggage : Baggage

The baggage to use

Return values
self

New Context instance with the new baggage

withoutActiveSpan()

Create a new Context with no active span.

public withoutActiveSpan() : self
Return values
self

New Context instance with no active span

withTraceId()

Create a new Context with the specified TraceId.

public static withTraceId(TraceId $traceId) : self
Parameters
$traceId : TraceId

The trace ID to use

Return values
self

        
On this page

Search results