From e1745d19b9bdfd1af7d805a6b2c32a5a5dbf4d15 Mon Sep 17 00:00:00 2001 From: Valentin Marchaud Date: Fri, 21 May 2021 14:16:47 +0200 Subject: [PATCH 1/2] feat(context): add utils method to remove keys from context #66 (#69) --- src/api/propagation.ts | 8 +++++++- src/api/trace.ts | 3 +++ src/baggage/context-helpers.ts | 13 +++++++++++++ src/trace/context-utils.ts | 9 +++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) 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 From f6673258c06ec80f03dbac102c2ebc32a1e05d31 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Fri, 21 May 2021 16:14:01 -0400 Subject: [PATCH 2/2] chore: release proposal 0.20.0 (#80) --- CHANGELOG.md | 14 +++++++++++++- package.json | 2 +- src/version.ts | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e7920ec..133ad1d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,19 @@ All notable changes to this project will be documented in this file. -## 1.0.0-rc.1 +## 0.20.0 + +### :rocket: Enhancement + +* [#69](https://github.com/open-telemetry/opentelemetry-js-api/pull/69) feat(context): add utils method to remove keys from context ([@vmarchaud](https://github.com/vmarchaud)) +* [#71](https://github.com/open-telemetry/opentelemetry-js-api/pull/71) chore: export baggage ([@dyladan](https://github.com/dyladan)) + +### Committers: 2 + +* Daniel Dyla ([@dyladan](https://github.com/dyladan)) +* Valentin Marchaud ([@vmarchaud](https://github.com/vmarchaud)) + +## 0.19.0 ### :boom: Breaking Change diff --git a/package.json b/package.json index 756df6af..2e90a854 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/api", - "version": "0.19.0", + "version": "0.20.0", "description": "Public API for OpenTelemetry", "main": "build/src/index.js", "module": "build/esm/index.js", diff --git a/src/version.ts b/src/version.ts index 3fc2009a..a14ba6ef 100644 --- a/src/version.ts +++ b/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.19.0'; +export const VERSION = '0.20.0';