Skip to content

Commit 93f4001

Browse files
authored
[Monitor OpenTelemetry][Monitor OpenTelemetry Exporter] Update Internal Version to Match Spec (#33298)
### Packages impacted by this PR @azure/monitor-opentelemetry @azure/monitor-opentelemetry-exporter ### Describe the problem that is addressed by this PR We should be able to differentiate between the application insights shim, azure monitor distro, and exporter. ### Are there test cases added in this PR? _(If not, why?)_ Yes ### 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)
1 parent 7ce0dd9 commit 93f4001

File tree

7 files changed

+68
-6
lines changed

7 files changed

+68
-6
lines changed

sdk/monitor/monitor-opentelemetry-exporter/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### Other Changes
66

77
- Filter OpenTelemetry semantic attributes from being double recorded as custom dimensions.
8+
- Add support for detecting the Application Insights shim on internal verison.
9+
810
## 1.0.0-beta.29 (2025-03-04)
911

1012
### Features Added

sdk/monitor/monitor-opentelemetry-exporter/src/Declarations/Constants.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ export enum RetriableRestErrorTypes {
9292
REQUEST_SEND_ERROR = "REQUEST_SEND_ERROR",
9393
DNS_LOOKUP_TIMEOUT = "EAI_AGAIN",
9494
}
95+
/**
96+
* Application Insights shim version.
97+
* @internal
98+
*/
99+
export const ENV_APPLICATIONINSIGHTS_SHIM_VERSION = "APPLICATION_INSIGHTS_SHIM_VERSION";
100+
/**
101+
* Azure Monitor version prefix.
102+
* @internal
103+
*/
104+
export const ENV_AZURE_MONITOR_PREFIX = "AZURE_MONITOR_PREFIX";
105+
/**
106+
* Azure Monitor Distro version.
107+
* @internal
108+
*/
109+
export const ENV_AZURE_MONITOR_DISTRO_VERSION = "AZURE_MONITOR_DISTRO_VERSION";
95110

96111
/**
97112
* QuickPulse metric counter names.

sdk/monitor/monitor-opentelemetry-exporter/src/platform/nodejs/context/context.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { ATTR_TELEMETRY_SDK_VERSION } from "@opentelemetry/semantic-conventions"
77
import { KnownContextTagKeys } from "../../../generated/index.js";
88
import * as ai from "../../../utils/constants/applicationinsights.js";
99
import type { Tags } from "../../../types.js";
10+
import {
11+
ENV_AZURE_MONITOR_PREFIX,
12+
ENV_APPLICATIONINSIGHTS_SHIM_VERSION,
13+
ENV_AZURE_MONITOR_DISTRO_VERSION,
14+
} from "../../../Declarations/Constants.js";
1015

1116
let instance: Context | null = null;
1217

@@ -39,13 +44,23 @@ export class Context {
3944
Context.opentelemetryVersion = SDK_INFO[ATTR_TELEMETRY_SDK_VERSION];
4045
Context.sdkVersion = ai.packageVersion;
4146

42-
const prefix = process.env["AZURE_MONITOR_PREFIX"] ? process.env["AZURE_MONITOR_PREFIX"] : "";
43-
const version = process.env["AZURE_MONITOR_DISTRO_VERSION"]
44-
? `ext${process.env["AZURE_MONITOR_DISTRO_VERSION"]}`
45-
: `ext${Context.sdkVersion}`;
47+
const prefix = process.env[ENV_AZURE_MONITOR_PREFIX]
48+
? process.env[ENV_AZURE_MONITOR_PREFIX]
49+
: "";
50+
const version = this._getVersion();
4651
const internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`;
4752
this.tags[KnownContextTagKeys.AiInternalSdkVersion] = internalSdkVersion;
4853
}
54+
55+
private _getVersion(): string {
56+
if (process.env[ENV_APPLICATIONINSIGHTS_SHIM_VERSION]) {
57+
return `sha${process.env[ENV_APPLICATIONINSIGHTS_SHIM_VERSION]}`;
58+
} else if (process.env[ENV_AZURE_MONITOR_DISTRO_VERSION]) {
59+
return `dst${process.env[ENV_AZURE_MONITOR_DISTRO_VERSION]}`;
60+
} else {
61+
return `ext${Context.sdkVersion}`;
62+
}
63+
}
4964
}
5065

5166
/**

sdk/monitor/monitor-opentelemetry-exporter/test/internal/context.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,21 @@ describe("context.ts", () => {
4242
"Wrong ai.internal.sdkVersion",
4343
);
4444
assert.ok(
45-
context.tags["ai.internal.sdkVersion"].endsWith(":ext_testDistroVersion"),
45+
context.tags["ai.internal.sdkVersion"].endsWith(":dst_testDistroVersion"),
4646
"Wrong ai.internal.sdkVersion",
4747
);
4848
});
49+
it("caputres the shim version when present", () => {
50+
const originalEnv = process.env;
51+
const newEnv = <{ [id: string]: string }>{};
52+
newEnv["APPLICATION_INSIGHTS_SHIM_VERSION"] = "_testShimVersion";
53+
process.env = newEnv;
54+
const context = new Context();
55+
context["_loadInternalContext"]();
56+
assert.ok(
57+
context.tags["ai.internal.sdkVersion"].endsWith(":sha_testShimVersion"),
58+
"Wrong ai.internal.sdkVersion",
59+
);
60+
process.env = originalEnv;
61+
});
4962
});

sdk/monitor/monitor-opentelemetry/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 1.9.1 ()
4+
5+
## Other Changes
6+
7+
- Add support for detecting the Application Insights shim on internal verison.
8+
39
## 1.9.0 (2025-03-04)
410

511
### Features Added

sdk/monitor/monitor-opentelemetry/src/metrics/quickpulse/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import { SDK_INFO, hrTimeToMilliseconds } from "@opentelemetry/core";
6262
import type { Histogram, ResourceMetrics } from "@opentelemetry/sdk-metrics";
6363
import { DataPointType } from "@opentelemetry/sdk-metrics";
6464
import {
65+
APPLICATION_INSIGHTS_SHIM_VERSION,
6566
AZURE_MONITOR_AUTO_ATTACH,
6667
AZURE_MONITOR_OPENTELEMETRY_VERSION,
6768
AZURE_MONITOR_PREFIX,
@@ -85,11 +86,20 @@ import { Logger } from "../../shared/logging";
8586
export function getSdkVersion(): string {
8687
const { nodeVersion } = process.versions;
8788
const opentelemetryVersion = SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_VERSION];
88-
const version = `ext${AZURE_MONITOR_OPENTELEMETRY_VERSION}`;
89+
const version = getSdkVersionType();
8990
const internalSdkVersion = `${process.env[AZURE_MONITOR_PREFIX] ?? ""}node${nodeVersion}:otel${opentelemetryVersion}:${version}`;
9091
return internalSdkVersion;
9192
}
9293

94+
/** Get the internal SDK version type */
95+
export function getSdkVersionType(): string {
96+
if (process.env[APPLICATION_INSIGHTS_SHIM_VERSION]) {
97+
return `sha${process.env[APPLICATION_INSIGHTS_SHIM_VERSION]}`;
98+
} else {
99+
return `dst${AZURE_MONITOR_OPENTELEMETRY_VERSION}`;
100+
}
101+
}
102+
93103
// eslint-disable-next-line tsdoc/syntax
94104
/** Set the version prefix to a string in the format "{ResourceProvider}{OS}m_ */
95105
export function setSdkPrefix(): void {

sdk/monitor/monitor-opentelemetry/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.9.0";
149149
export const AZURE_MONITOR_STATSBEAT_FEATURES = "AZURE_MONITOR_STATSBEAT_FEATURES";
150150
export const AZURE_MONITOR_PREFIX = "AZURE_MONITOR_PREFIX";
151151
export const AZURE_MONITOR_AUTO_ATTACH = "AZURE_MONITOR_AUTO_ATTACH";
152+
export const APPLICATION_INSIGHTS_SHIM_VERSION = "APPLICATION_INSIGHTS_SHIM_VERSION";
152153

153154
export enum AttachTypePrefix {
154155
INTEGRATED_AUTO = "i",

0 commit comments

Comments
 (0)