TraceId not being injected in the logs
As per explained in Connect Logs and Traces we've added a a Monolog processor to our logs so they receive the trace and span id, but so far we've had no luck.
What we've found is that while the trace id is generated correctly at any point of our code - we just did a echo GlobalTracer::get()->getActiveSpan()->getTraceId(); at it worked - once we arrive to the Monolog processor the GlobalTracer::get()->getActiveSpan(); returns null for the same request.
We're using agent v6.15.1 wit the PHP agent 0.35.0, in a Symfony 3.4 project, with the following config:
monolog:
handlers:
datadog:
type: stream
path: "%kernel.logs_dir%/datadog-%kernel.environment%.log"
level: info
formatter: monolog.formatter.json
services:
datadog_processor:
class: App\Core\Infrastructure\Monolog\DatadogProcessor
tags:
- { name: monolog.processor, handler: datadog }
namespace App\Core\Infrastructure\Monolog;
use DDTrace\GlobalTracer;
class DatadogProcessor
{
public function __invoke(array $record)
{
$span = GlobalTracer::get()->getActiveSpan();
if (null === $span) {
return $record;
}
$record['message'] .= sprintf(
' [dd.trace_id=%d dd.span_id=%d]',
$span->getTraceId(),
$span->getSpanId()
);
return $record;
}
}
Hi @sdepablos I need to ask a few questions to be able to help:
- What is your env (SAPI)? web request or symfony command?
- How do you have access to
GlobalTracer? I.e. do you have a dependency in composer fordatadog/dd-traceor you rely on the classes made available by our extension? - If you are declaring a dependency in composer, is the version declared the same as the version of the installed extension?
If the answer to 1) is cli and the answer to 2) is 'composer' then you need to run the command as DD_TRACE_CLI_ENABLED=true.
Hi @labbati, sorry for the late reply but I didn't see your message until today. This is happening with
- Web request
- Using the classes made available by the extension
- Not applicable
Hi @labbati, attached a screenshot on how the trace_id and span_id are arriving to Datadog. Is it correct they arrive inside the string of the route? Shouldn't they be some kind of attributes of the log?

Hi @sdepablos, finding time to look into this issue is taking more than it should have. My apologies. Just dropping a message here to let you know that this is still in our radar and we will look into this asap.
Hello, FYI, we plan to work on logs-tracing correlation this quarter.
Hi @sdepablos,
At long last, Logs Correlation is now available with the tracer starting version 0.89.0. This documentation may also help you get started with it :smiley:
I'll be closing this issue for now, but feel free to open an other one in case you encounter an issue while connecting your logs and traces or if you have any feedback!