azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[BUG] Issues with setting (authenticated) user id using OpenTelemetry exporter

Open hansmbakker opened this issue 1 year ago • 8 comments

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_Id resulting in the All users bar chart to be filled with the value 1. The below chart should have a higher value at the end of the timeline: Image
  • only when manually choosing Authenticated users from the dropdown, it works: Image
  • the Authenticated Users Timeline workbook does not work: Image

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.id is 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

  1. Create a project using the OpenTelemetry Azure Monitor Exporter, e.g. create a new Aspire.NET project.
  2. 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.
  3. See that the Users page in Application Insights only works when Authenticated Users is 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

hansmbakker avatar Oct 22 '24 09:10 hansmbakker

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @cijothomas @rajkumar-rangaraj @reyang @TimothyMothra.

github-actions[bot] avatar Oct 22 '24 09:10 github-actions[bot]

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.

johncrim avatar Oct 22 '24 18:10 johncrim

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.

TimothyMothra avatar Oct 23 '24 00:10 TimothyMothra

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 avatar Feb 14 '25 07:02 gboder

@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.

johncrim avatar Feb 14 '25 16:02 johncrim

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 avatar Mar 26 '25 21:03 ckschiefer

@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 avatar Mar 28 '25 01:03 johncrim

@johncrim - Thanks for the info. I have already decided to use the AI SDK for now instead of doing custom work.

ckschiefer avatar Mar 28 '25 12:03 ckschiefer