cwany
cwany

Reputation: 113

Application Insights log to wrong target

I have two web apps. Both have App Insights JS SDK added to their views.

One is big web app and the second one is small microservice with one page. They have different instrumentation keys.

The problem is that we find logs from the "big app" in the microservice AI resource. This probably happens when something wrong happens in the "big app", user redirects the the microservice page and then exists the site or closes the window. All logs in the buffer are sent from microservice page using AI JS SDK, even though they did not happen there.

The above are just my assumptions, but I do not see any other explenation. I do not want to use one AI resource, because apps have to be monitored separately.

Do you have any ideas how to solve the problem? Or maybe there might be different reason for it?

Upvotes: 0

Views: 377

Answers (1)

Mark Wolff
Mark Wolff

Reputation: 124

If you are using the latest version of the Application Insights JS SDK, you can specify a namePrefix as part of your configuration. This will prefix all cookie/sessionstorage/localstorage keys with this string, so that they do not conflict with other instances of the 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();

Upvotes: 2

Related Questions