Reputation: 1
As part of the Application Insights custom telemetry I create and send from my application, I can provide custom properties with Events that I choose to track. Those are then available later within the normal AI UI or Analytics interface to query against. Similarly, when a user begins a session, I can use the AI API to set the app-defined user identifier or an app-defined session identifier.
But is there a way to do a cross of the two? For example, is there a way that I could set a custom property for a given user (such as an audience or role she is part of)? Or a way to set a custom property for a given user session? (perhaps the connection type or company branch office they are in) There are plenty of predefined sort of user- and session-related properties that AI implicitly associates with each user session. (like city, country, device, etc.)
I would really like to set properties like these one time for that session (or user) and then be able to associate other activities during that user session with these properties. (such as custom events, metrics, trace entries, etc.) What I need to avoid is having to set such properties with every event, every trace, or every metric logged (e.g., with an ITelemetryInitializer), because I've got about 25 different ASP.NET apps instrumented on the client and server side and a couple of separate SaaS apps instrumented only on the client side. To try to introduce custom extensions and then continually and repeatedly determine the custom properties to be added to everything logged would be a monumental undertaking across a lot of teams.
Is this possible? If so, how? I haven't been able to find any mention of it in the API documentation and Intellisense snooping in the C# API has similarly turned up nothing obvious. (e.g., with Microsoft.ApplicationInsights.Channel.ITelemetry.Context.Session or .User)
Upvotes: 0
Views: 787
Reputation: 6281
Yes, you can set property once per session. Then use join to associate it with the rest of events.
For instance, below query counts events per session and then associates this count with custom property. After that it can be piped for further aggregations if needed.
let events = customEvents
| where timestamp > ago(1d);
events
| summarize count() by session_Id
| join kind=inner (
events
| where name == "MySingleEventPerSession"
| summarize any(*) by session_Id
) on session_Id
| project count_, any_customDimensions.MyCustomProperty, session_Id
Upvotes: 0