[BUG] Issues with setting (authenticated) user id using OpenTelemetry exporter
Library name and version
Azure.Monitor.OpenTelemetry.Exporter 1.2.0
Describe the bug
This is a follow-up on https://github.com/Azure/azure-sdk-for-net/issues/45089.
It looks like setting the opentelemetry tag enduser.id indeed sets the top-level user_AuthenticatedId, but it does not fully work as expected:
- it does not set
user_Idresulting in theAll usersbar chart to be filled with the value1. The below chart should have a higher value at the end of the timeline: - only when manually choosing
Authenticated usersfrom the dropdown, it works: - the
Authenticated Users Timelineworkbook does not work:
Apart from the functionality, enduser.id is deprecated and is recommended to be replaced by user.id.
Expected behavior
- Application Insights functionality related to Users and Authenticated Users works
- Used tag is not deprecated (currently
user.idis the expected value)
Actual behavior
- Only Authenticated Users works within the Users page in Application Insights. Users does not work. Other workbooks related to users like "Authenticated Users Timeline" do not work.
- Used tag is deprecated (
enduser.id) is deprecated
Reproduction Steps
- Create a project using the OpenTelemetry Azure Monitor Exporter, e.g. create a new Aspire.NET project.
- Add a (fictional) userId value by setting
activity.SetTag("enduser.id", userId). The value for now does not matter, this issue is about how the value is processed by the OpenTelemetry Exporter and how it is finally picked up by Application Insights. - See that the
Userspage in Application Insights only works whenAuthenticated Usersis selected from the dropdown.
activity.SetTag("user.id", userId); results in the user.id tag being added as custom dimension which is not picked up by the Out of the Box Application Insights pages and workbooks.
Environment
No response
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @cijothomas @rajkumar-rangaraj @reyang @TimothyMothra.
Note that https://github.com/Azure/azure-sdk-for-net/issues/45089 has some additional details on this. It was incorrectly closed (it has not been fixed, and will not be fixed by the consolidating issue) IMO.
I think the UX is broken because we're only setting the User Auth Id, but not the Anon Id. This is on our backlog, but we're blocked waiting for the community to define stable attributes.
Apart from the functionality, enduser.id is deprecated and is recommended to be replaced by user.id.
Yeah we're aware that enduser.id was depricated. We took a dependency on this while it was still experimental and we got burned. user.id is also experimental so we've decided to wait until the community has stable attributes.
We have someone from our team helping to driving this spec in the community.
Hi, I've seen that two days ago that the user.* properties have been shifted from experimental to development. I assume I can start to prepare the code to use those user. attributes, right?
See: https://github.com/open-telemetry/semantic-conventions/pull/1889 and https://github.com/open-telemetry/semantic-conventions/blob/main/docs/attributes-registry/user.md
@gboder - you can, but I would advise against switching to the OpenTelemetry exporter (if you're using the legacy one right now) unless you're game for doing a bunch of custom work to get the AI portal working correctly.
I was attempting to set enduser.id for an exception so that it would map to user_AuthenticatedId on exceptions in the AI portal. The closest I came was to use a processor for LogRecord, but I can only set attributes (maps to customDimensions) and not tags like the Activity processor. Am I missing something or is this not supported yet?
@ckschiefer - Exceptions become otel LogRecords, and attributes on the LogRecords become customDimensions.
The Azure Otel exporter doesn't provide a way to override the mappings that it performs (which is why everything becomes a customDimension), but if you're willing to hack hard enough you'll find that it works if you add a LogRecord processor with a negative weight (so it runs before the Azure Otel exporter). The .NET otel libs don't provide a way to set the LogProcessor weight, but you can do it using reflection.
So then, you need a way to pass the request cookie values to your LogProcessor so you can set the enduser.id before the otel exporter reads it. Use Baggage.SetBaggage(key, value); at the request level, and then read the baggage value in your LogProcessor.
Hope that helps... I stand by my previous comment:
.. I would advise against switching to the OpenTelemetry exporter (if you're using the legacy one right now) unless you're game for doing a bunch of custom work to get the AI portal working correctly.
@johncrim - Thanks for the info. I have already decided to use the AI SDK for now instead of doing custom work.