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 --- .../open-telemetry/sdk/Metrics/MeterProvider.php | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 vendor/open-telemetry/sdk/Metrics/MeterProvider.php (limited to 'vendor/open-telemetry/sdk/Metrics/MeterProvider.php') diff --git a/vendor/open-telemetry/sdk/Metrics/MeterProvider.php b/vendor/open-telemetry/sdk/Metrics/MeterProvider.php new file mode 100644 index 000000000..36c17cf81 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MeterProvider.php @@ -0,0 +1,130 @@ + $metricReaders + */ + public function __construct( + ?ContextStorageInterface $contextStorage, + ResourceInfo $resource, + ClockInterface $clock, + AttributesFactoryInterface $attributesFactory, + InstrumentationScopeFactoryInterface $instrumentationScopeFactory, + iterable $metricReaders, + ViewRegistryInterface $viewRegistry, + ?ExemplarFilterInterface $exemplarFilter, + StalenessHandlerFactoryInterface $stalenessHandlerFactory, + MetricFactoryInterface $metricFactory = null + ) { + $this->metricFactory = $metricFactory ?? new StreamFactory(); + $this->resource = $resource; + $this->clock = $clock; + $this->instrumentationScopeFactory = $instrumentationScopeFactory; + $this->metricReaders = $metricReaders; + $this->viewRegistry = $viewRegistry; + $this->exemplarFilter = $exemplarFilter; + $this->stalenessHandlerFactory = $stalenessHandlerFactory; + $this->instruments = new MeterInstruments(); + + $registry = new MetricRegistry($contextStorage, $attributesFactory, $clock); + $this->registry = $registry; + $this->writer = $registry; + } + + public function getMeter( + string $name, + ?string $version = null, + ?string $schemaUrl = null, + iterable $attributes = [] + ): MeterInterface { + if ($this->closed || Sdk::isDisabled()) { //@todo create meter provider from factory, and move Sdk::isDisabled() there + return new NoopMeter(); + } + + return new Meter( + $this->metricFactory, + $this->resource, + $this->clock, + $this->stalenessHandlerFactory, + $this->metricReaders, + $this->viewRegistry, + $this->exemplarFilter, + $this->instruments, + $this->instrumentationScopeFactory->create($name, $version, $schemaUrl, $attributes), + $this->registry, + $this->writer, + ); + } + + public function shutdown(): bool + { + if ($this->closed) { + return false; + } + + $this->closed = true; + + $success = true; + foreach ($this->metricReaders as $metricReader) { + if (!$metricReader->shutdown()) { + $success = false; + } + } + + return $success; + } + + public function forceFlush(): bool + { + if ($this->closed) { + return false; + } + + $success = true; + foreach ($this->metricReaders as $metricReader) { + if (!$metricReader->forceFlush()) { + $success = false; + } + } + + return $success; + } + + public static function builder(): MeterProviderBuilder + { + return new MeterProviderBuilder(); + } +} -- cgit v1.2.3