Flow PHP

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. An all-zero TraceId is considered "invalid" and indicates no active trace.

Example usage:

$traceId = TraceId::generate();
echo $traceId->toHex(); // "0af7651916cd43dd8448eb211c80319c"

// Invalid trace ID (all zeros)
$invalid = TraceId::invalid();
echo $invalid->isValid(); // false

Interfaces

Stringable

Constants

INVALID  = '00000000000000000000000000000000'

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.
invalid()  : self
Get an invalid TraceId (all zeros).
isValid()  : bool
Check if this TraceId is valid (not all zeros).
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.

Constants

INVALID

public mixed INVALID = '00000000000000000000000000000000'

Methods

__toString()

public __toString() : string
Return values
string

equals()

Check if this TraceId equals another TraceId.

public equals(self $other) : bool
Parameters
$other : self
Return values
bool

fromArray()

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
throws
InvalidArgumentException

if the data is invalid

Return values
self

fromBytes()

Create a TraceId from 16 raw bytes.

public static fromBytes(string $bytes) : self
Parameters
$bytes : string

16 raw bytes

Tags
throws
InvalidArgumentException

if the byte string is not exactly 16 bytes

Return values
self

fromHex()

Create a TraceId from a 32-character hexadecimal string.

public static fromHex(string $hex) : self
Parameters
$hex : string

32-character lowercase hexadecimal string

Tags
throws
InvalidArgumentException

if the hex string is invalid

Return values
self

generate()

Generate a new random TraceId.

public static generate() : self
Return values
self

invalid()

Get an invalid TraceId (all zeros).

public static invalid() : self

Invalid TraceIds indicate no active trace context.

Return values
self

isValid()

Check if this TraceId is valid (not all zeros).

public isValid() : bool

An all-zero TraceId indicates no active trace context.

Return values
bool

normalize()

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
string

toHex()

Get the TraceId as a 32-character lowercase hexadecimal string.

public toHex() : string
Return values
string

        
On this page

Search results