@@ -43,6 +43,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
4343 $ loader ->load ('services_metrics.php ' );
4444 $ loader ->load ('services_traces.php ' );
4545 $ loader ->load ('services_tracing_instrumentation.php ' );
46+ $ loader ->load ('services_metering_instrumentation.php ' );
4647
4748 $ this ->registerService ($ mergedConfig ['service ' ], $ container );
4849 $ this ->registerInstrumentation ($ mergedConfig ['instrumentation ' ], $ container );
@@ -91,10 +92,16 @@ private function registerService(array $config, ContainerBuilder $container): vo
9192 private function registerInstrumentation (array $ config , ContainerBuilder $ container ): void
9293 {
9394 $ this ->registerCacheTracingInstrumentationConfiguration ($ container , $ config ['cache ' ]);
95+
9496 $ this ->registerConsoleTracingInstrumentationConfiguration ($ container , $ config ['console ' ]);
97+ $ this ->registerConsoleMeteringInstrumentationConfiguration ($ container , $ config ['console ' ]);
98+
9599 $ this ->registerDoctrineTracingInstrumentationConfiguration ($ container , $ config ['doctrine ' ]);
96100 $ this ->registerHttpClientTracingInstrumentationConfiguration ($ container , $ config ['http_client ' ]);
101+
97102 $ this ->registerHttpKernelTracingInstrumentationConfiguration ($ container , $ config ['http_kernel ' ]);
103+ $ this ->registerHttpKernelMeteringInstrumentationConfiguration ($ container , $ config ['http_kernel ' ]);
104+
98105 $ this ->registerMailerTracingInstrumentationConfiguration ($ container , $ config ['mailer ' ]);
99106 $ this ->registerMessengerTracingInstrumentationConfiguration ($ container , $ config ['messenger ' ]);
100107 $ this ->registerTwigTracingInstrumentationConfiguration ($ container , $ config ['twig ' ]);
@@ -137,6 +144,22 @@ private function registerConsoleTracingInstrumentationConfiguration(ContainerBui
137144 $ this ->setTracingInstrumentationParams ($ container , 'console ' , $ config , $ isConfigEnabled );
138145 }
139146
147+ /**
148+ * @param InstrumentationConfig $config
149+ */
150+ private function registerConsoleMeteringInstrumentationConfiguration (ContainerBuilder $ container , array $ config ): void
151+ {
152+ $ isConfigEnabled = $ this ->isConfigEnabled ($ container , $ config ['metering ' ]);
153+
154+ if ($ isConfigEnabled && !class_exists (Command::class)) {
155+ throw new \LogicException ('Console instrumentation cannot be enabled because the symfony/console package is not installed. ' );
156+ }
157+
158+ if (!$ isConfigEnabled ) {
159+ $ container ->removeDefinition ('open_telemetry.instrumentation.console.metric.event_subscriber ' );
160+ }
161+ }
162+
140163 /**
141164 * @param InstrumentationConfig $config
142165 */
@@ -188,6 +211,18 @@ private function registerHttpKernelTracingInstrumentationConfiguration(Container
188211 $ this ->setTracingInstrumentationParams ($ container , 'http_kernel ' , $ config , $ isConfigEnabled );
189212 }
190213
214+ /**
215+ * @param InstrumentationConfig $config
216+ */
217+ private function registerHttpKernelMeteringInstrumentationConfiguration (ContainerBuilder $ container , array $ config ): void
218+ {
219+ $ isConfigEnabled = $ this ->isConfigEnabled ($ container , $ config ['metering ' ]);
220+
221+ if (!$ isConfigEnabled ) {
222+ $ container ->removeDefinition ('open_telemetry.instrumentation.http_kernel.metric.event_subscriber ' );
223+ }
224+ }
225+
191226 /**
192227 * @param InstrumentationConfig $config
193228 */
0 commit comments