Sampler
Interface for sampling decisions.
Samplers determine whether a span should be recorded and/or exported. This allows controlling the volume of telemetry data while maintaining the ability to trace complete transactions.
Following OpenTelemetry, the sampling decision receives the parent Context (carrying the active span and the tracing-suppression bit) alongside the span to be created.
Example usage:
$sampler = new TraceIdRatioBasedSampler(0.1); // 10% sampling
$result = $sampler->shouldSample($context, $span);
if ($result->decision->isRecording()) {
// Record the span
}
Methods
- __toString() : string
- Get a string representation of this sampler for debugging.
- shouldSample() : SamplingResult
- Determine if a span should be sampled.
Methods
__toString()
Get a string representation of this sampler for debugging.
public
__toString() : string
Examples:
- "AlwaysOnSampler"
- "TraceIdRatioBasedSampler{0.001}"
- "ParentBased{root=AlwaysOnSampler}"
Return values
stringshouldSample()
Determine if a span should be sampled.
public
shouldSample(Context $parentContext, Span $span) : SamplingResult
Parameters
- $parentContext : Context
-
The parent context of the span to be created
- $span : Span
-
The span to evaluate for sampling
Return values
SamplingResult —The sampling decision