diff options
author | Andrew Dolgov <[email protected]> | 2023-10-20 17:12:29 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2023-10-20 21:13:39 +0300 |
commit | cdd7ad020e165fe680703b6d3319b908b682fb7a (patch) | |
tree | b51eb09b7b4587e8fbc5624ac8d88d28cfcd0b04 /vendor/open-telemetry/sdk/Trace/TracerSharedState.php | |
parent | 45a9ff0c88cbd33892ff16ab837e9059937d656e (diff) |
jaeger-client -> opentelemetry
Diffstat (limited to 'vendor/open-telemetry/sdk/Trace/TracerSharedState.php')
-rw-r--r-- | vendor/open-telemetry/sdk/Trace/TracerSharedState.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/vendor/open-telemetry/sdk/Trace/TracerSharedState.php b/vendor/open-telemetry/sdk/Trace/TracerSharedState.php new file mode 100644 index 000000000..d0540cc1f --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/TracerSharedState.php @@ -0,0 +1,100 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\SDK\Trace; + +use OpenTelemetry\API\Trace as API; /** @phan-suppress-current-line PhanUnreferencedUseNormal */ +use OpenTelemetry\SDK\Common\Future\CancellationInterface; +use OpenTelemetry\SDK\Resource\ResourceInfo; +use OpenTelemetry\SDK\Trace\SpanProcessor\MultiSpanProcessor; +use OpenTelemetry\SDK\Trace\SpanProcessor\NoopSpanProcessor; + +/** + * Stores shared state/config between all {@see API\TracerInterface} created via the same {@see API\TracerProviderInterface}. + */ +final class TracerSharedState +{ + /** @readonly */ + private IdGeneratorInterface $idGenerator; + + /** @readonly */ + private ResourceInfo $resource; + + /** @readonly */ + private SpanLimits $spanLimits; + + /** @readonly */ + private SamplerInterface $sampler; + + /** @readonly */ + private SpanProcessorInterface $spanProcessor; + + private ?bool $shutdownResult = null; + + public function __construct( + IdGeneratorInterface $idGenerator, + ResourceInfo $resource, + SpanLimits $spanLimits, + SamplerInterface $sampler, + array $spanProcessors + ) { + $this->idGenerator = $idGenerator; + $this->resource = $resource; + $this->spanLimits = $spanLimits; + $this->sampler = $sampler; + + switch (count($spanProcessors)) { + case 0: + $this->spanProcessor = NoopSpanProcessor::getInstance(); + + break; + case 1: + $this->spanProcessor = $spanProcessors[0]; + + break; + default: + $this->spanProcessor = new MultiSpanProcessor(...$spanProcessors); + + break; + } + } + + public function hasShutdown(): bool + { + return null !== $this->shutdownResult; + } + + public function getIdGenerator(): IdGeneratorInterface + { + return $this->idGenerator; + } + + public function getResource(): ResourceInfo + { + return $this->resource; + } + + public function getSpanLimits(): SpanLimits + { + return $this->spanLimits; + } + + public function getSampler(): SamplerInterface + { + return $this->sampler; + } + + public function getSpanProcessor(): SpanProcessorInterface + { + return $this->spanProcessor; + } + + /** + * Returns `false` is the provider is already shutdown, otherwise `true`. + */ + public function shutdown(?CancellationInterface $cancellation = null): bool + { + return $this->shutdownResult ?? ($this->shutdownResult = $this->spanProcessor->shutdown($cancellation)); + } +} |