diff --git a/src/agent/aksLoader.ts b/src/agent/aksLoader.ts index 6ee47807..78407d17 100644 --- a/src/agent/aksLoader.ts +++ b/src/agent/aksLoader.ts @@ -11,7 +11,7 @@ import { InstrumentationOptions } from '../types'; import { OTLPMetricExporter as OTLPProtoMetricExporter } from "@opentelemetry/exporter-metrics-otlp-proto"; import { OTLPMetricExporter as OTLPHttpMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http"; import { MetricReader, PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics"; -import { OTLP_METRIC_EXPORTER_EXPORT_INTERVAL } from './types'; +import { ENV_OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, OTLP_METRIC_EXPORTER_EXPORT_INTERVAL } from './types'; export class AKSLoader extends AgentLoader { @@ -55,6 +55,9 @@ export class AKSLoader extends AgentLoader { ) ); + // Ensure Delta temporality is used for OTLP metrics + process.env[ENV_OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE] = "Delta"; + // Create metricReaders array and add OTLP reader if environment variables request it try { const metricReaders: MetricReader[] = []; diff --git a/src/agent/types.ts b/src/agent/types.ts index 0b6fbe4c..e3842027 100644 --- a/src/agent/types.ts +++ b/src/agent/types.ts @@ -5,6 +5,7 @@ export const AZURE_APP_NAME = process.env.WEBSITE_SITE_NAME || 'unknown'; export const AZURE_MONITOR_AUTO_ATTACH = "AZURE_MONITOR_AUTO_ATTACH"; export const OTLP_METRIC_EXPORTER_EXPORT_INTERVAL = 60000; // in ms +export const ENV_OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE = "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE"; export interface IAgentLogger { log(message: any, ...optional: any[]): void; diff --git a/test/unitTests/agent/aksLoader.tests.ts b/test/unitTests/agent/aksLoader.tests.ts index 4c03daa5..d57f9636 100644 --- a/test/unitTests/agent/aksLoader.tests.ts +++ b/test/unitTests/agent/aksLoader.tests.ts @@ -355,6 +355,21 @@ describe("agent/AKSLoader", () => { assert.equal(exporter.constructor.name, "OTLPMetricExporter", "Should be an OTLPMetricExporter"); }); + it("constructor sets OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE to Delta", () => { + const env = { + ["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333", + }; + process.env = env; + + new AKSLoader(); + + assert.equal( + process.env["OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE"], + "Delta", + "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE should be set to Delta" + ); + }); + it("constructor creates OTLP metric reader when OTEL_METRICS_EXPORTER contains mixed case otlp with other exporters", () => { const env = { ["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333",