Log correlation links your log records to the trace that was active when the log was emitted. In Datadog, this lets you jump directly from a log entry to the full distributed trace, and vice versa.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/datadog/dd-trace-js/llms.txt
Use this file to discover all available pages before exploring further.
How log correlation works
dd-trace injects trace identifiers into log records as structured fields:dd.trace_id— The current trace IDdd.span_id— The current span IDdd.service— The service namedd.env— The environmentdd.version— The application version
Automatic log injection
For supported logging libraries (pino, bunyan, winston), dd-trace can inject trace context automatically. Enable it with theDD_LOGS_INJECTION environment variable or the logInjection init option.
- Environment variable
- Programmatic
Logger examples
Manual log injection
If your logging library is not automatically supported, or you need finer control, inject trace context manually usingtracer.scope().active().
Getting individual fields
Access specific trace identifiers from the active span context:JSON log format requirements
For Datadog to correlate logs with traces, log records must be sent as JSON and include the trace fields in one of these formats: Nested underdd key (preferred):
Ensure logs are shipped to Datadog using the Datadog Agent or a supported log forwarder. The log pipeline processes the
dd.trace_id field to create the correlation link in the Datadog UI.Confirming log correlation is working
To verify that trace IDs are appearing in logs, run your application with a request and check the log output fordd.trace_id or the dd object. In the Datadog UI, open a log entry and look for the “View Trace” button, which appears when correlation is working.