UNPKG

@azure/opentelemetry-instrumentation-azure-sdk

Version:
75 lines (74 loc) 3.01 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var instrumenter_exports = {}; __export(instrumenter_exports, { OpenTelemetryInstrumenter: () => OpenTelemetryInstrumenter, propagator: () => propagator }); module.exports = __toCommonJS(instrumenter_exports); var import_api = require("@opentelemetry/api"); var import_core = require("@opentelemetry/core"); var import_spanWrapper = require("./spanWrapper.js"); var import_configuration = require("./configuration.js"); var import_transformations = require("./transformations.js"); const propagator = new import_core.W3CTraceContextPropagator(); class OpenTelemetryInstrumenter { startSpan(name, spanOptions) { let ctx = spanOptions?.tracingContext || import_api.context.active(); let span; if ((0, import_configuration.envVarToBoolean)("AZURE_TRACING_DISABLED")) { span = import_api.trace.wrapSpanContext(import_api.INVALID_SPAN_CONTEXT); } else { span = import_api.trace.getTracer(spanOptions.packageName, spanOptions.packageVersion).startSpan(name, (0, import_transformations.toSpanOptions)(spanOptions), ctx); if ((0, import_configuration.envVarToBoolean)("AZURE_HTTP_TRACING_CHILDREN_DISABLED") && name.toUpperCase().startsWith("HTTP")) { ctx = (0, import_core.suppressTracing)(ctx); } } return { span: new import_spanWrapper.OpenTelemetrySpanWrapper(span), tracingContext: import_api.trace.setSpan(ctx, span) }; } withContext(tracingContext, callback, ...callbackArgs) { return import_api.context.with( tracingContext, callback, /** Assume caller will bind `this` or use arrow functions */ void 0, ...callbackArgs ); } parseTraceparentHeader(traceparentHeader) { return propagator.extract( import_api.context.active(), { traceparent: traceparentHeader }, import_api.defaultTextMapGetter ); } createRequestHeaders(tracingContext) { const headers = {}; propagator.inject(tracingContext || import_api.context.active(), headers, import_api.defaultTextMapSetter); return headers; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { OpenTelemetryInstrumenter, propagator }); //# sourceMappingURL=instrumenter.js.map