I am using the OTEL Spring Boot starter /
and trying to auto inject logs as per .6.x/docs/logger-mdc-instrumentation.md
I am using the default Logback configured in Spring Boot and using JSON based logging with the following libraries being used:
- implementation 'io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter'
- implementation 'net.logstash.logback:logstash-logback-encoder:8.0'
- implementation 'io.opentelemetry.instrumentation:opentelemetry-logback-mdc-1.0:2.13.3-alpha'
A snippet of the code is:
@GetMapping("/trace/svc2")
public ResponseEntity<String> service2(@RequestHeader Map<String, String> headers) {
System.out.println(String.format("Service 2 Traceparent: "+headers.get("traceparent")));
System.out.println(MDC.get("trace_id") + " " + MDC.get("span_id") + " " + MDC.get("span_flags")); --> Does not print anything
System.out.println(Span.current().getSpanContext().getTraceId()); --> Prints correctly
System.out.println(Span.current().getSpanContext().getSpanId()); --> Prints correctly
log.info("Inside service 2"); --> No trace_id, span_id injected.
ResponseEntity<String> response
= restTemplate.getForEntity("http://localhost:8081/trace/svc3", String.class);
return new ResponseEntity<String>(
String.format("Service 2 Listed %d headers", headers.size()), HttpStatus.OK);
}
I have annotated the parent class with @Slf4j and have verified that any custom attribute added by MDC.put() works absolutely fine.
Would you have any suggestions on what we are missing out?