TraceState implements Stringable
W3C Trace Context tracestate header value.
TraceState provides vendor-specific trace identification data and enables multiple tracing systems to participate in the same trace. It's an immutable list of key-value pairs with ordering preserved.
Example usage:
$state = TraceState::empty();
$state = $state->with('vendor', 'value');
echo $state->toString(); // "vendor=value"
Tags
Interfaces
- Stringable
Methods
- __toString() : string
- all() : array<string, string>
- Get all entries as an array.
- empty() : self
- Create an empty TraceState.
- equals() : bool
- Check if this TraceState equals another TraceState.
- fromArray() : self
- Create TraceState from a normalized array representation.
- fromString() : self
- Create TraceState from W3C tracestate header string.
- get() : null|string
- Get a value by key.
- isEmpty() : bool
- Check if this TraceState has any entries.
-
normalize()
: array{entries: array
} - Normalize the TraceState to an array representation for serialization.
- toString() : string
- Convert to W3C tracestate header string.
- with() : self
- Create a new TraceState with a key-value pair added or updated.
- without() : self
- Create a new TraceState with a key removed.
Methods
__toString()
public
__toString() : string
Return values
stringall()
Get all entries as an array.
public
all() : array<string, string>
Return values
array<string, string>empty()
Create an empty TraceState.
public
static empty() : self
Return values
selfequals()
Check if this TraceState equals another TraceState.
public
equals(self $other) : bool
Parameters
- $other : self
Return values
boolfromArray()
Create TraceState from a normalized array representation.
public
static fromArray(array{entries: array} $data) : self
Parameters
-
$data
: array{entries: array
} -
Normalized TraceState data
Return values
selffromString()
Create TraceState from W3C tracestate header string.
public
static fromString(string $string) : self
Parameters
- $string : string
-
W3C tracestate header value
Tags
Return values
selfget()
Get a value by key.
public
get(string $key) : null|string
Parameters
- $key : string
Return values
null|string —The value or null if not found
isEmpty()
Check if this TraceState has any entries.
public
isEmpty() : bool
Return values
boolnormalize()
Normalize the TraceState to an array representation for serialization.
public
normalize() : array{entries: array}
Return values
array{entries: arraytoString()
Convert to W3C tracestate header string.
public
toString() : string
Return values
stringwith()
Create a new TraceState with a key-value pair added or updated.
public
with(string $key, string $value) : self
New entries are added at the beginning (most recent position).
Parameters
- $key : string
- $value : string
Tags
Return values
selfwithout()
Create a new TraceState with a key removed.
public
without(string $key) : self
Parameters
- $key : string