Flow PHP

SpanContext

Read onlyYes
FinalYes

Immutable identification of a span within a trace.

SpanContext carries the identifying information that makes a span unique within a trace: the trace ID, span ID, and optional parent span ID. It also tracks whether the span originated from a remote process, and includes trace flags and vendor-specific trace state.

Example usage:

$context = SpanContext::create(
    TraceId::generate(),
    SpanId::generate(),
);
echo $context->traceId->toHex();
echo $context->traceFlags->isSampled() ? 'sampled' : 'not sampled';

Properties

$isRemote  : bool
$parentSpanId  : SpanId|null
$spanId  : SpanId
$traceFlags  : TraceFlags
$traceId  : TraceId
$traceState  : TraceState

Methods

__construct()  : mixed
create()  : self
Create a local SpanContext.
createRemote()  : self
Create a remote SpanContext (received from another process).
fromArray()  : self
Create a SpanContext from a normalized array representation.
isRoot()  : bool
Check if this is a root span (no parent).
isValid()  : bool
Check if this SpanContext has valid trace and span IDs.
normalize()  : array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags: array{byte: int}, traceState: array{entries: array}}
Normalize the SpanContext to an array representation for serialization.
withTraceFlags()  : self
Create a new SpanContext with the specified trace flags.
withTraceState()  : self
Create a new SpanContext with the specified trace state.

Properties

Methods

fromArray()

Create a SpanContext from a normalized array representation.

public static fromArray(array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags?: array{byte: int}, traceState?: array{entries: array}} $data) : self
Parameters
$data : array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags?: array{byte: int}, traceState?: array{entries: array}}

Normalized SpanContext data

Return values
self

isRoot()

Check if this is a root span (no parent).

public isRoot() : bool
Return values
bool

isValid()

Check if this SpanContext has valid trace and span IDs.

public isValid() : bool

A SpanContext is valid when both the trace ID and span ID are non-zero. Note: SpanId and TraceId already reject all-zero values at construction, so any successfully created SpanContext is valid by construction.

Return values
bool

normalize()

Normalize the SpanContext to an array representation for serialization.

public normalize() : array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags: array{byte: int}, traceState: array{entries: array}}
Return values
array{traceId: array{hex: string}, spanId: array{hex: string}, parentSpanId: null|array{hex: string}, isRemote: bool, traceFlags: array{byte: int}, traceState: array{entries: array}}

withTraceFlags()

Create a new SpanContext with the specified trace flags.

public withTraceFlags(TraceFlags $traceFlags) : self
Parameters
$traceFlags : TraceFlags
Return values
self

withTraceState()

Create a new SpanContext with the specified trace state.

public withTraceState(TraceState $traceState) : self
Parameters
$traceState : TraceState
Return values
self

        
On this page

Search results