Managing Insights Application Files

I am wondering how applications work with cookies because I would like to understand user and session tracking, so I studied and ...

Here is a brief introduction to the theory:

  • Whenever the Application Insights SDK receives a request that does not have a proxy for tracking user cookie tracking (as installed by the Insight JS application fragment), it will set this cookie and start a new session. (from apmtips )

2.

UserTelemetryInitializer updates the Id and AcquisitionDate properties of the User context for all telemetry elements with values ​​retrieved from the ai_user cookie generated by the Application Insights JavaScript application code running in the user's browser.

SessionTelemetryInitializer updates the Session context's Id property for all telemetry elements with a value retrieved from the ai_session cookie generated by the JavaScript ApplicationInsights tool code running in the user's browser. (from azure documentation (configuring Insight SKD application with ApplicationInsights.config) )

So there are two cookies: ai_session and ai_user .

And here are my questions:

  • When are they initialized?
  • What does it do?
  • How can I stop using them?
  • If I wanted to save them, how can I change their expiration time?

Trying to remove them, I made a project using ASP.NET web applications using the default template for Web Api, which includes MVC and Web Api.

After researching, I found this approach to disable them, but I have no WebSessionTrackingTelemetryModule method. So I commented on "UserTelemetryInitializer" and "SessionTelemetryInitializer", and this is what I have:

<TelemetryInitializers> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.SyntheticTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.ClientIpHeaderTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.UserAgentTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.OperationNameTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.OperationIdTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" /> <!--<Add Type="Microsoft.ApplicationInsights.Extensibility.Web.UserTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" />--> <!--<Add Type="Microsoft.ApplicationInsights.Extensibility.Web.SessionTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" />--> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.AzureRoleEnvironmentTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.DomainNameRoleInstanceTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.DeviceTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web" /> </TelemetryInitializers> 

AND:

 <TelemetryModules> <Add Type="Microsoft.ApplicationInsights.Extensibility.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.ApplicationInsights.Extensibility.DependencyCollector" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector"/> <Add Type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.RequestTrackingTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Web"/> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.ExceptionTrackingTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Web" /> <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Web" /> </TelemetryModules> 

But it does not matter. Either I leave the modules commented, or not, cookies are still generated.

Trying to delete cookies, I commented on the actions taken in Startup and excluded all .js files from my project, but cookies continue to appear after each request.

So, at this moment, I don’t understand where “Javascript” is happening, and I assume that what I am missing is something in the backend. I am wrong?

Finally, my Startup.cs comment looks like this:

 [assembly: OwinStartupAttribute(typeof(Try001.Startup))] namespace Try001 { public partial class Startup { public void Configuration(IAppBuilder app) { //ConfigureAuth(app); } } } 

And my Global.asax.cs file looks like this:

 public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { //AreaRegistration.RegisterAllAreas(); //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); //BundleConfig.RegisterBundles(BundleTable.Bundles); } } 

Where RegisterRoutes just does the default routing. Therefore, I tried to do only the simplest things to make it work, but I do not know where to continue to dig.

Can anyone enlighten me?

Thanks for reading so far.

+8
c # azure-application-insights
source share
1 answer

The cookie initialization logic is executed in the Insights app SDK. If you look at the source of your page, you will see JS from // az 416426.vo.msecnd.net/scripts/a/ai.0.js. You can also read / contribute to the source code of the JavaScript SDK on GitHub: https://github.com/Microsoft/ApplicationInsights-JS

Answering your questions:

When are they initialized and what do they do? They are initialized by the JavaScript SDK, when it tries to send some telemetry element and checks if there is a cookie, it creates them. See https://github.com/Microsoft/ApplicationInsights-JS/blob/master/JavaScript/JavaScriptSDK/Context/User.ts for more details, there is also a similar logic for the session cookie.

How can I stop using them? You cannot disable these cookies if you use the JavaScript SDK, the only way to remove the JavaScript SDK (by removing the fragment that adds it to the page), however, this means that you will no longer have telemetry processing on the client side, such as the viewing page, client performance and user / session information.

If I wanted to save them, how can I change their expiration time? There are two parameters that you can control:

  • session resumption time - how much time elapsed before a reset session without activity (30 minutes by default)
  • end time - how much time elapses before a reset session even with activity (24 hours by default).

To change them, set the following values ​​in this fragment next to the toolbox key:

  ..snippet.. }({ instrumentationKey: "<your key>", sessionRenewalMs:<your custom value in ms>, sessionExpirationMs:<your custom value in ms> }); 
+7
source share

All Articles