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 --- vendor/open-telemetry/sdk/Registry.php | 208 +++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 vendor/open-telemetry/sdk/Registry.php (limited to 'vendor/open-telemetry/sdk/Registry.php') diff --git a/vendor/open-telemetry/sdk/Registry.php b/vendor/open-telemetry/sdk/Registry.php new file mode 100644 index 000000000..2f0a20263 --- /dev/null +++ b/vendor/open-telemetry/sdk/Registry.php @@ -0,0 +1,208 @@ + $factory + */ + public static function registerTransportFactory(string $protocol, $factory, bool $clobber = false): void + { + if (!$clobber && array_key_exists($protocol, self::$transportFactories)) { + return; + } + if (!is_subclass_of($factory, TransportFactoryInterface::class)) { + trigger_error( + sprintf( + 'Cannot register transport factory: %s must exist and implement %s', + is_string($factory) ? $factory : get_class($factory), + TransportFactoryInterface::class + ), + E_USER_WARNING + ); + + return; + } + self::$transportFactories[$protocol] = $factory; + } + + /** + * @param SpanExporterFactoryInterface|class-string $factory + */ + public static function registerSpanExporterFactory(string $exporter, $factory, bool $clobber = false): void + { + if (!$clobber && array_key_exists($exporter, self::$spanExporterFactories)) { + return; + } + if (!is_subclass_of($factory, SpanExporterFactoryInterface::class)) { + trigger_error( + sprintf( + 'Cannot register span exporter factory: %s must exist and implement %s', + is_string($factory) ? $factory : get_class($factory), + SpanExporterFactoryInterface::class + ), + E_USER_WARNING + ); + + return; + } + self::$spanExporterFactories[$exporter] = $factory; + } + + /** + * @param MetricExporterFactoryInterface|class-string $factory + */ + public static function registerMetricExporterFactory(string $exporter, $factory, bool $clobber = false): void + { + if (!$clobber && array_key_exists($exporter, self::$metricExporterFactories)) { + return; + } + if (!is_subclass_of($factory, MetricExporterFactoryInterface::class)) { + trigger_error( + sprintf( + 'Cannot register metric factory: %s must exist and implement %s', + is_string($factory) ? $factory : get_class($factory), + MetricExporterFactoryInterface::class + ), + E_USER_WARNING + ); + + return; + } + self::$metricExporterFactories[$exporter] = $factory; + } + + public static function registerLogRecordExporterFactory(string $exporter, $factory, bool $clobber = false): void + { + if (!$clobber && array_key_exists($exporter, self::$logRecordExporterFactories)) { + return; + } + if (!is_subclass_of($factory, LogRecordExporterFactoryInterface::class)) { + trigger_error( + sprintf( + 'Cannot register LogRecord exporter factory: %s must exist and implement %s', + is_string($factory) ? $factory : get_class($factory), + LogRecordExporterFactoryInterface::class + ), + E_USER_WARNING + ); + + return; + } + self::$logRecordExporterFactories[$exporter] = $factory; + } + + public static function registerTextMapPropagator(string $name, TextMapPropagatorInterface $propagator, bool $clobber = false): void + { + if (!$clobber && array_key_exists($name, self::$textMapPropagators)) { + return; + } + self::$textMapPropagators[$name] = $propagator; + } + + public static function registerResourceDetector(string $name, ResourceDetectorInterface $detector): void + { + self::$resourceDetectors[$name] = $detector; + } + + public static function spanExporterFactory(string $exporter): SpanExporterFactoryInterface + { + if (!array_key_exists($exporter, self::$spanExporterFactories)) { + throw new RuntimeException('Span exporter factory not defined for: ' . $exporter); + } + $class = self::$spanExporterFactories[$exporter]; + $factory = (is_callable($class)) ? $class : new $class(); + assert($factory instanceof SpanExporterFactoryInterface); + + return $factory; + } + + public static function logRecordExporterFactory(string $exporter): LogRecordExporterFactoryInterface + { + if (!array_key_exists($exporter, self::$logRecordExporterFactories)) { + throw new RuntimeException('LogRecord exporter factory not defined for: ' . $exporter); + } + $class = self::$logRecordExporterFactories[$exporter]; + $factory = (is_callable($class)) ? $class : new $class(); + assert($factory instanceof LogRecordExporterFactoryInterface); + + return $factory; + } + + /** + * Get transport factory registered for protocol. If $protocol contains a content-type eg `http/xyz` then + * only the first part, `http`, is used. + */ + public static function transportFactory(string $protocol): TransportFactoryInterface + { + $protocol = explode('/', $protocol)[0]; + if (!array_key_exists($protocol, self::$transportFactories)) { + throw new RuntimeException('Transport factory not defined for protocol: ' . $protocol); + } + $class = self::$transportFactories[$protocol]; + $factory = (is_callable($class)) ? $class : new $class(); + assert($factory instanceof TransportFactoryInterface); + + return $factory; + } + + public static function metricExporterFactory(string $exporter): MetricExporterFactoryInterface + { + if (!array_key_exists($exporter, self::$metricExporterFactories)) { + throw new RuntimeException('Metric exporter factory not registered for protocol: ' . $exporter); + } + $class = self::$metricExporterFactories[$exporter]; + $factory = (is_callable($class)) ? $class : new $class(); + assert($factory instanceof MetricExporterFactoryInterface); + + return $factory; + } + + public static function textMapPropagator(string $name): TextMapPropagatorInterface + { + if (!array_key_exists($name, self::$textMapPropagators)) { + throw new RuntimeException('Text map propagator not registered for: ' . $name); + } + + return self::$textMapPropagators[$name]; + } + + public static function resourceDetector(string $name): ResourceDetectorInterface + { + if (!array_key_exists($name, self::$resourceDetectors)) { + throw new RuntimeException('Resource detector not registered for: ' . $name); + } + + return self::$resourceDetectors[$name]; + } + + /** + * @return array + */ + public static function resourceDetectors(): array + { + return array_values(self::$resourceDetectors); + } +} -- cgit v1.2.3