UNPKG

@azure/monitor-opentelemetry

Version:
40 lines 1.83 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); /** * ESM Loader entry point for Azure Monitor OpenTelemetry. * * For ESM applications, this loader MUST be used with the --import flag to ensure * instrumentation hooks are registered before any application modules are loaded. * This is required because ESM modules cannot be instrumented after they are loaded. * * Usage: node --import \@azure/monitor-opentelemetry/loader \<your-app-entry-point\> */ const nodeModule = tslib_1.__importStar(require("node:module")); const index_js_1 = require("./shared/logging/index.js"); const module_js_1 = require("./shared/module.js"); const OTEL_LOADER_SPECIFIER = "@opentelemetry/instrumentation/hook.mjs"; // Register the OpenTelemetry instrumentation loader immediately when this module is imported const registerFn = nodeModule .register; if (typeof registerFn === "function") { const parentURL = (0, module_js_1.getModuleParentURL)(); if (parentURL) { try { // eslint-disable-next-line @typescript-eslint/no-explicit-any const result = registerFn(OTEL_LOADER_SPECIFIER, parentURL); // Handle potential promise rejection (Node.js 20.6+ returns a promise-like object) if (result && typeof result.catch === "function") { void result.catch((error) => { index_js_1.Logger.getInstance().warn("Failed to register OpenTelemetry instrumentation loader", error); }); } } catch (error) { index_js_1.Logger.getInstance().warn("Failed to register OpenTelemetry instrumentation loader", error); } } } //# sourceMappingURL=loader.js.map