Flow PHP

ParentBasedSampler implements Sampler

Read onlyYes
FinalYes

Sampler that respects the parent span's sampling decision.

This sampler ensures sampling consistency across a trace:

  • If the parent was sampled, this span is sampled
  • If the parent was not sampled, this span is not sampled
  • For root spans (no parent), delegates to the configured root sampler

This is the recommended sampler for most production deployments as it ensures complete traces while maintaining sampling decisions made upstream.

Example usage:

$sampler = new ParentBasedSampler(
    new TraceIdRatioBasedSampler(0.01), // 1% for root spans
);
$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(Sampler $rootSampler[, null|Sampler $remoteParentSampled = null ][, null|Sampler $remoteParentNotSampled = null ][, null|Sampler $localParentSampled = null ][, null|Sampler $localParentNotSampled = null ]) : mixed
Parameters
$rootSampler : Sampler

Sampler to use for root spans (no parent)

$remoteParentSampled : null|Sampler = null

Sampler for remote sampled parents (default: AlwaysOnSampler)

$remoteParentNotSampled : null|Sampler = null

Sampler for remote non-sampled parents (default: AlwaysOffSampler)

$localParentSampled : null|Sampler = null

Sampler for local sampled parents (default: AlwaysOnSampler)

$localParentNotSampled : null|Sampler = null

Sampler for local non-sampled parents (default: AlwaysOffSampler)

__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