|
4 | 4 |
|
5 | 5 | namespace Flow\Bridge\Symfony\TelemetryBundle\DependencyInjection; |
6 | 6 |
|
| 7 | +use Flow\Bridge\Psr3\Telemetry\{LogRecordConverter, TelemetryLogger}; |
7 | 8 | use Flow\Bridge\Symfony\TelemetryBundle\Exception\RuntimeException; |
8 | 9 | use Flow\Bridge\Symfony\TelemetryBundle\Resource\Detector\SymfonyDeploymentDetector; |
9 | 10 | use Flow\Bridge\Telemetry\OTLP\Exporter\{OTLPLogExporter, OTLPMetricExporter, OTLPSpanExporter}; |
@@ -66,17 +67,23 @@ public function load(array $configs, ContainerBuilder $container) : void |
66 | 67 | { |
67 | 68 | $loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
68 | 69 | $configuration = new Configuration(); |
69 | | - /** @var array{resource: array{detectors?: array{enabled?: bool, static?: array{cache?: array{enabled?: bool, path?: null|string}, os?: array{enabled?: bool}, host?: array{enabled?: bool}, service?: array{enabled?: bool}, deployment?: array{enabled?: bool}, environment?: array{enabled?: bool}}, dynamic?: array{process?: array{enabled?: bool}}}, custom?: array<string, mixed>}, clock_service_id?: null|string, context_storage?: array{type?: string, service_id?: null|string}, propagator?: array{type?: string, service_id?: null|string}, tracer_provider?: array<string, mixed>, meter_provider?: array<string, mixed>, logger_provider?: array<string, mixed>, instrumentation?: array{http_kernel?: array{enabled?: bool, exclude_paths?: array<array{path: string, method?: null|string}>, context_propagation?: bool}, console?: array{enabled?: bool, exclude_commands?: array<string>}, messenger?: array{enabled?: bool, context_propagation?: bool}, twig?: array{enabled?: bool, trace_templates?: bool, trace_blocks?: bool, trace_macros?: bool, exclude_templates?: array<string>}, http_client?: array{enabled?: bool, exclude_clients?: array<string>}, psr18_client?: array{enabled?: bool, exclude_clients?: array<string>}, dbal?: array{enabled?: bool, log_sql?: bool, max_sql_length?: int, exclude_connections?: array<string>}, cache?: array{enabled?: bool, exclude_pools?: array<string>}}, tracers?: array<string, array{version?: string, schema_url?: null|string, attributes?: array<string, mixed>}>, meters?: array<string, array{version?: string, schema_url?: null|string, attributes?: array<string, mixed>}>, loggers?: array<string, array{version?: string, schema_url?: null|string, attributes?: array<string, mixed>}>} $config */ |
| 70 | + /** @var array{resource: array{detectors?: array{enabled?: bool, static?: array{cache?: array{enabled?: bool, path?: null|string}, os?: array{enabled?: bool}, host?: array{enabled?: bool}, service?: array{enabled?: bool}, deployment?: array{enabled?: bool}, environment?: array{enabled?: bool}}, dynamic?: array{process?: array{enabled?: bool}}}, custom?: array<string, mixed>}, clock_service_id?: null|string, main_logger?: null|string, context_storage?: array{type?: string, service_id?: null|string}, propagator?: array{type?: string, service_id?: null|string}, tracer_provider?: array<string, mixed>, meter_provider?: array<string, mixed>, logger_provider?: array<string, mixed>, instrumentation?: array{http_kernel?: array{enabled?: bool, exclude_paths?: array<array{path: string, method?: null|string}>, context_propagation?: bool}, console?: array{enabled?: bool, exclude_commands?: array<string>}, messenger?: array{enabled?: bool, context_propagation?: bool}, twig?: array{enabled?: bool, trace_templates?: bool, trace_blocks?: bool, trace_macros?: bool, exclude_templates?: array<string>}, http_client?: array{enabled?: bool, exclude_clients?: array<string>}, psr18_client?: array{enabled?: bool, exclude_clients?: array<string>}, dbal?: array{enabled?: bool, log_sql?: bool, max_sql_length?: int, exclude_connections?: array<string>}, cache?: array{enabled?: bool, exclude_pools?: array<string>}}, tracers?: array<string, array{version?: string, schema_url?: null|string, attributes?: array<string, mixed>}>, meters?: array<string, array{version?: string, schema_url?: null|string, attributes?: array<string, mixed>}>, loggers?: array<string, array{version?: string, schema_url?: null|string, attributes?: array<string, mixed>}>} $config */ |
70 | 71 | $config = $this->processConfiguration($configuration, $configs); |
71 | 72 |
|
| 73 | + $container->setParameter('flow.telemetry.main_logger', $config['main_logger'] ?? null); |
| 74 | + |
| 75 | + $tracers = ($config['tracers'] ?? []) + ['default' => []]; |
| 76 | + $meters = ($config['meters'] ?? []) + ['default' => []]; |
| 77 | + $loggers = ($config['loggers'] ?? []) + ['default' => []]; |
| 78 | + |
72 | 79 | $this->registerGlobalServices($config, $container); |
73 | 80 | $this->registerPropagator($config['propagator'] ?? [], $container); |
74 | 81 | $this->registerResource($config['resource'], $container); |
75 | 82 | $this->registerTelemetry($config, $container); |
76 | 83 | $this->registerInstrumentation($config['instrumentation'] ?? [], $container, $loader); |
77 | | - $this->registerTracers($config['tracers'] ?? [], $container); |
78 | | - $this->registerMeters($config['meters'] ?? [], $container); |
79 | | - $this->registerLoggers($config['loggers'] ?? [], $container); |
| 84 | + $this->registerTracers($tracers, $container); |
| 85 | + $this->registerMeters($meters, $container); |
| 86 | + $this->registerLoggers($loggers, $container); |
80 | 87 | } |
81 | 88 |
|
82 | 89 | /** |
@@ -907,6 +914,11 @@ private function registerGlobalServices(array $config, ContainerBuilder $contain |
907 | 914 | } else { |
908 | 915 | $container->setDefinition('flow.telemetry.context_storage', new Definition(MemoryContextStorage::class)); |
909 | 916 | } |
| 917 | + |
| 918 | + $container->setDefinition( |
| 919 | + 'flow.telemetry.psr3.log_record_converter', |
| 920 | + new Definition(LogRecordConverter::class) |
| 921 | + ); |
910 | 922 | } |
911 | 923 |
|
912 | 924 | /** |
@@ -986,7 +998,14 @@ private function registerLoggers(array $config, ContainerBuilder $container) : v |
986 | 998 | } |
987 | 999 |
|
988 | 1000 | $definition->setPublic(true); |
989 | | - $container->setDefinition('flow.telemetry.' . $name . '.logger', $definition); |
| 1001 | + $loggerServiceId = 'flow.telemetry.' . $name . '.logger'; |
| 1002 | + $container->setDefinition($loggerServiceId, $definition); |
| 1003 | + |
| 1004 | + $psr3Definition = new Definition(TelemetryLogger::class); |
| 1005 | + $psr3Definition->setArgument(0, new Reference($loggerServiceId)); |
| 1006 | + $psr3Definition->setArgument(1, new Reference('flow.telemetry.psr3.log_record_converter')); |
| 1007 | + $psr3Definition->setPublic(true); |
| 1008 | + $container->setDefinition($loggerServiceId . '.psr3', $psr3Definition); |
990 | 1009 | } |
991 | 1010 | } |
992 | 1011 |
|
@@ -1195,10 +1214,9 @@ private function registerResource(array $resourceConfig, ContainerBuilder $conta |
1195 | 1214 | $cacheEnabled = $cacheConfig['enabled'] ?? true; |
1196 | 1215 |
|
1197 | 1216 | if ($cacheEnabled) { |
1198 | | - $cachePath = $cacheConfig['path'] ?? '%kernel.cache_dir%/flow_telemetry_resource.cache'; |
1199 | 1217 | $cachingDefinition = new Definition(CachingDetector::class); |
1200 | 1218 | $cachingDefinition->setArgument(0, new Reference('flow.telemetry.resource.detector.static.chain')); |
1201 | | - $cachingDefinition->setArgument(1, $cachePath); |
| 1219 | + $cachingDefinition->setArgument(1, $cacheConfig['path'] ?? null); |
1202 | 1220 | $container->setDefinition('flow.telemetry.resource.detector.static', $cachingDefinition); |
1203 | 1221 | } else { |
1204 | 1222 | $container->setAlias('flow.telemetry.resource.detector.static', 'flow.telemetry.resource.detector.static.chain'); |
|
0 commit comments