diff --git a/api/src/correlation_context/CorrelationContext.ts b/api/src/baggage/Baggage.ts similarity index 77% rename from api/src/correlation_context/CorrelationContext.ts rename to api/src/baggage/Baggage.ts index c7bd5668b97..1ab2a9b670e 100644 --- a/api/src/correlation_context/CorrelationContext.ts +++ b/api/src/baggage/Baggage.ts @@ -17,13 +17,13 @@ import { EntryValue } from './EntryValue'; /** - * CorrelationContext represents collection of entries. Each key of - * CorrelationContext is associated with exactly one value. CorrelationContext + * Baggage represents collection of entries. Each key of + * Baggage is associated with exactly one value. Baggage * is serializable, to facilitate propagating it not only inside the process - * but also across process boundaries. CorrelationContext is used to annotate + * but also across process boundaries. Baggage is used to annotate * telemetry with the name:value pair Entry. Those values can be used to add * dimension to the metric or additional contest properties to logs and traces. */ -export interface CorrelationContext { +export interface Baggage { [entryKey: string]: EntryValue; } diff --git a/api/src/correlation_context/EntryValue.ts b/api/src/baggage/EntryValue.ts similarity index 100% rename from api/src/correlation_context/EntryValue.ts rename to api/src/baggage/EntryValue.ts diff --git a/api/src/context/context.ts b/api/src/context/context.ts index ee2568aef67..104e8f59451 100644 --- a/api/src/context/context.ts +++ b/api/src/context/context.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { NoopSpan, Span, SpanContext } from '../'; import { Context, createContextKey } from '@opentelemetry/context-base'; +import { Baggage, NoopSpan, Span, SpanContext } from '../'; /** * Active span key @@ -32,6 +32,11 @@ const SUPPRESS_INSTRUMENTATION_KEY = createContextKey( 'OpenTelemetry Context Key SUPPRESS_INSTRUMENTATION' ); +/** + * Baggage key + */ +const BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key'); + /** * Return the active span if one exists * @@ -107,3 +112,19 @@ export function unsuppressInstrumentation(context: Context): Context { export function isInstrumentationSuppressed(context: Context): boolean { return Boolean(context.getValue(SUPPRESS_INSTRUMENTATION_KEY)); } + +/** + * @param {Context} Context that manage all context values + * @returns {Baggage} Extracted baggage from the context + */ +export function getBaggage(context: Context): Baggage | undefined { + return (context.getValue(BAGGAGE_KEY) as Baggage) || undefined; +} + +/** + * @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); +} diff --git a/api/src/index.ts b/api/src/index.ts index 09fc2f2b24d..c19be4333a8 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -20,8 +20,8 @@ export * from './common/Time'; export * from './context/context'; export * from './context/propagation/TextMapPropagator'; export * from './context/propagation/NoopTextMapPropagator'; -export * from './correlation_context/CorrelationContext'; -export * from './correlation_context/EntryValue'; +export * from './baggage/Baggage'; +export * from './baggage/EntryValue'; export * from './metrics/BatchObserverResult'; export * from './metrics/BoundInstrument'; export * from './metrics/Meter'; diff --git a/api/src/metrics/NoopMeter.ts b/api/src/metrics/NoopMeter.ts index 06eabc197d0..a81315ba92e 100644 --- a/api/src/metrics/NoopMeter.ts +++ b/api/src/metrics/NoopMeter.ts @@ -33,7 +33,7 @@ import { BoundCounter, BoundBaseObserver, } from './BoundInstrument'; -import { CorrelationContext } from '../correlation_context/CorrelationContext'; +import { Baggage } from '../baggage/Baggage'; import { SpanContext } from '../trace/span_context'; import { ObserverResult } from './ObserverResult'; @@ -198,11 +198,7 @@ export class NoopBoundCounter implements BoundCounter { } export class NoopBoundValueRecorder implements BoundValueRecorder { - record( - _value: number, - _correlationContext?: CorrelationContext, - _spanContext?: SpanContext - ): void { + record(_value: number, _baggage?: Baggage, _spanContext?: SpanContext): void { return; } } diff --git a/api/src/trace/span_context.ts b/api/src/trace/span_context.ts index b194c414c97..613bdb8eb29 100644 --- a/api/src/trace/span_context.ts +++ b/api/src/trace/span_context.ts @@ -18,7 +18,7 @@ import { TraceState } from './trace_state'; /** * A SpanContext represents the portion of a {@link Span} which must be - * serialized and propagated along side of a {@link CorrelationContext}. + * serialized and propagated along side of a {@link Baggage}. */ export interface SpanContext { /**