TraceId implements Stringable
Read onlyYes
FinalYes
A 16-byte (128-bit) trace identifier compatible with OpenTelemetry W3C Trace Context.
TraceIds are used to correlate spans across service boundaries. All-zero TraceIds are rejected at construction time per W3C spec.
Example usage:
$traceId = TraceId::generate();
echo $traceId->toHex(); // "0af7651916cd43dd8448eb211c80319c"
Interfaces
- Stringable
Methods
- __toString() : string
- equals() : bool
- Check if this TraceId equals another TraceId.
- fromArray() : self
- Create a TraceId from a normalized array representation.
- fromBytes() : self
- Create a TraceId from 16 raw bytes.
- fromHex() : self
- Create a TraceId from a 32-character hexadecimal string.
- generate() : self
- Generate a new random TraceId.
- normalize() : array{hex: string}
- Normalize the TraceId to an array representation for serialization.
- toBytes() : string
- Get the TraceId as 16 raw bytes.
- toHex() : string
- Get the TraceId as a 32-character lowercase hexadecimal string.
Methods
__toString()
public
__toString() : string
Return values
stringequals()
Check if this TraceId equals another TraceId.
public
equals(self $other) : bool
Parameters
- $other : self
Return values
boolfromArray()
Create a TraceId from a normalized array representation.
public
static fromArray(array{hex: string} $data) : self
Parameters
- $data : array{hex: string}
-
Normalized TraceId data
Tags
Return values
selffromBytes()
Create a TraceId from 16 raw bytes.
public
static fromBytes(string $bytes) : self
Parameters
- $bytes : string
-
16 raw bytes
Tags
Return values
selffromHex()
Create a TraceId from a 32-character hexadecimal string.
public
static fromHex(string $hex) : self
Parameters
- $hex : string
-
32-character lowercase hexadecimal string
Tags
Return values
selfgenerate()
Generate a new random TraceId.
public
static generate() : self
Return values
selfnormalize()
Normalize the TraceId to an array representation for serialization.
public
normalize() : array{hex: string}
Return values
array{hex: string}toBytes()
Get the TraceId as 16 raw bytes.
public
toBytes() : string
Return values
stringtoHex()
Get the TraceId as a 32-character lowercase hexadecimal string.
public
toHex() : string