OpenTelemetry PHP

ParentBased
in package
implements SamplerInterface

This implementation of the SamplerInterface that respects parent context's sampling decision and delegates for the root span.

Example:

use OpenTelemetry\API\Trace\ParentBased;
use OpenTelemetry\API\Trace\AlwaysOnSampler

$rootSampler = new AlwaysOnSampler();
$sampler = new ParentBased($rootSampler);

Table of Contents

Interfaces

SamplerInterface
This interface is used to organize sampling logic.

Properties

$localParentNotSampler  : SamplerInterface
$localParentSampler  : SamplerInterface
$remoteParentNotSampler  : SamplerInterface
$remoteParentSampler  : SamplerInterface
$root  : SamplerInterface

Methods

__construct()  : mixed
ParentBased sampler delegates the sampling decision based on the parent context.
getDescription()  : string
Returns the sampler name or short description with the configuration.
shouldSample()  : SamplingResult
Invokes the respective delegate sampler when parent is set or uses root sampler for the root span.

Properties

Methods

__construct()

ParentBased sampler delegates the sampling decision based on the parent context.

public __construct(SamplerInterface $root[, SamplerInterface|null $remoteParentSampler = null ][, SamplerInterface|null $remoteParentNotSampler = null ][, SamplerInterface|null $localParentSampler = null ][, SamplerInterface|null $localParentNotSampler = null ]) : mixed
Parameters
$root : SamplerInterface

Sampler called for the span with no parent (root span).

$remoteParentSampler : SamplerInterface|null = null

Sampler called for the span with the remote sampled parent. When null, AlwaysOnSampler is used.

$remoteParentNotSampler : SamplerInterface|null = null

Sampler called for the span with the remote not sampled parent. When null, AlwaysOffSampler is used.

$localParentSampler : SamplerInterface|null = null

Sampler called for the span with local the sampled parent. When null, AlwaysOnSampler is used.

$localParentNotSampler : SamplerInterface|null = null

Sampler called for the span with the local not sampled parent. When null, AlwaysOffSampler is used.

getDescription()

Returns the sampler name or short description with the configuration.

public getDescription() : string

This may be displayed on debug pages or in the logs. Example: "TraceIdRatioBasedSampler{0.000100}"

Return values
string

shouldSample()

Invokes the respective delegate sampler when parent is set or uses root sampler for the root span.

public shouldSample(ContextInterface $parentContext, string $traceId, string $spanName, int $spanKind, AttributesInterface $attributes, array<string|int, mixed> $links) : SamplingResult
Parameters
$parentContext : ContextInterface

Context with parent Span. The Span's SpanContext may be invalid to indicate a root span.

$traceId : string

TraceId of the Span to be created. It can be different from the TraceId in the SpanContext. Typically in situations when the Span to be created starts a new Trace.

$spanName : string

Name of the Span to be created.

$spanKind : int

Span kind.

$attributes : AttributesInterface

Initial set of Attributes for the Span being constructed.

$links : array<string|int, mixed>

Collection of links that will be associated with the Span to be created. Typically, useful for batch operations. @see https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#links-between-spans

Return values
SamplingResult

        
On this page

Search results