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 --- .../api/Instrumentation/CachedInstrumentation.php | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 vendor/open-telemetry/api/Instrumentation/CachedInstrumentation.php (limited to 'vendor/open-telemetry/api/Instrumentation/CachedInstrumentation.php') diff --git a/vendor/open-telemetry/api/Instrumentation/CachedInstrumentation.php b/vendor/open-telemetry/api/Instrumentation/CachedInstrumentation.php new file mode 100644 index 000000000..5ffb3950d --- /dev/null +++ b/vendor/open-telemetry/api/Instrumentation/CachedInstrumentation.php @@ -0,0 +1,97 @@ +|null */ + private ?ArrayAccess $tracers; + /** @var ArrayAccess|null */ + private ?ArrayAccess $meters; + /** @var ArrayAccess|null */ + private ?ArrayAccess $loggers; + + public function __construct(string $name, ?string $version = null, ?string $schemaUrl = null, iterable $attributes = []) + { + $this->name = $name; + $this->version = $version; + $this->schemaUrl = $schemaUrl; + $this->attributes = $attributes; + $this->tracers = self::createWeakMap(); + $this->meters = self::createWeakMap(); + $this->loggers = self::createWeakMap(); + } + + private static function createWeakMap(): ?ArrayAccess + { + if (PHP_VERSION_ID < 80000) { + return null; + } + + /** @phan-suppress-next-line PhanUndeclaredClassReference */ + assert(class_exists(\WeakMap::class, false)); + /** @phan-suppress-next-line PhanUndeclaredClassMethod */ + $map = new \WeakMap(); + assert($map instanceof ArrayAccess); + + return $map; + } + + public function tracer(): TracerInterface + { + $tracerProvider = Globals::tracerProvider(); + + if ($this->tracers === null) { + return $tracerProvider->getTracer($this->name, $this->version, $this->schemaUrl, $this->attributes); + } + + return $this->tracers[$tracerProvider] ??= $tracerProvider->getTracer($this->name, $this->version, $this->schemaUrl, $this->attributes); + } + + public function meter(): MeterInterface + { + $meterProvider = Globals::meterProvider(); + + if ($this->meters === null) { + return $meterProvider->getMeter($this->name, $this->version, $this->schemaUrl, $this->attributes); + } + + return $this->meters[$meterProvider] ??= $meterProvider->getMeter($this->name, $this->version, $this->schemaUrl, $this->attributes); + } + public function logger(): LoggerInterface + { + $loggerProvider = Globals::loggerProvider(); + + if ($this->loggers === null) { + return $loggerProvider->getLogger($this->name, $this->version, $this->schemaUrl, $this->attributes); + } + + return $this->loggers[$loggerProvider] ??= $loggerProvider->getLogger($this->name, $this->version, $this->schemaUrl, $this->attributes); + } +} -- cgit v1.2.3-54-g00ecf