SpanId implements Stringable
An 8-byte (64-bit) span identifier compatible with OpenTelemetry W3C Trace Context.
SpanIds uniquely identify a span within a trace. An all-zero SpanId is considered "invalid" and indicates no active span.
Example usage:
$spanId = SpanId::generate();
echo $spanId->toHex(); // "00f067aa0ba902b7"
// Invalid span ID (all zeros)
$invalid = SpanId::invalid();
echo $invalid->isValid(); // false
Interfaces
- Stringable
Constants
- INVALID = '0000000000000000'
Methods
- __toString() : string
- equals() : bool
- Check if this SpanId equals another SpanId.
- fromArray() : self
- Create a SpanId from a normalized array representation.
- fromBytes() : self
- Create a SpanId from 8 raw bytes.
- fromHex() : self
- Create a SpanId from a 16-character hexadecimal string.
- generate() : self
- Generate a new random SpanId.
- invalid() : self
- Get an invalid SpanId (all zeros).
- isValid() : bool
- Check if this SpanId is valid (not all zeros).
- normalize() : array{hex: string}
- Normalize the SpanId to an array representation for serialization.
- toBytes() : string
- Get the SpanId as 8 raw bytes.
- toHex() : string
- Get the SpanId as a 16-character lowercase hexadecimal string.
Constants
INVALID
public
mixed
INVALID
= '0000000000000000'
Methods
__toString()
public
__toString() : string
Return values
stringequals()
Check if this SpanId equals another SpanId.
public
equals(self $other) : bool
Parameters
- $other : self
Return values
boolfromArray()
Create a SpanId from a normalized array representation.
public
static fromArray(array{hex: string} $data) : self
Parameters
- $data : array{hex: string}
-
Normalized SpanId data
Tags
Return values
selffromBytes()
Create a SpanId from 8 raw bytes.
public
static fromBytes(string $bytes) : self
Parameters
- $bytes : string
-
8 raw bytes
Tags
Return values
selffromHex()
Create a SpanId from a 16-character hexadecimal string.
public
static fromHex(string $hex) : self
Parameters
- $hex : string
-
16-character lowercase hexadecimal string
Tags
Return values
selfgenerate()
Generate a new random SpanId.
public
static generate() : self
Return values
selfinvalid()
Get an invalid SpanId (all zeros).
public
static invalid() : self
Invalid SpanIds indicate no active span context.
Return values
selfisValid()
Check if this SpanId is valid (not all zeros).
public
isValid() : bool
An all-zero SpanId indicates no active span context.
Return values
boolnormalize()
Normalize the SpanId to an array representation for serialization.
public
normalize() : array{hex: string}
Return values
array{hex: string}toBytes()
Get the SpanId as 8 raw bytes.
public
toBytes() : string
Return values
stringtoHex()
Get the SpanId as a 16-character lowercase hexadecimal string.
public
toHex() : string