TraceFlags implements Stringable
W3C Trace Context trace flags (single byte).
TraceFlags contain information about the trace. Currently defined flags:
- SAMPLED (bit 0): Whether the trace should be sampled/exported
- RANDOM (bit 1): Whether the trace-id was randomly generated
Example usage:
$flags = TraceFlags::default();
$flags = $flags->withSampled(true);
echo $flags->toHex(); // "01"
Tags
Interfaces
- Stringable
Constants
Methods
- __toString() : string
- default() : self
- Create TraceFlags with default values (no flags set).
- equals() : bool
- Check if this TraceFlags equals another TraceFlags.
- fromArray() : self
- Create TraceFlags from a normalized array representation.
- fromByte() : self
- Create TraceFlags from a byte value.
- fromHex() : self
- Create TraceFlags from a 2-character hexadecimal string.
- isRandom() : bool
- Check if the RANDOM flag is set.
- isSampled() : bool
- Check if the SAMPLED flag is set.
- normalize() : array{byte: int}
- Normalize the TraceFlags to an array representation for serialization.
- sampled() : self
- Create TraceFlags with SAMPLED flag set.
- toByte() : int
- Get the flags as a byte value.
- toHex() : string
- Get the flags as a 2-character lowercase hexadecimal string.
- withRandom() : self
- Create a new TraceFlags with the RANDOM flag set or unset.
- withSampled() : self
- Create a new TraceFlags with the SAMPLED flag set or unset.
Constants
RANDOM
public
mixed
RANDOM
= 0x2
SAMPLED
public
mixed
SAMPLED
= 0x1
Methods
__toString()
public
__toString() : string
Return values
stringdefault()
Create TraceFlags with default values (no flags set).
public
static default() : self
Return values
selfequals()
Check if this TraceFlags equals another TraceFlags.
public
equals(self $other) : bool
Parameters
- $other : self
Return values
boolfromArray()
Create TraceFlags from a normalized array representation.
public
static fromArray(array{byte: int} $data) : self
Parameters
- $data : array{byte: int}
-
Normalized TraceFlags data
Return values
selffromByte()
Create TraceFlags from a byte value.
public
static fromByte(int $byte) : self
Parameters
- $byte : int
-
The flags byte (0-255)
Tags
Return values
selffromHex()
Create TraceFlags from a 2-character hexadecimal string.
public
static fromHex(string $hex) : self
Parameters
- $hex : string
-
2-character lowercase hexadecimal string
Tags
Return values
selfisRandom()
Check if the RANDOM flag is set.
public
isRandom() : bool
Return values
boolisSampled()
Check if the SAMPLED flag is set.
public
isSampled() : bool
Return values
boolnormalize()
Normalize the TraceFlags to an array representation for serialization.
public
normalize() : array{byte: int}
Return values
array{byte: int}sampled()
Create TraceFlags with SAMPLED flag set.
public
static sampled() : self
Return values
selftoByte()
Get the flags as a byte value.
public
toByte() : int
Return values
inttoHex()
Get the flags as a 2-character lowercase hexadecimal string.
public
toHex() : string
Return values
stringwithRandom()
Create a new TraceFlags with the RANDOM flag set or unset.
public
withRandom([bool $random = true ]) : self
Parameters
- $random : bool = true
Return values
selfwithSampled()
Create a new TraceFlags with the SAMPLED flag set or unset.
public
withSampled([bool $sampled = true ]) : self
Parameters
- $sampled : bool = true