Skip to content

Commit

Permalink
chore: make logging context keys configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaguerre committed Aug 30, 2022
1 parent a3c1623 commit 4e33863
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public function getConfigTreeBuilder(): TreeBuilder
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultTrue()->end()
->arrayNode('handlers')
->defaultValue([
'main',
'console',
])
->scalarPrototype()->end()
->info('Handlers to which the trace context processor should be bound')
->end()
->arrayNode('keys')
->addDefaultsIfNotSet()
->children()
Expand Down
5 changes: 5 additions & 0 deletions src/DependencyInjection/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ protected function loadLogging(array $config, ContainerBuilder $container): void
$map[$property] = $keys;
}

foreach ($config['handlers'] as $handler) {
$container->getDefinition(\Instrumentation\Logging\Processor\TraceContextProcessor::class)
->addTag('monolog.processor', ['handler' => $handler]);
}

$container->setParameter('logging.trace_context_keys', $map);
}

Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/config/logging/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@

->set(Logging\Processor\TraceContextProcessor::class)
->args([param('logging.trace_context_keys')])
->tag('monolog.processor');
;
};
2 changes: 1 addition & 1 deletion src/Tracing/Instrumentation/LogHandler/TracingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function write(array $record): void
if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Throwable) {
$span->recordException($record['context']['exception'], ['raw_stacktrace' => $record['context']['exception']->getTraceAsString()]);
} else {
$span->addEvent($record['message'], ['_severity' => $record['level_name'], '_category' => $record['channel']]);
$span->addEvent($record['message']);
}
}
}

0 comments on commit 4e33863

Please sign in to comment.