OpenTelemetry PHP

AlwaysRecordSampler
in package
implements SamplerInterface

This implementation of the SamplerInterface converts {@link \OpenTelemetry\SDK\Trace\SamplingResult::DROP} decisions from the root sampler into {@link \OpenTelemetry\SDK\Trace\SamplingResult::RECORD_ONLY} decisions, allowing processors to see all spans without sending them to exporters.

This is typically used to enable accurate span-to-metrics processing. Example:

use OpenTelemetry\SDK\Trace\Sampler\AlwaysRecordSampler;
use OpenTelemetry\SDK\Trace\Sampler\AlwaysOffSampler;

$rootSampler = new AlwaysOffSampler();
$sampler = new AlwaysRecordSampler($rootSampler);
Tags
see
https://opentelemetry.io/docs/specs/otel/trace/sdk/#alwaysrecord
experimental

Table of Contents

Interfaces

SamplerInterface
This interface is used to organize sampling logic.

Properties

$root  : SamplerInterface

Methods

__construct()  : mixed
AlwaysRecord sampler ensures every span is passed to the `SpanProcessor`, even those that would normally be dropped by the root sampler. It does this by converting {@link \OpenTelemetry\SDK\Trace\SamplingResult::DROP} decisions into {@link \OpenTelemetry\SDK\Trace\SamplingResult::RECORD_ONLY}.
getDescription()  : string
Returns the sampler name or short description with the configuration.
shouldSample()  : SamplingResult
Overrides the sampling decision from the root sampler to {@link \OpenTelemetry\SDK\Trace\SamplingResult::RECORD_ONLY} when the root sampler returns {@link \OpenTelemetry\SDK\Trace\SamplingResult::DROP}.

Properties

Methods

__construct()

AlwaysRecord sampler ensures every span is passed to the `SpanProcessor`, even those that would normally be dropped by the root sampler. It does this by converting {@link \OpenTelemetry\SDK\Trace\SamplingResult::DROP} decisions into {@link \OpenTelemetry\SDK\Trace\SamplingResult::RECORD_ONLY}.

public __construct(SamplerInterface $root) : mixed
Parameters
$root : SamplerInterface

The root sampler called for the span.

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}"

Attributes
#[Override]
Return values
string

shouldSample()

Overrides the sampling decision from the root sampler to {@link \OpenTelemetry\SDK\Trace\SamplingResult::RECORD_ONLY} when the root sampler returns {@link \OpenTelemetry\SDK\Trace\SamplingResult::DROP}.

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

Attributes
#[Override]
Return values
SamplingResult

        
On this page

Search results