UNPKG

@azure/monitor-opentelemetry-exporter

Version:

Application Insights exporter for the OpenTelemetry JavaScript (Node.js) SDK

48 lines 1.75 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import * as os from "node:os"; import { SDK_INFO } from "@opentelemetry/core"; import { ATTR_TELEMETRY_SDK_VERSION } from "@opentelemetry/semantic-conventions"; import { KnownContextTagKeys } from "../../../generated/index.js"; import * as ai from "../../../utils/constants/applicationinsights.js"; let instance = null; /** * Azure Telemetry context. * @internal */ export class Context { constructor() { this.tags = {}; this._loadDeviceContext(); this._loadInternalContext(); } _loadDeviceContext() { this.tags[KnownContextTagKeys.AiDeviceOsVersion] = os && `${os.type()} ${os.release()}`; } _loadInternalContext() { const { node } = process.versions; [Context.nodeVersion] = node.split("."); Context.opentelemetryVersion = SDK_INFO[ATTR_TELEMETRY_SDK_VERSION]; Context.sdkVersion = ai.packageVersion; const prefix = process.env["AZURE_MONITOR_PREFIX"] ? process.env["AZURE_MONITOR_PREFIX"] : ""; const version = process.env["AZURE_MONITOR_DISTRO_VERSION"] ? `ext${process.env["AZURE_MONITOR_DISTRO_VERSION"]}` : `ext${Context.sdkVersion}`; const internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`; this.tags[KnownContextTagKeys.AiInternalSdkVersion] = internalSdkVersion; } } Context.sdkVersion = null; Context.opentelemetryVersion = null; Context.nodeVersion = ""; /** * Singleton Context instance * @internal */ export function getInstance() { if (!instance) { instance = new Context(); } return instance; } //# sourceMappingURL=context.js.map