diff --git a/README.md b/README.md index fe62608a6..3cf6feb3c 100644 --- a/README.md +++ b/README.md @@ -107,13 +107,7 @@ const config : AzureMonitorOpenTelemetryOptions = { bunyan: { enabled: true}, winston: { enabled: true}, } as InstrumentationOptions, - resource: resource, - extendedMetrics:{ - gc: true, - heap: true, - loop: true - } - + resource: resource }; useAzureMonitor(config); @@ -137,7 +131,6 @@ useAzureMonitor(config); | webInstrumentationConnectionString | Sets connection string used for web Instrumentation (Browser SDK Loader) (Optional, Default undefined) | | | instrumentationOptions | instrumentation options | { azureSdk: { enabled: true }, http: { enabled: true }, mongoDb: { enabled: true }, mySql: { enabled: true }, postgreSql: { enabled: true }, redis: { enabled: true }, redis4: { enabled: true }, console: { enabled: true}, bunyan: { enabled: true}, winston: { enabled: true} } | | resource | Opentelemetry Resource. [More info here](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-resources) | | -| extendedMetrics | Enable/Disable specific extended Metrics(gc, heap and loop). | {"gc": false, "heap": false, "loop": false} | Configuration could be set using configuration file `applicationinsights.json` located under root folder of applicationinsights package installation folder, Ex: `node_modules/applicationinsights`. @@ -183,7 +176,6 @@ And invoked via `appInsights.` | ----------------------------|------------------------------------------------------------------------------------------------------------| | setDistributedTracingMode | AI only tracing mode is no longer supported. Migrate to using W3C_AND_AI tracing mode. | | setAutoCollectHeartbeat | Heartbeat is not supported in either Azure Monitor OpenTelemetry or the shim.| -| enableWebInstrumenatation | WebInstrumentation is not supported in the shim, but is available in Azure Monitor OpenTelemetry as `enableBrowserSdkLoader` | | setAutoDependencyCorrelation| Turning off autoDependencyCorrelation is not supported by either Azure Monitor OpenTelemetry or the shim. | | setUseDiskRetryCaching | While enabling/disabling offline storage is supported, setting the resend interval or the maxBytesOnDisk values are not supported in the shim or Azure Monitor OpenTelemetry. | | setAutoCollectIncomingRequestAzureFunctions | Auto collection of Azure Functions is not supported by the shim or Azure Monitor OpenTelemetry. | @@ -209,6 +201,9 @@ The following configurations are set using either environment variables, setting | httpAgent/httpsAgent | Not supported in the shim or Azure Monitor OpenTelemetry. | | webInstrumentationConfig | Not currently supported by the shim or Azure Monitor OpenTelemetry. | | quickPulseHost | Not supported in the shim or Azure Monitor OpenTelemetry. | +| enableAutoCollectExtendedMetrics | Extended/native metrics are not supported in the shim or Azure Monitor OpenTelemetry. | +| disableAllExtendedMetrics | Will not have any effect as extended/native metrics are not supported in the shim or Azure Monitor OpenTelemetry. | +| extendedMetricDisablers | Will not have any effect as extended/native metrics are not supported in the shim or Azure Monitor OpenTelemetry. | The following methods are part of the `TelemetryClient` class. They can be called using `applicationinsights.defaultClient.()`. diff --git a/src/shim/applicationinsights.ts b/src/shim/applicationinsights.ts index ce4b14a1c..d4b8c9d8f 100644 --- a/src/shim/applicationinsights.ts +++ b/src/shim/applicationinsights.ts @@ -152,6 +152,7 @@ export class Configuration { public static setAutoCollectPerformance(value: boolean, collectExtendedMetrics: any) { if (defaultClient) { defaultClient.config.enableAutoCollectPerformance = value; + defaultClient.config.enableAutoCollectExtendedMetrics = collectExtendedMetrics; } return Configuration; } diff --git a/src/shim/shim-config.ts b/src/shim/shim-config.ts index f4de9dd20..0d27fa321 100644 --- a/src/shim/shim-config.ts +++ b/src/shim/shim-config.ts @@ -7,16 +7,14 @@ import { diag } from "@opentelemetry/api"; import { HttpInstrumentationConfig } from "@opentelemetry/instrumentation-http"; import { DistributedTracingModes, IConfig, IDisabledExtendedMetrics, IWebInstrumentationConfig } from "./types"; import { ShimJsonConfig } from "./shim-jsonConfig"; -import { AzureMonitorOpenTelemetryOptions, ExtendedMetricType, InstrumentationOptions, InstrumentationOptionsType } from "../types"; +import { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, InstrumentationOptionsType } from "../types"; +const ENV_azurePrefix = "APPSETTING_"; // Azure adds this prefix to all environment variables +const ENV_iKey = "APPINSIGHTS_INSTRUMENTATIONKEY"; // This key is provided in the readme +const legacy_ENV_iKey = "APPINSIGHTS_INSTRUMENTATION_KEY"; +const ENV_profileQueryEndpoint = "APPINSIGHTS_PROFILE_QUERY_ENDPOINT"; +const ENV_quickPulseHost = "APPINSIGHTS_QUICKPULSE_HOST"; class Config implements IConfig { - - public static ENV_azurePrefix = "APPSETTING_"; // Azure adds this prefix to all environment variables - public static ENV_iKey = "APPINSIGHTS_INSTRUMENTATIONKEY"; // This key is provided in the readme - public static legacy_ENV_iKey = "APPINSIGHTS_INSTRUMENTATION_KEY"; - public static ENV_profileQueryEndpoint = "APPINSIGHTS_PROFILE_QUERY_ENDPOINT"; - public static ENV_quickPulseHost = "APPINSIGHTS_QUICKPULSE_HOST"; - public connectionString: string; public endpointUrl: string; public maxBatchSize: number; @@ -251,47 +249,6 @@ class Config implements IConfig { process.env["APPLICATION_INSIGHTS_NO_STANDARD_METRICS"] = "disable"; } } - // NATIVE METRICS - if (typeof (this.enableAutoCollectExtendedMetrics) === "boolean") { - options.extendedMetrics = { - [ExtendedMetricType.gc]: this.enableAutoCollectExtendedMetrics, - [ExtendedMetricType.heap]: this.enableAutoCollectExtendedMetrics, - [ExtendedMetricType.loop]: this.enableAutoCollectExtendedMetrics, - }; - } - // Disable specific native metrics if provided - if (this.extendedMetricDisablers) { - const extendedMetricDisablers: string[] = this.extendedMetricDisablers.split(","); - for (const extendedMetricDisabler of extendedMetricDisablers) { - if (extendedMetricDisabler === "gc") { - options.extendedMetrics = { - ...options.extendedMetrics, - [ExtendedMetricType.gc]: false - }; - } - if (extendedMetricDisabler === "heap") { - options.extendedMetrics = { - ...options.extendedMetrics, - [ExtendedMetricType.heap]: false - }; - } - if (extendedMetricDisabler === "loop") { - options.extendedMetrics = { - ...options.extendedMetrics, - [ExtendedMetricType.loop]: false - }; - } - } - } - // Disable all native metrics - if (this.disableAllExtendedMetrics === true) { - options.extendedMetrics = { - ...options.extendedMetrics, - [ExtendedMetricType.gc]: false, - [ExtendedMetricType.heap]: false, - [ExtendedMetricType.loop]: false, - }; - } if (this.noDiagnosticChannel === true) { // Disable all instrumentations except http to conform with AppInsights 2.x behavior @@ -336,6 +293,15 @@ class Config implements IConfig { } // NOT SUPPORTED CONFIGURATION OPTIONS + if (this.enableAutoCollectExtendedMetrics === true || typeof(this.enableAutoCollectExtendedMetrics) === "object") { + this._configWarnings.push("Extended metrics are no longer supported."); + } + if (typeof this.disableAllExtendedMetrics === "boolean") { + this._configWarnings.push("Extended metrics are no longer supported."); + } + if (this.extendedMetricDisablers) { + this._configWarnings.push("Extended metrics are no longer supported."); + } if (this.disableAppInsights) { this._configWarnings.push("disableAppInsights configuration no longer supported."); } @@ -383,6 +349,20 @@ class Config implements IConfig { if (this.correlationHeaderExcludedDomains) { this._configWarnings.push("The correlationHeaderExcludedDomains configuration option is not supported by the shim."); } + if ( + process.env[ENV_iKey] || + process.env[legacy_ENV_iKey] || + process.env[ENV_azurePrefix + ENV_iKey] || + process.env[ENV_azurePrefix + legacy_ENV_iKey] + ) { + this._configWarnings.push("The iKey configuration option is not supported by the shim. Please configure the the connection string instead."); + } + if (process.env[ENV_profileQueryEndpoint]) { + this._configWarnings.push("The profileQueryEndpoint configuration option is not supported by the shim."); + } + if (process.env[ENV_quickPulseHost]) { + this._configWarnings.push("Please configure the quickPulseHost in the connection string instead."); + } return options; } } diff --git a/test/unitTests/shim/config.tests.ts b/test/unitTests/shim/config.tests.ts index f26a487f5..92fcc9087 100644 --- a/test/unitTests/shim/config.tests.ts +++ b/test/unitTests/shim/config.tests.ts @@ -86,7 +86,6 @@ describe("shim/configuration/config", () => { assert.equal(JSON.stringify(options.instrumentationOptions.bunyan), JSON.stringify({ enabled: true }), "wrong bunyan setting"); assert.equal(options.enableAutoCollectExceptions, true, "wrong enableAutoCollectExceptions"); assert.equal(options.enableAutoCollectPerformance, true, "wrong enableAutoCollectPerformance"); - assert.equal(JSON.stringify(options.extendedMetrics), JSON.stringify({ gc: true, heap: true, loop: true }), "wrong extendedMetrics"); assert.equal(options.azureMonitorExporterOptions.credential, config.aadTokenCredential, "wrong credential"); assert.equal(options.instrumentationOptions.http.enabled, true); assert.equal( @@ -102,9 +101,6 @@ describe("shim/configuration/config", () => { JSON.stringify({ timeoutMillis: 1000 }), "wrong otlpLogExporterConfig" ); assert.equal(options.azureMonitorExporterOptions.disableOfflineStorage, false, "wrong disableOfflineStorage"); - assert.equal(options.extendedMetrics.heap, true, "wrong heap"); - assert.equal(options.extendedMetrics.loop, true, "wrong loop"); - assert.equal(options.extendedMetrics.gc, true, "wrong gc"); }); it("should activate DEBUG internal logger", () => { @@ -125,13 +121,6 @@ describe("shim/configuration/config", () => { assert.equal(process.env["APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL"], "WARN"); }); - it("should disableAllExtendedMetrics", () => { - const config = new Config(connectionString); - config.disableAllExtendedMetrics = true; - let options = config.parseConfig(); - assert.equal(JSON.stringify(options.extendedMetrics), JSON.stringify({ gc: false, heap: false, loop: false })); - }); - it("should set context tags on logs and spans", () => { const telemetryClient = new TelemetryClient(connectionString); telemetryClient.context.tags = { "ai.cloud.role": "testRole", "ai.cloud.roleInstance": "testRoleInstance" }; @@ -213,15 +202,6 @@ describe("shim/configuration/config", () => { assert.equal(process.env["APPLICATION_INSIGHTS_NO_STANDARD_METRICS"], "disable"); }); - it("should disable specific native metrics", () => { - const config = new Config(connectionString); - config.extendedMetricDisablers = "heap,gc"; - config.parseConfig(); - let options = config.parseConfig(); - assert.equal(options.extendedMetrics.heap, false); - assert.equal(options.extendedMetrics.gc, false); - }); - describe("#Shim unsupported messages", () => { it("should warn if disableAppInsights is set", () => { const config = new Config(connectionString);