4

The UserContext class provides 3 properties to identify the user. They are: AccountId, AuthenticatedUserId and Id.

What's the difference between them?

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30
hendoe
  • 153
  • 12

1 Answers1

7

At least from a docs perspective, this is what they mean:

  • UserId: The ID should be a Guid or another string complex enough to identify each user uniquely. For example, it could be a long random number. User IDs should persist across user sessions to track how users behave over time. There are various approaches for persisting the ID.
  • AuthenticatedUserId: In a web app, users are (by default) identified by cookies. A user might be counted more than once if they access your app from a different machine or browser, or if they delete cookies. You can thus get a more accurate count by setting the authenticated user ID in the browser code.

    Note: The user ID is also set in a session cookie and sent to the server. If the server SDK is installed, the authenticated user ID is sent as part of the context properties of both client and server telemetry. You can then filter and search on it.

  • AccountId: In multi-tenant applications this is the account ID or name, which the user is acting with. Examples may be subscription ID for Azure portal or blog name for a blogging platform.

References:

Hope this helps.

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30
  • Github issue link is dead – SubliemeSiem Feb 10 '21 at 07:40
  • https://learn.microsoft.com/en-us/azure/azure-monitor/app/data-model-context#anonymous-user-id explains as: Anonymous user id vs Authenticated user id – felickz Sep 28 '21 at 22:24
  • For many apps, all 3 of these are the same thing. So we end up having 3 duplicate properties in App Insights for every single event. – MgSam Nov 04 '21 at 18:30