Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Monitor OpenTelemetry Exporter] Don't Apply Cloud Tags to Statsbeat Telemetry #33229

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/monitor/monitor-opentelemetry-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Other Changes

- Removed faulty span exception exporting logic.
- Remove applying cloud.* tags to statsbeat telemetry.

## 1.0.0-beta.28 (2025-01-28)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
MetricDataPoint,
} from "../generated/index.js";
import { createTagsFromResource } from "./common.js";
import { BreezePerformanceCounterNames, OTelPerformanceCounterNames } from "../types.js";
import { BreezePerformanceCounterNames, OTelPerformanceCounterNames, Tags } from "../types.js";
import {
ENV_OTEL_METRICS_EXPORTER,
ENV_OTLP_METRICS_ENDPOINT,
Expand Down Expand Up @@ -56,13 +56,14 @@ export function resourceMetricsToEnvelope(
const envelopes: Envelope[] = [];
const time = new Date();
const instrumentationKey = ikey;
const tags = createTagsFromResource(metrics.resource);
let tags: Tags;
let envelopeName: string;

if (isStatsbeat) {
envelopeName = "Microsoft.ApplicationInsights.Statsbeat";
} else {
envelopeName = "Microsoft.ApplicationInsights.Metric";
tags = createTagsFromResource(metrics.resource);
}

metrics.scopeMetrics.forEach((scopeMetric) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { BreezePerformanceCounterNames, OTelPerformanceCounterNames } from "../.
import { Context, getInstance } from "../../src/platform/index.js";
import { describe, it, assert } from "vitest";
import { ENV_APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED } from "../../src/Declarations/Constants.js";
import { StatsbeatCounter } from "../../src/export/statsbeat/types.js";

const context = getInstance();
const packageJsonPath = path.resolve(__dirname, "../../", "./package.json");
Expand Down Expand Up @@ -88,6 +89,22 @@ function assertEnvelope(
}
}

function assertStatsbeatEnvelope(
envelope: Envelope,
name: string,
sampleRate: number,
baseType: string,
): void {
assert.ok(envelope);
assert.strictEqual(envelope.name, name);
assert.strictEqual(envelope.sampleRate, sampleRate);
assert.deepStrictEqual(envelope.data?.baseType, baseType);

assert.strictEqual(envelope.instrumentationKey, "ikey");

assert.deepStrictEqual(envelope.tags, undefined);
}

describe("metricUtil.ts", () => {
it("should not send custom metrics to Breeze if env var is set to disable", async () => {
const originalEnv = process.env;
Expand Down Expand Up @@ -533,5 +550,33 @@ describe("metricUtil.ts", () => {
);
process.env = originalEnv;
});
it("should add not attach tags to statsbeat telemetry", async () => {
const provider = new MeterProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "basic-service",
}),
});
const exporter = new TestExporter({
connectionString: "InstrumentationKey=00000000-0000-0000-0000-000000000000",
});
const metricReaderOptions: PeriodicExportingMetricReaderOptions = {
exporter: exporter,
};
const metricReader = new PeriodicExportingMetricReader(metricReaderOptions);
provider.addMetricReader(metricReader);
const meter = provider.getMeter("example-meter-node");
// Create Counter instrument with the meter
const counter = meter.createCounter(StatsbeatCounter.SUCCESS_COUNT);
counter.add(1);
provider.forceFlush();
await new Promise((resolve) => setTimeout(resolve, 800));
const envelope = resourceMetricsToEnvelope(testMetrics, "ikey", true);
assertStatsbeatEnvelope(
envelope[0],
"Microsoft.ApplicationInsights.Statsbeat",
100,
"MetricData",
);
});
});
});
Loading