Override app insights client config for containerised node js azure web app

140 views Asked by At

When we used package deployment mode for our node.js app running on azure web app resource, we used the code-based way to override the default appInsights client configuration. Like that:

import {setup as setupAppInsigths} from "applicationinsights"

setupAppInsigths().
  .setAutoCollectDependencies(false)
  .start()

And it worked perfectly

But after we moved to container deployment mode, this stoped working and appInsights started to operate in the default mode, logging all outbound requests(e.g to the db) as dependencies, which we don't want.

We use standard node:18 docker image as a base for our app image.

I also tried to override this config by setting environment var APPLICATIONINSIGHTS_CONFIGURATION_CONTENT to { "enableAutoCollectDependencies": false, "autoCollectPerformanceExtendedMetrics": false, "enableSendLiveMetrics": false }, but this also doesn't seem to make any difference.

Is there some other configuration I need to do in order to override those default config when running node js in the container mode?

To make sure all config properties are set correctly on appInsights defaultClient, I added an endpoint in my app to show the content of defaultClient.config and all the props I set including enableAutoCollectDependencies are there:

{
"_endpointBase": "https://dc.services.visualstudio.com",
"_connectionString": "myConnectionString",
"_instrumentationKey": "",
"correlationHeaderExcludedDomains": [    "*.core.windows.net",    "*.core.chinacloudapi.cn",    "*.core.cloudapi.de",    "*.core.usgovcloudapi.net",    "*.core.microsoft.scloud",    "*.core.eaglex.ic.gov"],
"correlationIdRetryIntervalMs": 30000,
"disableAllExtendedMetrics": false,
"disableAppInsights": false,
"disableStatsbeat": false,
"enableAutoCollectConsole": false,
"enableAutoCollectDependencies": false,
"enableAutoCollectIncomingRequestAzureFunctions": false,
"enableAutoCollectExceptions": true,
"enableAutoCollectExtendedMetrics": false,
"enableAutoCollectExternalLoggers": true
,"enableAutoCollectHeartbeat": true,
"enableAutoCollectPerformance": false,
"enableAutoCollectPreAggregatedMetrics": true,
"enableAutoCollectRequests": true,
"enableAutoDependencyCorrelation": true,
"enableSendLiveMetrics": false,
"enableUseDiskRetryCaching": true,
"endpointUrl": "https://eastus-8.in.applicationinsights.azure.com/v2.1/track",
"ignoreLegacyHeaders": false,
"maxBatchIntervalMs": 15000,
"maxBatchSize": 250,
"quickPulseHost": "eastus.livediagnostics.monitor.azure.com",
"samplingPercentage": 100,
"enableWebInstrumentation": false,
"_webInstrumentationConnectionString": "",
"webInstrumentationConfig": null,
"webInstrumentationSrc": "",
"enableAutoWebSnippetInjection": false,
"_profileQueryEndpoint": "https://eastus-8.in.applicationinsights.azure.com/",
"correlationId": "cid-v1:"
}

But I still see the dependencies for http requests to the database...

1

There are 1 answers

0
Dmitry Klochkov On

Ok, after a day of struggle I found a fix for that issue. Looks like automatically injected AppInsights sdk doesn't respect any custom configurations any more(or when running in container mode), nor set to the appInsights default client programmatically nor specified in APPLICATIONINSIGHTS_CONFIGURATION_CONTENT env var.

So my current solution is to disable that auto-infected sdk completely by setting InstrumentationEngine_EXTENSION_VERSION=disabled

Azure portal now shows "Enable Application Insights without redeploying your code" message and a button to "Turn on Application insights" on the app insights blade as if it is disabled, but it will work fine while you have other app insights related env vars in place, like APPINSIGHTS_INSTRUMENTATIONKEY, and a long as you configure the appinsights client in your code.