From cdd7ad020e165fe680703b6d3319b908b682fb7a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 20 Oct 2023 17:12:29 +0300 Subject: jaeger-client -> opentelemetry --- .../sdk/Trace/Sampler/ParentBased.php | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 vendor/open-telemetry/sdk/Trace/Sampler/ParentBased.php (limited to 'vendor/open-telemetry/sdk/Trace/Sampler/ParentBased.php') diff --git a/vendor/open-telemetry/sdk/Trace/Sampler/ParentBased.php b/vendor/open-telemetry/sdk/Trace/Sampler/ParentBased.php new file mode 100644 index 000000000..db801d3d8 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Sampler/ParentBased.php @@ -0,0 +1,100 @@ +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(); + } +} -- cgit v1.2.3