UNPKG

@opentelemetry/api

Version:
1 lines • 2.01 kB
{"version":3,"file":"context-helpers.cjs","names":["createContextKey","ContextAPI"],"sources":["../../src/baggage/context-helpers.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ContextAPI } from '../api/context';\nimport { createContextKey } from '../context/context';\nimport type { Context } from '../context/types';\nimport type { Baggage } from './types';\n\n/**\n * Baggage key\n */\nconst BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key');\n\n/**\n * Retrieve the current baggage from the given context\n *\n * @param {Context} Context that manage all context values\n * @returns {Baggage} Extracted baggage from the context\n */\nexport function getBaggage(context: Context): Baggage | undefined {\n return (context.getValue(BAGGAGE_KEY) as Baggage) || undefined;\n}\n\n/**\n * Retrieve the current baggage from the active/current context\n *\n * @returns {Baggage} Extracted baggage from the context\n */\nexport function getActiveBaggage(): Baggage | undefined {\n return getBaggage(ContextAPI.getInstance().active());\n}\n\n/**\n * Store a baggage in the given context\n *\n * @param {Context} Context that manage all context values\n * @param {Baggage} baggage that will be set in the actual context\n */\nexport function setBaggage(context: Context, baggage: Baggage): Context {\n return context.setValue(BAGGAGE_KEY, baggage);\n}\n\n/**\n * Delete the baggage stored in the given context\n *\n * @param {Context} Context that manage all context values\n */\nexport function deleteBaggage(context: Context): Context {\n return context.deleteValue(BAGGAGE_KEY);\n}\n"],"mappings":";;;;;;AAaA,MAAM,cAAcA,gBAAAA,iBAAiB,2BAA2B;;;;;;;AAQhE,SAAgB,WAAW,SAAuC;CAChE,OAAQ,QAAQ,SAAS,WAAW,KAAiB,KAAA;AACvD;;;;;;AAOA,SAAgB,mBAAwC;CACtD,OAAO,WAAWC,kBAAAA,WAAW,YAAY,CAAC,CAAC,OAAO,CAAC;AACrD;;;;;;;AAQA,SAAgB,WAAW,SAAkB,SAA2B;CACtE,OAAO,QAAQ,SAAS,aAAa,OAAO;AAC9C;;;;;;AAOA,SAAgB,cAAc,SAA2B;CACvD,OAAO,QAAQ,YAAY,WAAW;AACxC"}