ApplicationInsights-JS icon indicating copy to clipboard operation
ApplicationInsights-JS copied to clipboard

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

Open timtucker-dte opened this issue 1 year ago • 2 comments

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.

timtucker-dte avatar Feb 11 '25 18:02 timtucker-dte

Agree, the telemetry initializers added before initialization should be valid and therefore process every event.

MSNev avatar Feb 11 '25 19:02 MSNev

@siyuniu-ms Can you please investigate on why the above example is not "adding" and calling the telemetry initializer for all events. As I believe that we should be supporting adding the initializers before initialization (which is how the SDK Loader manages the onInit function)

MSNev avatar Feb 11 '25 19:02 MSNev