Unable to propagate UserId via MDC
Expected behavior
When I insert the userId into the logging context via MDC, I would expect that it would be mapped correctly.
Actual behavior
UserId is only visible as custom properties.
To Reproduce
// does not work
MDC.put("enduser.id", userId)
// does work
Span.current().setAttribute("enduser.id", userId)
System information
Please provide the following information:
- SDK Version: 3.4.15
- OS type and version: Windows
- Application Server type and version (if applicable):
- Using spring-boot? Yes (3.1.2)
- Additional relevant libraries (with version, if applicable):
hi @MatthiasMpo! MDC only applies to logs
hi @MatthiasMpo! MDC only applies to logs
Hi @trask, maybe I was not clear. I set enduser.id via MDC and Span Attribute.
After that only my requests and Dependencies had the correct user. Traces did not.
I would expect that the MDC properties are also able to map to Application Insights "default" properties.
Or is there another way to set the User Id for Traces in Java? In all my dotnet application it works via ITelemetryInitializer.
does this work for other MDC attributes, e.g. xyz? just trying to understand if it's something specific to enduser.id or not, thx
I also tried it with user_agent.original (SemanticConventions). It was respected in Request via Span, but not with MDC. If I use xyz I see in traces and request xyz as customDimensions.
I found enduser.id in the Microsoft Docu for Application Insights in Java: https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-add-modify?tabs=java#set-the-user-id-or-authenticated-user-id