Skip to content

Automatic injection is enabled, but trace_id is null in MDC context. #7495

@sinbom

Description

@sinbom

DD_LOGS_INECTION
Environment Variable: DD_LOGS_INJECTION
Default: true
Enabled automatic MDC key injection for Datadog trace and span IDs. See Advanced Usage for details.

String traceId = MDC.get("dd.trace_id"); // null
String spanId = MDC.get("dd.span_id"); // null

I'm trying to access trace_id, span_id injected into MDC context in application code with DD_LOGS_INCTION option enabled. but, no value is injected into the MDC and NULL is returned.

"dd.trace_id":"%X{dd.trace_id}", "dd.span_id":"%X{dd.span_id}"

What I didn't understand is that when I output the logs, if I use the format in logback-spring.xml that uses the trace_id, span_id keys of the MDC context, the values are present in the output logs. I already know that if I add the dd-trace-api dependency to my project and use CorrelationIdentifier, it returns trace_id, span_id. I would like to avoid adding dependencies if possible. The documentation describes the keys as being automatically injected into the MDC context, do I necessarily need to use CorrelationIdentifier to access them?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions