Application Insights 记录到错误的目标

Application Insights log to wrong target

我有两个网络应用程序。两者都将 App Insights JS SDK 添加到它们的视图中。

一个是大型网络应用程序,第二个是只有一个页面的小型微服务。他们有不同的检测键。

问题是我们在微服务AI资源中找到了"big app"的日志。当 "big app" 中发生错误时,可能会发生这种情况,用户重定向微服务页面,然后存在站点或关闭 window。缓冲区中的所有日志都是使用 AI JS SDK 从微服务页面发送的,即使它们没有发生在那里。

以上只是我的推测,没有其他的解释。 我不想使用一种人工智能资源,因为应用程序必须单独监控。

你有什么解决问题的想法吗?或者可能有不同的原因?

如果您使用的是最新版本的 Application Insights JS SDK,您可以指定 namePrefix 作为配置的一部分。这将在所有 cookie/sessionstorage/localstorage 键前加上这个字符串,这样它们就不会与 SDK 的其他实例冲突。

import { ApplicationInsights } from '@microsoft/applicationinsights-web'

const appInsights = new ApplicationInsights({ config: {
  instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE',
  namePrefix: 'my_app'
} });
appInsights.loadAppInsights();
appInsights.trackPageView();