Managing Application Insights Cookies

瘦欲@ 提交于 2019-12-04 01:41:42
Alex Bulankou

Cookie initialization logic happens in Application Insights JavaScript SDK. If you look in the source of your page you will notice JS from //az416426.vo.msecnd.net/scripts/a/ai.0.js. You can also read/contribute to the source code of JavaScript SDK on GitHub: https://github.com/Microsoft/ApplicationInsights-JS

Replying to your questions:

When are they initialized and what is doing it?
They are initialized by JavaScript SDK when it attempts to send any telemetry item and checks if the cookie are not present, it creates them. For details see https://github.com/Microsoft/ApplicationInsights-JS/blob/master/JavaScript/JavaScriptSDK/Context/User.ts, there's also similar logic for session cookie.

How can I stop using them?
As of the more recent versions of the JavaScript SDK, you can now control the cookies as well as the local storage for both user information and the session buffer (used to rate limit the requests to AI) through the config object:

...snippet...
}({
    instrumentationKey: "<your key>",
    isCookieUseDisabled: true,
    isStorageUseDisabled: true,
    enableSessionStorageBuffer: true
});

If I wanted to keep them, how could I change their expiration time? There are two settings you can control:

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

To change them set following values in this snippet next to where instrumentation key is set:

      ..snippet..
 }({
        instrumentationKey: "<your key>",
        sessionRenewalMs:<your custom value in ms>,
        sessionExpirationMs:<your custom value in ms>

    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!