UNPKG

@opentelemetry/api

Version:
45 lines (44 loc) • 1.29 kB
import { createContextKey } from "../context/context.mjs"; import { ContextAPI } from "../api/context.mjs"; //#region src/baggage/context-helpers.ts /** * Baggage key */ const BAGGAGE_KEY = createContextKey("OpenTelemetry Baggage Key"); /** * Retrieve the current baggage from the given context * * @param {Context} Context that manage all context values * @returns {Baggage} Extracted baggage from the context */ function getBaggage(context) { return context.getValue(BAGGAGE_KEY) || void 0; } /** * Retrieve the current baggage from the active/current context * * @returns {Baggage} Extracted baggage from the context */ function getActiveBaggage() { return getBaggage(ContextAPI.getInstance().active()); } /** * Store a baggage in the given context * * @param {Context} Context that manage all context values * @param {Baggage} baggage that will be set in the actual context */ function setBaggage(context, baggage) { return context.setValue(BAGGAGE_KEY, baggage); } /** * Delete the baggage stored in the given context * * @param {Context} Context that manage all context values */ function deleteBaggage(context) { return context.deleteValue(BAGGAGE_KEY); } //#endregion export { deleteBaggage, getActiveBaggage, getBaggage, setBaggage }; //# sourceMappingURL=context-helpers.mjs.map