UNPKG

nestjs-otel

Version:
25 lines (24 loc) 885 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Baggage = exports.baggageParamFactory = void 0; const common_1 = require("@nestjs/common"); const api_1 = require("@opentelemetry/api"); const baggageParamFactory = (key, _ctx) => { const baggage = api_1.propagation.getBaggage(api_1.context.active()); if (!baggage) { return; } if (key) { return baggage.getEntry(key)?.value; } return baggage; }; exports.baggageParamFactory = baggageParamFactory; /** * Decorator to retrieve OpenTelemetry Baggage from the active context. * * @param key (Optional) The specific baggage key to retrieve. * If provided, returns the value (string) of that key. * If not provided, returns the entire Baggage object. */ exports.Baggage = (0, common_1.createParamDecorator)(exports.baggageParamFactory);