function ParentBased::shouldSample
Invokes the respective delegate sampler when parent is set or uses root sampler for the root span.
Overrides SamplerInterface::shouldSample
File
-
vendor/
open-telemetry/ sdk/ Trace/ Sampler/ ParentBased.php, line 63
Class
- ParentBased
- 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
Namespace
OpenTelemetry\SDK\Trace\SamplerCode
public function shouldSample(ContextInterface $parentContext, string $traceId, string $spanName, int $spanKind, AttributesInterface $attributes, array $links) : SamplingResult {
$parentSpan = Span::fromContext($parentContext);
$parentSpanContext = $parentSpan->getContext();
// Invalid parent SpanContext indicates root span is being created
if (!$parentSpanContext->isValid()) {
return $this->root
->shouldSample(...func_get_args());
}
if ($parentSpanContext->isRemote()) {
return $parentSpanContext->isSampled() ? $this->remoteParentSampler
->shouldSample(...func_get_args()) : $this->remoteParentNotSampler
->shouldSample(...func_get_args());
}
return $parentSpanContext->isSampled() ? $this->localParentSampler
->shouldSample(...func_get_args()) : $this->localParentNotSampler
->shouldSample(...func_get_args());
}