root = $root; $this->remoteParentSampler = $remoteParentSampler ?? new AlwaysOnSampler(); $this->remoteParentNotSampler = $remoteParentNotSampler ?? new AlwaysOffSampler(); $this->localParentSampler = $localParentSampler ?? new AlwaysOnSampler(); $this->localParentNotSampler = $localParentNotSampler ?? new AlwaysOffSampler(); } /** * Invokes the respective delegate sampler when parent is set or uses root sampler for the root span. * {@inheritdoc} */ 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()); } public function getDescription(): string { return 'ParentBased+' . $this->root->getDescription(); } }