最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

open telemetry - Trace_id and Span_id are not auto injected while using OpenTelemetry Spring Boot Starter - Stack Overflow

programmeradmin2浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论