UNPKG

@azure/monitor-opentelemetry

Version:
35 lines 1.63 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.ensureAzureSdkTracingBridge = ensureAzureSdkTracingBridge; const api_1 = require("@opentelemetry/api"); /** * Eagerly installs the OpenTelemetry bridge for \@azure/core-tracing. * * The \@azure/opentelemetry-instrumentation-azure-sdk package normally installs * the bridge via a require-in-the-middle (RITM) hook that intercepts future * `require("@azure/core-tracing")` calls. However, if \@azure/core-tracing is * already loaded before useAzureMonitor() is called (e.g. because the customer * imported \@azure/ai-projects or any other Azure SDK package first), the hook * never fires, and Azure SDK spans are silently dropped. * * This function works around the issue by directly calling useInstrumenter() * with an instrumenter created via createOpenTelemetryInstrumenter(), which * patches the already-loaded \@azure/core-tracing singleton state. * * @internal */ function ensureAzureSdkTracingBridge() { try { // eslint-disable-next-line @typescript-eslint/no-require-imports const { useInstrumenter } = require("@azure/core-tracing"); // eslint-disable-next-line @typescript-eslint/no-require-imports const { createOpenTelemetryInstrumenter } = require("@azure/opentelemetry-instrumentation-azure-sdk"); useInstrumenter(createOpenTelemetryInstrumenter()); } catch (e) { api_1.diag.warn("Failed to install Azure SDK tracing bridge", e); } } //# sourceMappingURL=azureSdkTracingBridge.js.map