Connecting Java logs and Traces traceId and span Id have the value of Zero

Viewed 158

I am following the Connecting Java logs and Traces from the Datadog docs: https://docs.datadoghq.com/tracing/connect_logs_and_traces/java/?tab=slf4jandlogback

I added the next code to my endpoint:

import org.slf4j.MDC;
import datadog.trace.api.CorrelationIdentifier;

// There must be spans started and active before this block.
try {
    MDC.put("dd.trace_id", CorrelationIdentifier.getTraceId());
    MDC.put("dd.span_id", CorrelationIdentifier.getSpanId());

// Log something

} finally {
    MDC.remove("dd.trace_id");
    MDC.remove("dd.span_id");
}

In the console I can see the next logs: dd.trace_id":"0","dd.span_id":"0"}

I am not pretty sure why I am not getting a correct trace_id and span_id and why these values are Zero.

Any ideas?

0 Answers
Related