c# - Managing Application Insights Cookies -


i'm wondering how application insights work cookies because i'll understand user , session tracking, i've been researching and...

here brief introduction theory:

  1. whenever application insights sdk request doesn’t have application insights user tracking cookie (set application insights js snippet) set cookie , start new session. (from apmtips )

2.

usertelemetryinitializer updates id , acquisitiondate properties of user context telemetry items values extracted ai_user cookie generated application insights javascript instrumentation code running in user's browser.

sessiontelemetryinitializer updates id property of session context telemetry items value extracted ai_session cookie generated applicationinsights javascript instrumentation code running in user's browser. (from azure documentation (configuring application insights skd applicationinsights.config))

so there 2 cookies: ai_session, , ai_user.

and here comes questions:

  1. when initialized?
  2. what doing it?
  3. how can stop using them?
  4. if wanted keep them, how change expiration time?

trying remove them made project using asp.net web applications using default template web api, includes mvc , web api.

doing research found this approach disable them don't have websessiontrackingtelemetrymodule. commented out "usertelemetryinitializer" , "sessiontelemetryinitializer" , 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 doesn't make difference. either leave modules commented or not, cookies still being generated.

trying remove cookies, commented steps done in startup , exclude project .js files, cookies keep appearing after every request.

so @ point don't understand "application insights javascript" takes place , guess i'm missing in backend. wrong?

finally, commented startup.cs looks like:

[assembly: owinstartupattribute(typeof(try001.startup))] namespace try001 {     public partial class startup     {          public void configuration(iappbuilder app)          {                //configureauth(app);          }     }   } 

and global.asax.cs looks like:

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 doing default routing. aimed basic stuff working, don't have clue keep digging.

could enlighten me?

thanks reading far.

cookie initialization logic happens in application insights javascript sdk. if in source of page notice js //az416426.vo.msecnd.net/scripts/a/ai.0.js. can read/contribute source code of javascript sdk on github: https://github.com/microsoft/applicationinsights-js

replying questions:

when initialized , doing it? initialized javascript sdk when attempts send telemetry item , checks if cookie not present, creates them. details see https://github.com/microsoft/applicationinsights-js/blob/master/javascript/javascriptsdk/context/user.ts, there's similar logic session cookie.

how can stop using them? cannot disable these cookies if you're using javascript sdk, way remove javascript sdk (by removing snippet adds page), mean no longer have client-side telemetry, page views , client performance , users/sessions information.

if wanted keep them, how change expiration time? there 2 settings can control:

  • session renewal time - how time elapses before session reset no activity (default 30 minutes)
  • session expiration time - how time elapses before session reset activity (default 24 hours).

to change them set following values in snippet next instrumentation key set:

      ..snippet..  }({         instrumentationkey: "<your key>",         sessionrenewalms:<your custom value in ms>,         sessionexpirationms:<your custom value in ms>      }); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -