Skip to content

Commit

Permalink
Add Ability to Disable Statsbeat in the Exporter (#25919)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR
@azure/monitor-opentelemetry-exporter

### Describe the problem that is addressed by this PR
This PR allows statsbeat to be disabled via setting an environment
variable.

### Are there test cases added in this PR? _(If not, why?)_
Yes, added the relevant test to determine that statsbeat is disabled
when the environment variable is set.

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [x] Added a changelog (if necessary)
  • Loading branch information
JacksonWeber authored May 22, 2023
1 parent 9d828fc commit 2dd2c16
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 0 additions & 1 deletion sdk/monitor/monitor-opentelemetry-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

- Azure Monitor OpenTelemetry Metrics Exporter Configuration updated.


### Bugs Fixed

- Suppress tracing while exporting metrics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions sdk/monitor/monitor-opentelemetry-exporter/src/export/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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];
});
});
});
});

0 comments on commit 2dd2c16

Please sign in to comment.