diff --git a/sdk/monitor/monitor-opentelemetry-exporter/CHANGELOG.md b/sdk/monitor/monitor-opentelemetry-exporter/CHANGELOG.md index 4f4c07d48a01..68cf97c4e81c 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/CHANGELOG.md +++ b/sdk/monitor/monitor-opentelemetry-exporter/CHANGELOG.md @@ -35,7 +35,6 @@ - Azure Monitor OpenTelemetry Metrics Exporter Configuration updated. - ### Bugs Fixed - Suppress tracing while exporting metrics. diff --git a/sdk/monitor/monitor-opentelemetry-exporter/src/Declarations/Constants.ts b/sdk/monitor/monitor-opentelemetry-exporter/src/Declarations/Constants.ts index 7ca1e4f21e47..e8cb32bca6a4 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/src/Declarations/Constants.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/src/Declarations/Constants.ts @@ -41,6 +41,11 @@ export const ENV_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING"; * @internal */ export const ENV_INSTRUMENTATION_KEY = "APPINSIGHTS_INSTRUMENTATIONKEY"; +/** + * Disable Statsbeat environment variable name. + * @internal + */ +export const ENV_DISABLE_STATSBEAT = "APPLICATION_INSIGHTS_NO_STATSBEAT"; /** * QuickPulse metric counter names. diff --git a/sdk/monitor/monitor-opentelemetry-exporter/src/export/base.ts b/sdk/monitor/monitor-opentelemetry-exporter/src/export/base.ts index 066593d85dc7..d87c57cfc57d 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/src/export/base.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/src/export/base.ts @@ -9,7 +9,11 @@ import { HttpSender, FileSystemPersist } from "../platform"; import { AzureMonitorExporterOptions } from "../config"; import { PersistentStorage, Sender } from "../types"; import { isRetriable, BreezeResponse } from "../utils/breezeUtils"; -import { DEFAULT_BREEZE_ENDPOINT, ENV_CONNECTION_STRING } from "../Declarations/Constants"; +import { + DEFAULT_BREEZE_ENDPOINT, + ENV_CONNECTION_STRING, + ENV_DISABLE_STATSBEAT, +} from "../Declarations/Constants"; import { TelemetryItem as Envelope } from "../generated"; import { NetworkStatsbeatMetrics } from "./statsbeat/networkStatsbeatMetrics"; import { MAX_STATSBEAT_FAILURES } from "./statsbeat/types"; @@ -68,7 +72,7 @@ export abstract class AzureMonitorBaseExporter { this._sender = new HttpSender(this._endpointUrl, this._options); this._persister = new FileSystemPersist(this._instrumentationKey, this._options); - if (!this._isStatsbeatExporter) { + if (!this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT]) { // Initialize statsbeatMetrics this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({ instrumentationKey: this._instrumentationKey, diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/internal/statsbeat.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/statsbeat.test.ts index c7ec3f456dd2..68580e5306d1 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/internal/statsbeat.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/statsbeat.test.ts @@ -5,7 +5,7 @@ import * as assert from "assert"; import { ExportResult, ExportResultCode } from "@opentelemetry/core"; import { failedBreezeResponse, successfulBreezeResponse } from "../utils/breezeTestUtils"; import { AzureMonitorBaseExporter } from "../../src/index"; -import { DEFAULT_BREEZE_ENDPOINT } from "../../src/Declarations/Constants"; +import { DEFAULT_BREEZE_ENDPOINT, ENV_DISABLE_STATSBEAT } from "../../src/Declarations/Constants"; import { TelemetryItem as Envelope } from "../../src/generated"; import nock from "nock"; import { NetworkStatsbeatMetrics } from "../../src/export/statsbeat/networkStatsbeatMetrics"; @@ -367,5 +367,15 @@ describe("#AzureMonitorStatsbeatExporter", () => { delete process.env.LONG_INTERVAL_EXPORT_MILLIS; }); }); + + describe("Disable Statsbeat", () => { + it("should disable statsbeat when the environement variable is set", () => { + process.env[ENV_DISABLE_STATSBEAT] = "true"; + const exporter = new TestExporter(); + assert.ok(!exporter["_networkStatsbeatMetrics"]); + assert.ok(!exporter["_longIntervalStatsbeatMetrics"]); + delete process.env[ENV_DISABLE_STATSBEAT]; + }); + }); }); });