Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.

Commit e1745d1

Browse files
authored
feat(context): add utils method to remove keys from context #66 (#69)
1 parent 77b8c34 commit e1745d1

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

src/api/propagation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ import {
2828
registerGlobal,
2929
unregisterGlobal,
3030
} from '../internal/global-utils';
31-
import { getBaggage, setBaggage } from '../baggage/context-helpers';
31+
import {
32+
getBaggage,
33+
setBaggage,
34+
deleteBaggage,
35+
} from '../baggage/context-helpers';
3236
import { createBaggage } from '../baggage/utils';
3337

3438
const API_NAME = 'propagation';
@@ -108,6 +112,8 @@ export class PropagationAPI {
108112

109113
public setBaggage = setBaggage;
110114

115+
public deleteBaggage = deleteBaggage;
116+
111117
private _getGlobalPropagator(): TextMapPropagator {
112118
return getGlobal(API_NAME) || NOOP_TEXT_MAP_PROPAGATOR;
113119
}

src/api/trace.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import { Tracer } from '../trace/tracer';
2828
import { TracerProvider } from '../trace/tracer_provider';
2929
import {
30+
deleteSpan,
3031
getSpan,
3132
getSpanContext,
3233
setSpan,
@@ -89,6 +90,8 @@ export class TraceAPI {
8990

9091
public isSpanContextValid = isSpanContextValid;
9192

93+
public deleteSpan = deleteSpan;
94+
9295
public getSpan = getSpan;
9396

9497
public getSpanContext = getSpanContext;

src/baggage/context-helpers.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { Baggage } from './types';
2424
const BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key');
2525

2626
/**
27+
* Retrieve the current baggage from the given context
28+
*
2729
* @param {Context} Context that manage all context values
2830
* @returns {Baggage} Extracted baggage from the context
2931
*/
@@ -32,9 +34,20 @@ export function getBaggage(context: Context): Baggage | undefined {
3234
}
3335

3436
/**
37+
* Store a baggage in the given context
38+
*
3539
* @param {Context} Context that manage all context values
3640
* @param {Baggage} baggage that will be set in the actual context
3741
*/
3842
export function setBaggage(context: Context, baggage: Baggage): Context {
3943
return context.setValue(BAGGAGE_KEY, baggage);
4044
}
45+
46+
/**
47+
* Delete the baggage stored in the given context
48+
*
49+
* @param {Context} Context that manage all context values
50+
*/
51+
export function deleteBaggage(context: Context): Context {
52+
return context.deleteValue(BAGGAGE_KEY);
53+
}

src/trace/context-utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ export function setSpan(context: Context, span: Span): Context {
4444
return context.setValue(SPAN_KEY, span);
4545
}
4646

47+
/**
48+
* Remove current span stored in the context
49+
*
50+
* @param context context to delete span from
51+
*/
52+
export function deleteSpan(context: Context): Context {
53+
return context.deleteValue(SPAN_KEY);
54+
}
55+
4756
/**
4857
* Wrap span context in a NoopSpan and set as span in a new
4958
* context

0 commit comments

Comments
 (0)