microsoft / ApplicationInsights-Java

Application Insights for Java
http://aka.ms/application-insights
Other
295 stars 198 forks source link

Unable to propagate UserId via MDC #3254

Open MatthiasMpo opened 1 year ago

MatthiasMpo commented 1 year ago

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:

image

trask commented 1 year ago

hi @MatthiasMpo! MDC only applies to logs

MatthiasMpo commented 1 year ago

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.

trask commented 1 year ago

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

MatthiasMpo commented 1 year ago

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