88use OpenTelemetry \SDK \Common \Export \TransportFactoryInterface ;
99use OpenTelemetry \SDK \Logs \LogRecordExporterFactoryInterface ;
1010use OpenTelemetry \SDK \Metrics \MetricExporterFactoryInterface ;
11+ use OpenTelemetry \SDK \Resource \ResourceDetectorInterface ;
1112use OpenTelemetry \SDK \Trace \SpanExporter \SpanExporterFactoryInterface ;
1213use RuntimeException ;
1314
@@ -22,6 +23,7 @@ class Registry
2223 private static array $ metricExporterFactories = [];
2324 private static array $ textMapPropagators = [];
2425 private static array $ logRecordExporterFactories = [];
26+ private static array $ resourceDetectors = [];
2527
2628 /**
2729 * @param TransportFactoryInterface|class-string<TransportFactoryInterface> $factory
@@ -91,6 +93,7 @@ public static function registerMetricExporterFactory(string $exporter, $factory,
9193 }
9294 self ::$ metricExporterFactories [$ exporter ] = $ factory ;
9395 }
96+
9497 public static function registerLogRecordExporterFactory (string $ exporter , $ factory , bool $ clobber = false ): void
9598 {
9699 if (!$ clobber && array_key_exists ($ exporter , self ::$ logRecordExporterFactories )) {
@@ -119,6 +122,11 @@ public static function registerTextMapPropagator(string $name, TextMapPropagator
119122 self ::$ textMapPropagators [$ name ] = $ propagator ;
120123 }
121124
125+ public static function registerResourceDetector (string $ name , ResourceDetectorInterface $ detector ): void
126+ {
127+ self ::$ resourceDetectors [$ name ] = $ detector ;
128+ }
129+
122130 public static function spanExporterFactory (string $ exporter ): SpanExporterFactoryInterface
123131 {
124132 if (!array_key_exists ($ exporter , self ::$ spanExporterFactories )) {
@@ -180,4 +188,21 @@ public static function textMapPropagator(string $name): TextMapPropagatorInterfa
180188
181189 return self ::$ textMapPropagators [$ name ];
182190 }
191+
192+ public static function resourceDetector (string $ name ): ResourceDetectorInterface
193+ {
194+ if (!array_key_exists ($ name , self ::$ resourceDetectors )) {
195+ throw new RuntimeException ('Resource detector not registered for: ' . $ name );
196+ }
197+
198+ return self ::$ resourceDetectors [$ name ];
199+ }
200+
201+ /**
202+ * @return array<int, ResourceDetectorInterface>
203+ */
204+ public static function resourceDetectors (): array
205+ {
206+ return array_values (self ::$ resourceDetectors );
207+ }
183208}
0 commit comments