Skip to content

Need Help : Not injecting span_id and trace_id in log #11947

Answered by laurit
Yogeshsuch asked this question in Q&A
Discussion options

You must be logged in to vote

Firstly, we provide 2 appenders for logback. One is for exporting logs via otlp and the other one is for for injecting trace and span id into log. You are using the wrong one, you need https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/logback/logback-mdc-1.0/library. Secondly trace/span id is injected based on the span that is current in the context. You need to change your code that creates the span to

        Span span = tracer.spanBuilder("my-span").startSpan();
        try (Scope scope = span.makeCurrent()) {
            logger.info("Hello world");
            // Your business logic
            return "Hello, World!";
        } finally {
  …

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@Yogeshsuch
Comment options

@laurit
Comment options

@Yogeshsuch
Comment options

@laurit
Comment options

Answer selected by Yogeshsuch
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants