Flow PHP

TraceFlags implements Stringable

Read onlyYes
FinalYes

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
see
https://www.w3.org/TR/trace-context/#trace-flags

Interfaces

Stringable

Constants

RANDOM  = 0x2
SAMPLED  = 0x1

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

Methods

__toString()

public __toString() : string
Return values
string

default()

Create TraceFlags with default values (no flags set).

public static default() : self
Return values
self

equals()

Check if this TraceFlags equals another TraceFlags.

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

fromArray()

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
self

fromByte()

Create TraceFlags from a byte value.

public static fromByte(int $byte) : self
Parameters
$byte : int

The flags byte (0-255)

Tags
throws
InvalidArgumentException

if the byte is out of range

Return values
self

fromHex()

Create TraceFlags from a 2-character hexadecimal string.

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

2-character lowercase hexadecimal string

Tags
throws
InvalidArgumentException

if the hex string is invalid

Return values
self

isRandom()

Check if the RANDOM flag is set.

public isRandom() : bool
Return values
bool

isSampled()

Check if the SAMPLED flag is set.

public isSampled() : bool
Return values
bool

normalize()

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
self

toByte()

Get the flags as a byte value.

public toByte() : int
Return values
int

toHex()

Get the flags as a 2-character lowercase hexadecimal string.

public toHex() : string
Return values
string

withRandom()

Create a new TraceFlags with the RANDOM flag set or unset.

public withRandom([bool $random = true ]) : self
Parameters
$random : bool = true
Return values
self

withSampled()

Create a new TraceFlags with the SAMPLED flag set or unset.

public withSampled([bool $sampled = true ]) : self
Parameters
$sampled : bool = true
Return values
self

        
On this page

Search results