管理 Application Insights Cookie
Managing Application Insights Cookies
我想知道应用程序洞察力如何与 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 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 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.
我的问题来了:
- 它们什么时候初始化?
- 它在做什么?
- 我怎样才能停止使用它们?
- 如果我想保留它们,我该如何更改它们的过期时间?
试图删除它们我使用 ASP.NET Web 应用程序创建了一个项目,使用 Web Api 的默认模板,其中包括 MVC 和 Web Api。
进行研究后,我发现 this approach 可以禁用它们,但我没有任何 WebSessionTrackingTelemetryModule。所以我注释掉了 "UserTelemetryInitializer" 和 "SessionTelemetryInitializer" 这就是我所拥有的:
<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 仍在生成中。
试图删除 cookie,我评论了启动中完成的步骤,并从我的项目中排除了所有 .js 文件,但每次请求后 cookie 不断出现。
所以在这一点上我不明白 "Application Insights Javascript" 发生在哪里,我想我缺少的是后端的东西。我错了吗?
最后,我的评论 Startup.cs 看起来像:
[assembly: OwinStartupAttribute(typeof(Try001.Startup))]
namespace Try001
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
//ConfigureAuth(app);
}
}
}
我的 Global.asax.cs 看起来像:
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 只是在执行默认路由。所以我的目标是只做最基本的事情来让它工作,但我不知道在哪里继续挖掘。
谁能教教我?
感谢您到目前为止的阅读。
Cookie 初始化逻辑发生在 Application Insights JavaScript SDK 中。如果您查看页面的源代码,您会注意到来自 //az416426.vo.msecnd.net/scripts/a/ai.0.js 的 JS。您也可以在GitHub上read/contribute到JavaScript SDK的源代码:https://github.com/Microsoft/ApplicationInsights-JS
回复您的问题:
它们什么时候初始化的,它在做什么?
它们由 JavaScript SDK 初始化,当它尝试发送任何遥测项目并检查 cookie 是否不存在时,它会创建它们。详情见https://github.com/Microsoft/ApplicationInsights-JS/blob/master/JavaScript/JavaScriptSDK/Context/User.ts,session cookie也有类似的逻辑。
如何停止使用它们?
从更新的 JavaScript SDK 版本开始,您现在可以通过 config object:
...snippet...
}({
instrumentationKey: "<your key>",
isCookieUseDisabled: true,
isStorageUseDisabled: true,
enableSessionStorageBuffer: true
});
如果我想保留它们,我该如何更改它们的到期时间? 您可以控制两个设置:
- session renewal time - 会话重置前经过了多少时间
没有 activity(默认为 30 分钟)
- session过期时间-多少时间
即使使用 activity(默认为 24 小时),在重置会话之前也会经过。
要更改它们,请在此代码段中设置检测密钥的位置旁边设置以下值:
..snippet..
}({
instrumentationKey: "<your key>",
sessionRenewalMs:<your custom value in ms>,
sessionExpirationMs:<your custom value in ms>
});
我想知道应用程序洞察力如何与 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 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 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.
我的问题来了:
- 它们什么时候初始化?
- 它在做什么?
- 我怎样才能停止使用它们?
- 如果我想保留它们,我该如何更改它们的过期时间?
试图删除它们我使用 ASP.NET Web 应用程序创建了一个项目,使用 Web Api 的默认模板,其中包括 MVC 和 Web Api。
进行研究后,我发现 this approach 可以禁用它们,但我没有任何 WebSessionTrackingTelemetryModule。所以我注释掉了 "UserTelemetryInitializer" 和 "SessionTelemetryInitializer" 这就是我所拥有的:
<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 仍在生成中。
试图删除 cookie,我评论了启动中完成的步骤,并从我的项目中排除了所有 .js 文件,但每次请求后 cookie 不断出现。
所以在这一点上我不明白 "Application Insights Javascript" 发生在哪里,我想我缺少的是后端的东西。我错了吗?
最后,我的评论 Startup.cs 看起来像:
[assembly: OwinStartupAttribute(typeof(Try001.Startup))]
namespace Try001
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
//ConfigureAuth(app);
}
}
}
我的 Global.asax.cs 看起来像:
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 只是在执行默认路由。所以我的目标是只做最基本的事情来让它工作,但我不知道在哪里继续挖掘。
谁能教教我?
感谢您到目前为止的阅读。
Cookie 初始化逻辑发生在 Application Insights JavaScript SDK 中。如果您查看页面的源代码,您会注意到来自 //az416426.vo.msecnd.net/scripts/a/ai.0.js 的 JS。您也可以在GitHub上read/contribute到JavaScript SDK的源代码:https://github.com/Microsoft/ApplicationInsights-JS
回复您的问题:
它们什么时候初始化的,它在做什么?
它们由 JavaScript SDK 初始化,当它尝试发送任何遥测项目并检查 cookie 是否不存在时,它会创建它们。详情见https://github.com/Microsoft/ApplicationInsights-JS/blob/master/JavaScript/JavaScriptSDK/Context/User.ts,session cookie也有类似的逻辑。
如何停止使用它们?
从更新的 JavaScript SDK 版本开始,您现在可以通过 config object:
...snippet...
}({
instrumentationKey: "<your key>",
isCookieUseDisabled: true,
isStorageUseDisabled: true,
enableSessionStorageBuffer: true
});
如果我想保留它们,我该如何更改它们的到期时间? 您可以控制两个设置:
- session renewal time - 会话重置前经过了多少时间 没有 activity(默认为 30 分钟)
- session过期时间-多少时间 即使使用 activity(默认为 24 小时),在重置会话之前也会经过。
要更改它们,请在此代码段中设置检测密钥的位置旁边设置以下值:
..snippet..
}({
instrumentationKey: "<your key>",
sessionRenewalMs:<your custom value in ms>,
sessionExpirationMs:<your custom value in ms>
});