Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDC attributes not captured with spring boot application using log4j. #12540

Open
nityanandagohain opened this issue Oct 30, 2024 · 6 comments · May be fixed by #12592
Open

MDC attributes not captured with spring boot application using log4j. #12540

nityanandagohain opened this issue Oct 30, 2024 · 6 comments · May be fixed by #12592

Comments

@nityanandagohain
Copy link

nityanandagohain commented Oct 30, 2024

I am using log4j in my spring boot application. The issue that I am facing is that the MDC attributes are not captured even after adding otel.instrumentation.log4j-appender.experimental.capture-mdc-attributes=* . Do I need to configure anything else ?

The other settings like otel.instrumentation.log4j-appender.experimental-log-attributes work as as expected.


update: I am able to get mdc attributes if I add them

ThreadContext.put("userId", "myid");
ThreadContext.put("requestId", "reqID");

But how do I capture attributes like className / LoggerName ?

@trask trask transferred this issue from open-telemetry/opentelemetry-java Oct 30, 2024
@trask
Copy link
Member

trask commented Oct 30, 2024

hi @nityanandagohain, are you using the OpenTelemetry Spring Boot starter or the OpenTelemetry Java agent or the OpenTelemetry Log4j Appender artifact?

@nityanandagohain
Copy link
Author

hi @trask I am using the otel java agent

here is the code that I am using to test it https://github.com/nityanandagohain/otel_log4j

this is the run command I am using

OTEL_METRICS_EXPORTER=none OTEL_LOGS_EXPORTER=otlp OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317"  OTEL_RESOURCE_ATTRIBUTES=service.name=test java -javaagent:"/Users/nityanandagohain/Downloads/opentelemetry-javaagent.jar" -Dotel.instrumentation.log4j-appender.experimental.capture-marker-attribute=true -Dotel.instrumentation.log4j-appender.experimental.capture-mdc-attributes='*' -jar target/*.jar

@trask
Copy link
Member

trask commented Oct 30, 2024

-Dotel.instrumentation.log4j-appender.experimental.capture-mdc-attributes='*'

my first guess would be that it's a shell quoting issue, maybe try

'-Dotel.instrumentation.log4j-appender.experimental.capture-mdc-attributes=*'

@laurit
Copy link
Contributor

laurit commented Oct 31, 2024

But how do I capture attributes like className / LoggerName ?

Capturing the class/method/line that logged the message is currently not implemented for log4j. It is implemented for logback. Logger name is set as InstrumentationScope.

@laurit laurit added the needs author feedback Waiting for additional feedback from the author label Oct 31, 2024
@nityanandagohain
Copy link
Author

Thanks @trask , the custom mdc attributes were captured but I wanted cass/method/line etc for log4j which doesn't seem to be supported as per @laurit .

Do we have any roadmap if it will be added for log4j ?
Thanks :)

@github-actions github-actions bot removed the needs author feedback Waiting for additional feedback from the author label Nov 1, 2024
@trask
Copy link
Member

trask commented Nov 5, 2024

hi @nityanandagohain, if you can create a new issue targeted at that feature (and closing this issue), we will tag it as "contribution welcome".

@laurit laurit linked a pull request Nov 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants