microsoft / microsoft/ApplicationInsights-JS

[BUG] Unable to use telemetry initializer to filter calls to retrieve config from js.monitor.azure.com

Open
#2,480 2 comments 0 reactions 1 assignee View on GitHub

@siyuniu-ms is already working on this.

Since Feb 11, 2025.

bug
Dominant language
TypeScript
Stars
685
Forks
261
Avg merge
21h 33m
Merged PRs (30d)
5

Description

Trying to cut down on the # of 3rd party dependency calls that get logged from our app to keep log volumes down, but ran into difficulties suppressing App Insights' calls to load its own config.

We wind up with at least one dependency call logged per page load for the following URL:
GET https://js.monitor.azure.com/scripts/b/ai.config.1.cfg.json

I tried adding a telemetry initializer to filter dependencies based on hostname, but it looks like the call to fetch the config is made & logged as soon as the ApplicationInsights object is created.

Since addTelemetryInitializer isn't called until after that, there's nothing to prevent the SDK from logging that initial request.

Steps to Reproduce

  • OS/Browser: Windows / Edge
  • SDK Version: 3.3.4
  • How you initialized the SDK:
const config: IConfiguration & IConfig = {
	connectionString: connectionString,

	enableAutoRouteTracking: true,
	enableAjaxPerfTracking: true,
	enableAjaxErrorStatusText: true,
	enableCorsCorrelation: true,

	// Monitor all AJAX calls
	maxAjaxCallsPerView: -1,

	// Whether or not to disable telemetry
	disableTelemetry: disableTelemetry,
};

// This triggers a fetch that gets logged as a dependency
const appInsights = new ApplicationInsights({
	config: config,
});
// Filter to exclude traffic is here
appInsights.addTelemetryInitializer(filterDependencyTracking);

const reactPlugin = new ReactPlugin();
appInsights.addPlugin(reactPlugin);

appInsights.loadAppInsights();

Expected behavior

All telemetry events get processed via the telemetry initializer as long as it's registered before calling loadAppInsights.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.