管理应用程序见解Cookie [英] Managing Application Insights Cookies

查看:65
本文介绍了管理应用程序见解Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道应用程序见解如何与cookie一起使用,因为我想了解用户和会话跟踪,因此我一直在研究和...

I'm wondering how application insights work with cookies because I'll like to understand user and session tracking, so I've been researching and...

这里是有关该理论的简要介绍:

Here is a brief introduction about the theory:

每当Application Insights SDK收到不包含应用程序洞察力用户跟踪Cookie(由Application Insights JS代码段设置)的请求时,它都会设置该Cookie并开始新的会话. (摘自

Whenever Application Insights SDK get a request that doesn’t have application insights user tracking cookie (set by Application Insights JS snippet) it will set this cookie and start a new session. (from apmtips )

2.

UserTelemetryInitializer 为所有遥测项目更新 User 上下文的 Id AcquisitionDate 属性,并从中提取值.由用户浏览器中运行的Application Insights JavaScript工具代码生成的 ai_user Cookie.

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

SessionTelemetryInitializer 使用从 ai_session 中提取的值,为所有遥测项目更新 Session 上下文的 Id 属性.由在用户浏览器中运行的ApplicationInsights JavaScript工具代码生成的cookie. (摘自 azure文档(配置应用程序带有ApplicationInsights.config的Insights SKD))

SessionTelemetryInitializer updates the Id property of the Session context for all telemetry items with value extracted from the ai_session cookie generated by the ApplicationInsights JavaScript instrumentation code running in the user's browser. (from azure documentation (Configuring the Application Insights SKD with ApplicationInsights.config))

因此有两个Cookie: ai_session ai_user .

So there are two cookies: ai_session, and ai_user.

这是我的问题:

  1. 何时初始化?
  2. 正在做什么?
  3. 如何停止使用它们?
  4. 如果我想保留它们,我该如何更改它们的到期时间?

尝试删除它们,我使用ASP.NET Web应用程序使用Web Api的默认模板(包括MVC和Web Api)创建了一个项目.

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.

进行研究后发现

Doing a research I found this approach to disable them but I don't have any WebSessionTrackingTelemetryModule. So I commented out "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>

然后:

<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>

但这没什么区别.无论我是否对模块进行评论,cookie仍在生成.

But it doesn't make a difference. Either I leave the modules commented or not, the cookies are still being generated.

尝试删除cookie,我评论了Startup中完成的步骤,并从我的项目中排除了所有.js文件,但是cookie每次出现后都会出现.

Trying to remove the cookies, I commented the steps done in Startup and exclude from my project all the .js files, but the cookies keep appearing after every request.

因此,在这一点上,我不知道"Application Insights Javascript"在哪里发生,我想我缺少的是后端中的内容.我错了吗?

So at this point I don't understand where the "Application Insights Javascript" takes place and I guess that what I'm missing is something in the backend. Am I wrong?

最后,我评论的Startup.cs如下:

Finally, my commented Startup.cs looks like:

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

我的Global.asax.cs看起来像:

And my 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);
    }
}

RegisterRoutes仅在其中进行默认路由的地方.因此,我旨在做一些非常基本的事情来使其正常工作,但是我不知道在哪里继续挖掘.

Where RegisterRoutes is just doing the default routing. So I aimed to do just the very basic stuff to get it working, but I don't have a clue about where to keep digging.

有人可以启发我吗?

感谢您到目前为止的阅读.

Thanks for reading so far.

推荐答案

Cookie初始化逻辑发生在Application Insights JavaScript SDK中.如果您查看页面的源代码,您会注意到//azaz426426.vo.msecnd.net/scripts/a/ai.0.js中的JS.您还可以在GitHub上阅读/贡献JavaScript SDK的源代码: https://github.com/Microsoft/ApplicationInsights-JS

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

回答您的问题:

它们何时初始化以及正在做什么?
当JavaScript SDK尝试发送任何遥测项目并检查cookie是否不存在时,它们将由JavaScript SDK初始化,然后创建它们.有关详细信息,请参见 https://github.com/Microsoft/ApplicationInsights-JS/blob/master/JavaScript/JavaScriptSDK/Context/User.ts ,会话cookie也有类似的逻辑.

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.

如何停止使用它们?
从JavaScript SDK的最新版本开始,您现在可以通过

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:

  • 会话更新时间-重置会话之前经过了多少时间 没有活动(默认为30分钟)
  • 会话过期时间-多少时间 即使有活动,会话仍会在重置会话之前经过(默认为24小时).
  • 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>

    });

这篇关于管理应用程序见解Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆