Closed ptabasso2 closed 7 months ago
You have not configured the appender that injects trace and span id into the mdc. See https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/logback/logback-mdc-1.0/library/README.md#usage Copy the logback.xml
from the readme into your application.
I’m not using the java agent. Essentially doing manual instrumentation using the java Otel SDK.
You could also use the OpenTelemetry starter. An OpenTelemetry bean will be provided and the Logback OpenTelemetry appender will be automatically added without any configuration.
You have not configured the appender that injects trace and span id into the mdc.
@laurit Wasn't it sufficient by doing this? It's the config from my application.properties
file
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - traceId: %X{trace_id} spanId: %X{span_id} - %msg%n
The only difference I'm seeing with the link you sent is the trace_flags
attribute which was not enabled in my case.
I will try with with the logback.xml and will let you know.
@jeanbisutti I will try it as well, thank you
@ptabasso2 the part that sets up the mdc appender is
<!-- Just wrap your logging appender, for example ConsoleAppender, with OpenTelemetryAppender -->
<appender name="OTEL" class="io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender">
<appender-ref ref="CONSOLE"/>
</appender>
@laurit That did the trick. It is working now. Thanks a lot!
Describe the bug
I’m currently trying to get the trace/log correlation working and was experimenting the MDC Instrumentation for logback integration
I’m using Spring Boot with
logback
andslf4j
I’m not using the java agent. Essentially doing manual instrumentation using the java Otel SDK. I’m using recent versions of spring 3.2 and otel sdk 1.35
Added the dependency to the project and changed the pattern layout of the file appender to add the the placeholders for both trace_id/span_id
But I can’t seem to see the trace_id/span_id values injected into the resulting log events. When debugging it, none of the fields or methods in the
OpenTelemetryAppender
class get picked.fyi when using
MDC.put()
the injection worksAny idea of how I could fix it?
Steps to reproduce
Providing the sample I'm using. sampleapp.tar.gz
It's the one used in the Otel getting started guide.
The build.gradle.kts has the dependency included
implementation("io.opentelemetry.instrumentation:opentelemetry-logback-mdc-1.0:1.32.1-alpha")
Note: I have tried several versions including the latest
application.properties
contains the configuration details for logback:curl command used:
curl http://localhost:8080/rolldice?rolls=12
OpenTelemetryAppender
fields or methods are picked.Expected behavior
The expected behavior is to see the trace/span ids injected to one of the log records.
Actual behavior
Those values are not present
Javaagent or library instrumentation version
No java agent. Otel SDK 1.35.0 (see dependency list above)
Environment
JDK:
OS:
gradle
Spring Boot
Additional context
No response