Support `setAuthenticatedUserContext`
See original GitHub issueThe ApplicationInsights-JS SDK supports a method called setAuthenticatedUserContext which sends a custom auth token with each event.
The client code is basically just doing some validation then updating the ai.user.authUserId tag.
On the server, it looks like the same thing can be done, but is not documented:
let client = appInsights.defaultClient;
let key = client.context.keys.userAuthUserId;
client.context.tags[key] = <authToken>;
Providing this same method on the server side would be helpful for several reasons:
- A users client and server activity can be tied together by the custom auth id
- SDK users don’t have to figure this out themselves
- SDK consistency
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Tracking your authenticated users with Azure AppInsights
setAuthenticatedUserContext (userId);. This will create a cookie that will track your authenticated user on each event/page view/request. The ...
Read more >Application Insights API for custom events and metrics
Use the Application Insights core telemetry API to send custom events and metrics and your own versions of standard telemetry. This API is...
Read more >Application insights setAuthenticatedUserContext with API ...
I have Application Insights configured on both the front and back-end of my website, which operate on different sub-domains (let's say www.
Read more >Azure Application Insights
... to create an Azure Application Insights service and hook it up with your ... to setAuthenticatedUserContext() passing a user.id and role.
Read more >Power Apps Portals - Application Insights Authenticated Users
Would be great if anyone could help getting back on track . ... "];f.length;)b("track"+f.pop());if(b("setAuthenticatedUserContext") ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This is what I ended up going with
Great catch!
The JS SDK can also provide this userId to the server-side using the “ai_authUser” cookie. It’s my understanding that our .NET SDK will read this cookie and automatically set the authUserId that it received from the JS SDK. It would be nice to implement that here as well.