Skip to content

Commit

Permalink
[Beta] Update Support Status of Native Metrics & Env Vars (#1298)
Browse files Browse the repository at this point in the history
* Update unsupported docs and API to show setting extended metrics values as unsupported.

* Remove unneeded tests.

* Update env var support.
  • Loading branch information
JacksonWeber committed Mar 21, 2024
1 parent 2d8c42f commit e0528d3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 78 deletions.
13 changes: 4 additions & 9 deletions README.md
Expand Up @@ -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);

Expand All @@ -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`.

Expand Down Expand Up @@ -183,7 +176,6 @@ And invoked via `appInsights.<METHOD_NAME>`
| ----------------------------|------------------------------------------------------------------------------------------------------------|
| 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. |
Expand All @@ -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.<METHOD_NAME>()`.

Expand Down
1 change: 1 addition & 0 deletions src/shim/applicationinsights.ts
Expand Up @@ -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;
}
Expand Down
78 changes: 29 additions & 49 deletions src/shim/shim-config.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
20 changes: 0 additions & 20 deletions test/unitTests/shim/config.tests.ts
Expand Up @@ -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(
Expand All @@ -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", () => {
Expand All @@ -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" };
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e0528d3

Please sign in to comment.