2

I am trying to add the traceId to the logs of a Java Spring project for easier debugging. Tracing is already present in the project using opentracing:

@Bean
public Tracer tracer() {
    Tracer tracer = TracerResolver.resolveTracer();
    if (tracer != null) {
        GlobalTracer.registerIfAbsent(tracer);
    }

    return GlobalTracer.get();
}

The logging uses slf4j with log4j and the pattern:

"%d %-5p trace=%X{traceId} [%c{1}] - %m%n"

However, in the logs, there is no traceId present. How could this be added?

On another note, checking the full MDC (by using %X), I see a _requestId field. Is it different from traceId?

Ratoone
  • 110
  • 2
  • 9

0 Answers0