Flow PHP

TraceIdRatioBasedSampler implements Sampler

Read onlyYes
FinalYes

Sampler that samples a configurable percentage of traces.

The sampling decision is deterministic based on the trace ID, ensuring that all spans in a trace are sampled consistently across different services.

Example usage:

// Sample 10% of traces
$sampler = new TraceIdRatioBasedSampler(0.1);
$result = $sampler->shouldSample($span);

Interfaces

Sampler
Interface for sampling decisions.

Methods

__construct()  : mixed
__toString()  : string
Get a string representation of this sampler for debugging.
shouldSample()  : SamplingResult
Determine if a span should be sampled.

Methods

__construct()

public __construct(float $ratio) : mixed
Parameters
$ratio : float

Sampling ratio between 0.0 (none) and 1.0 (all)

Tags
throws
InvalidArgumentException

if ratio is out of range

__toString()

Get a string representation of this sampler for debugging.

public __toString() : string

Examples:

  • "AlwaysOnSampler"
  • "TraceIdRatioBasedSampler{0.001}"
  • "ParentBased{root=AlwaysOnSampler}"
Return values
string

        
On this page

Search results