diff --git a/src/DDTrace/Integrations/Logs/LogsIntegration.php b/src/DDTrace/Integrations/Logs/LogsIntegration.php index 341cab1cd8..906987ae31 100644 --- a/src/DDTrace/Integrations/Logs/LogsIntegration.php +++ b/src/DDTrace/Integrations/Logs/LogsIntegration.php @@ -237,6 +237,17 @@ public function init(): int ); \DDTrace\remove_hook($hook, NullLogger::class); + \DDTrace\install_hook( + 'Monolog\Formatter\JsonFormatter::toJson', + function (HookData $hook) { + /** @var array $normalized */ + $normalized = $hook->args[0]; + $normalized['source'] = 'php'; + $hook->args[0] = $normalized; + $hook->overrideArguments($hook->args); + } + ); + return Integration::LOADED; } } diff --git a/tests/Integrations/Logs/MonologV2/MonologV2Test.php b/tests/Integrations/Logs/MonologV2/MonologV2Test.php index 114ce07f22..eaade6fe48 100644 --- a/tests/Integrations/Logs/MonologV2/MonologV2Test.php +++ b/tests/Integrations/Logs/MonologV2/MonologV2Test.php @@ -10,7 +10,7 @@ public function testDebugJsonFormatting() { $this->usingJson( 'debug', $this->getLogger(true), - '/^{"message":"A debug message","context":{"dd.trace_id":"\d+","dd.span_id":"\d+","dd.service":"my-service","dd.version":"4.2","dd.env":"my-env"},"level":100,"level_name":"DEBUG","channel":"test","datetime":".*","extra":{}}/' + '/^{"message":"A debug message","context":{"dd.trace_id":"\d+","dd.span_id":"\d+","dd.service":"my-service","dd.version":"4.2","dd.env":"my-env"},"level":100,"level_name":"DEBUG","channel":"test","datetime":".*","extra":{},"ddsource":"php"}/' ); } @@ -18,7 +18,7 @@ public function testLogJsonFormatting() { $this->usingJson( 'log', $this->getLogger(true), - '/^{"message":"A critical message","context":{"dd.trace_id":"\d+","dd.span_id":"\d+","dd.service":"my-service","dd.version":"4.2","dd.env":"my-env"},"level":500,"level_name":"CRITICAL","channel":"test","datetime":".*","extra":{}}/', + '/^{"message":"A critical message","context":{"dd.trace_id":"\d+","dd.span_id":"\d+","dd.service":"my-service","dd.version":"4.2","dd.env":"my-env"},"level":500,"level_name":"CRITICAL","channel":"test","datetime":".*","extra":{},"ddsource":"php"}/', false, 'critical' );