diff --git a/src/api/propagation.ts b/src/api/propagation.ts index ab2a8118..6ef7e8a9 100644 --- a/src/api/propagation.ts +++ b/src/api/propagation.ts @@ -28,7 +28,11 @@ import { registerGlobal, unregisterGlobal, } from '../internal/global-utils'; -import { getBaggage, setBaggage } from '../baggage/context-helpers'; +import { + getBaggage, + setBaggage, + deleteBaggage, +} from '../baggage/context-helpers'; import { createBaggage } from '../baggage/utils'; const API_NAME = 'propagation'; @@ -108,6 +112,8 @@ export class PropagationAPI { public setBaggage = setBaggage; + public deleteBaggage = deleteBaggage; + private _getGlobalPropagator(): TextMapPropagator { return getGlobal(API_NAME) || NOOP_TEXT_MAP_PROPAGATOR; } diff --git a/src/api/trace.ts b/src/api/trace.ts index f44fe256..726b552a 100644 --- a/src/api/trace.ts +++ b/src/api/trace.ts @@ -27,6 +27,7 @@ import { import { Tracer } from '../trace/tracer'; import { TracerProvider } from '../trace/tracer_provider'; import { + deleteSpan, getSpan, getSpanContext, setSpan, @@ -89,6 +90,8 @@ export class TraceAPI { public isSpanContextValid = isSpanContextValid; + public deleteSpan = deleteSpan; + public getSpan = getSpan; public getSpanContext = getSpanContext; diff --git a/src/baggage/context-helpers.ts b/src/baggage/context-helpers.ts index 05b24a82..ae7b4a78 100644 --- a/src/baggage/context-helpers.ts +++ b/src/baggage/context-helpers.ts @@ -24,6 +24,8 @@ import { Baggage } from './types'; 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 */ @@ -32,9 +34,20 @@ export function getBaggage(context: Context): Baggage | undefined { } /** + * 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 */ export function setBaggage(context: Context, baggage: Baggage): Context { return context.setValue(BAGGAGE_KEY, baggage); } + +/** + * Delete the baggage stored in the given context + * + * @param {Context} Context that manage all context values + */ +export function deleteBaggage(context: Context): Context { + return context.deleteValue(BAGGAGE_KEY); +} diff --git a/src/trace/context-utils.ts b/src/trace/context-utils.ts index 3714eb96..1d24bc2e 100644 --- a/src/trace/context-utils.ts +++ b/src/trace/context-utils.ts @@ -44,6 +44,15 @@ export function setSpan(context: Context, span: Span): Context { return context.setValue(SPAN_KEY, span); } +/** + * Remove current span stored in the context + * + * @param context context to delete span from + */ +export function deleteSpan(context: Context): Context { + return context.deleteValue(SPAN_KEY); +} + /** * Wrap span context in a NoopSpan and set as span in a new * context