diff --git a/README.md b/README.md index 61e6ae7b41..7465856da0 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Last updated March 2020 | Metrics | Beta | v0.3 | Beta | | Context | Beta | v0.3 | Beta | | Propagation | Beta | v0.3 | Beta | -| Correlation Context | Alpha | v0.3 | Development | +| Baggage | Alpha | v0.3 | Development | | OpenTracing Bridge | N/A | v0.3 | Beta | | Resources | N/A | v0.3 | Beta | diff --git a/packages/opentelemetry-api/src/correlation_context/CorrelationContext.ts b/packages/opentelemetry-api/src/baggage/Baggage.ts similarity index 77% rename from packages/opentelemetry-api/src/correlation_context/CorrelationContext.ts rename to packages/opentelemetry-api/src/baggage/Baggage.ts index c7bd5668b9..1ab2a9b670 100644 --- a/packages/opentelemetry-api/src/correlation_context/CorrelationContext.ts +++ b/packages/opentelemetry-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/packages/opentelemetry-api/src/correlation_context/EntryValue.ts b/packages/opentelemetry-api/src/baggage/EntryValue.ts similarity index 100% rename from packages/opentelemetry-api/src/correlation_context/EntryValue.ts rename to packages/opentelemetry-api/src/baggage/EntryValue.ts diff --git a/packages/opentelemetry-api/src/context/context.ts b/packages/opentelemetry-api/src/context/context.ts index ee2568aef6..104e8f5945 100644 --- a/packages/opentelemetry-api/src/context/context.ts +++ b/packages/opentelemetry-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/packages/opentelemetry-api/src/index.ts b/packages/opentelemetry-api/src/index.ts index 09fc2f2b24..c19be4333a 100644 --- a/packages/opentelemetry-api/src/index.ts +++ b/packages/opentelemetry-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/packages/opentelemetry-api/src/metrics/NoopMeter.ts b/packages/opentelemetry-api/src/metrics/NoopMeter.ts index 06eabc197d..a81315ba92 100644 --- a/packages/opentelemetry-api/src/metrics/NoopMeter.ts +++ b/packages/opentelemetry-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/packages/opentelemetry-api/src/trace/span_context.ts b/packages/opentelemetry-api/src/trace/span_context.ts index b194c414c9..613bdb8eb2 100644 --- a/packages/opentelemetry-api/src/trace/span_context.ts +++ b/packages/opentelemetry-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 { /** diff --git a/packages/opentelemetry-core/README.md b/packages/opentelemetry-core/README.md index 1b0c37196e..e33ef89b77 100644 --- a/packages/opentelemetry-core/README.md +++ b/packages/opentelemetry-core/README.md @@ -15,7 +15,7 @@ This package provides default implementations of the OpenTelemetry API for trace - [Built-in Propagators](#built-in-propagators) - [HttpTraceContext Propagator](#httptracecontext-propagator) - [Composite Propagator](#composite-propagator) - - [Correlation Context Propagator](#correlation-context-propagator) + - [Baggage Propagator](#baggage-propagator) - [Built-in Sampler](#built-in-sampler) - [Always Sampler](#always-sampler) - [Never Sampler](#never-sampler) @@ -51,16 +51,16 @@ const { CompositePropagator } = require("@opentelemetry/core"); api.propagation.setGlobalPropagator(new CompositePropagator()); ``` -#### Correlation Context Propagator +#### Baggage Propagator -Provides a text-based approach to propagate [correlation context](https://w3c.github.io/correlation-context/) to remote services using the [OpenTelemetry CorrelationContext Propagation](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/correlationcontext/api.md#header-name) HTTP headers. +Provides a text-based approach to propagate [baggage](https://w3c.github.io/baggage/) to remote services using the [OpenTelemetry Baggage Propagation](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/baggage/api.md#baggage-propagation) HTTP headers. ```js const api = require("@opentelemetry/api"); -const { HttpCorrelationContext } = require("@opentelemetry/core"); +const { HttpBaggage } = require("@opentelemetry/core"); /* Set Global Propagator */ -api.propagation.setGlobalPropagator(new HttpCorrelationContext()); +api.propagation.setGlobalPropagator(new HttpBaggage()); ``` ### Built-in Sampler diff --git a/packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts similarity index 68% rename from packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts rename to packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts index 9b3a178ba0..a576d5224d 100644 --- a/packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts +++ b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts @@ -15,23 +15,21 @@ */ import { + Baggage, Context, - CorrelationContext, + getBaggage, + setBaggage, TextMapGetter, TextMapPropagator, TextMapSetter, } from '@opentelemetry/api'; -import { - getCorrelationContext, - setCorrelationContext, -} from '../correlation-context'; const KEY_PAIR_SEPARATOR = '='; const PROPERTIES_SEPARATOR = ';'; const ITEMS_SEPARATOR = ','; -// Name of the http header used to propagate the correlation context -export const CORRELATION_CONTEXT_HEADER = 'baggage'; +// Name of the http header used to propagate the baggage +export const BAGGAGE_HEADER = 'baggage'; // Maximum number of name-value pairs allowed by w3c spec export const MAX_NAME_VALUE_PAIRS = 180; // Maximum number of bytes per a single name-value pair allowed by w3c spec @@ -44,23 +42,23 @@ type KeyPair = { }; /** - * Propagates {@link CorrelationContext} through Context format propagation. + * Propagates {@link Baggage} through Context format propagation. * - * Based on the Correlation Context specification: - * https://w3c.github.io/correlation-context/ + * Based on the Baggage specification: + * https://w3c.github.io/baggage/ */ -export class HttpCorrelationContext implements TextMapPropagator { +export class HttpBaggage implements TextMapPropagator { inject(context: Context, carrier: unknown, setter: TextMapSetter) { - const correlationContext = getCorrelationContext(context); - if (!correlationContext) return; - const keyPairs = this._getKeyPairs(correlationContext) + const baggage = getBaggage(context); + if (!baggage) return; + const keyPairs = this._getKeyPairs(baggage) .filter((pair: string) => { return pair.length <= MAX_PER_NAME_VALUE_PAIRS; }) .slice(0, MAX_NAME_VALUE_PAIRS); const headerValue = this._serializeKeyPairs(keyPairs); if (headerValue.length > 0) { - setter.set(carrier, CORRELATION_CONTEXT_HEADER, headerValue); + setter.set(carrier, BAGGAGE_HEADER, headerValue); } } @@ -71,22 +69,17 @@ export class HttpCorrelationContext implements TextMapPropagator { }, ''); } - private _getKeyPairs(correlationContext: CorrelationContext): string[] { - return Object.keys(correlationContext).map( + private _getKeyPairs(baggage: Baggage): string[] { + return Object.keys(baggage).map( (key: string) => - `${encodeURIComponent(key)}=${encodeURIComponent( - correlationContext[key].value - )}` + `${encodeURIComponent(key)}=${encodeURIComponent(baggage[key].value)}` ); } extract(context: Context, carrier: unknown, getter: TextMapGetter): Context { - const headerValue: string = getter.get( - carrier, - CORRELATION_CONTEXT_HEADER - ) as string; + const headerValue: string = getter.get(carrier, BAGGAGE_HEADER) as string; if (!headerValue) return context; - const correlationContext: CorrelationContext = {}; + const baggage: Baggage = {}; if (headerValue.length == 0) { return context; } @@ -94,13 +87,13 @@ export class HttpCorrelationContext implements TextMapPropagator { pairs.forEach(entry => { const keyPair = this._parsePairKeyValue(entry); if (keyPair) { - correlationContext[keyPair.key] = { value: keyPair.value }; + baggage[keyPair.key] = { value: keyPair.value }; } }); - if (Object.entries(correlationContext).length === 0) { + if (Object.entries(baggage).length === 0) { return context; } - return setCorrelationContext(context, correlationContext); + return setBaggage(context, baggage); } private _parsePairKeyValue(entry: string): KeyPair | undefined { @@ -120,6 +113,6 @@ export class HttpCorrelationContext implements TextMapPropagator { } fields(): string[] { - return [CORRELATION_CONTEXT_HEADER]; + return [BAGGAGE_HEADER]; } } diff --git a/packages/opentelemetry-core/src/correlation-context/correlation-context.ts b/packages/opentelemetry-core/src/correlation-context/correlation-context.ts deleted file mode 100644 index cb1f37cc55..0000000000 --- a/packages/opentelemetry-core/src/correlation-context/correlation-context.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - CorrelationContext, - Context, - createContextKey, -} from '@opentelemetry/api'; - -const CORRELATION_CONTEXT = createContextKey( - 'OpenTelemetry Distributed Contexts Key' -); - -/** - * @param {Context} Context that manage all context values - * @returns {CorrelationContext} Extracted correlation context from the context - */ -export function getCorrelationContext( - context: Context -): CorrelationContext | undefined { - return ( - (context.getValue(CORRELATION_CONTEXT) as CorrelationContext) || undefined - ); -} - -/** - * @param {Context} Context that manage all context values - * @param {CorrelationContext} correlation context that will be set in the actual context - */ -export function setCorrelationContext( - context: Context, - correlationContext: CorrelationContext -): Context { - return context.setValue(CORRELATION_CONTEXT, correlationContext); -} diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index 0835399ec1..a8167a61d9 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -26,8 +26,7 @@ export * from './version'; export * from './context/propagation/composite'; export * from './context/propagation/HttpTraceContext'; export * from './context/propagation/types'; -export * from './correlation-context/correlation-context'; -export * from './correlation-context/propagation/HttpCorrelationContext'; +export * from './baggage/propagation/HttpBaggage'; export * from './platform'; export * from './trace/NoRecordingSpan'; export * from './trace/Plugin'; diff --git a/packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts b/packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts similarity index 68% rename from packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts rename to packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts index ecf31942cb..3d1ff9b33e 100644 --- a/packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts +++ b/packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts @@ -17,22 +17,20 @@ import { defaultTextMapGetter, defaultTextMapSetter, - CorrelationContext, + Baggage, + setBaggage, + getBaggage, } from '@opentelemetry/api'; import { ROOT_CONTEXT } from '@opentelemetry/context-base'; import * as assert from 'assert'; import { - getCorrelationContext, - setCorrelationContext, -} from '../../src/correlation-context/correlation-context'; -import { - HttpCorrelationContext, - CORRELATION_CONTEXT_HEADER, + HttpBaggage, + BAGGAGE_HEADER, MAX_PER_NAME_VALUE_PAIRS, -} from '../../src/correlation-context/propagation/HttpCorrelationContext'; +} from '../../src/baggage/propagation/HttpBaggage'; -describe('HttpCorrelationContext', () => { - const httpTraceContext = new HttpCorrelationContext(); +describe('HttpBaggage', () => { + const httpTraceContext = new HttpBaggage(); let carrier: { [key: string]: unknown }; @@ -41,47 +39,47 @@ describe('HttpCorrelationContext', () => { }); describe('.inject()', () => { - it('should set correlation context header', () => { - const correlationContext: CorrelationContext = { + it('should set baggage header', () => { + const baggage: Baggage = { key1: { value: 'd4cda95b652f4a1592b449d5929fda1b' }, key3: { value: 'c88815a7-0fa9-4d95-a1f1-cdccce3c5c2a' }, 'with/slash': { value: 'with spaces' }, }; httpTraceContext.inject( - setCorrelationContext(ROOT_CONTEXT, correlationContext), + setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter ); assert.deepStrictEqual( - carrier[CORRELATION_CONTEXT_HEADER], + carrier[BAGGAGE_HEADER], 'key1=d4cda95b652f4a1592b449d5929fda1b,key3=c88815a7-0fa9-4d95-a1f1-cdccce3c5c2a,with%2Fslash=with%20spaces' ); }); it('should skip long key-value pairs', () => { - const correlationContext: CorrelationContext = { + const baggage: Baggage = { key1: { value: 'd4cda95b' }, key3: { value: 'c88815a7' }, }; // Generate long value 2*MAX_PER_NAME_VALUE_PAIRS const value = '1a'.repeat(MAX_PER_NAME_VALUE_PAIRS); - correlationContext['longPair'] = { value }; + baggage['longPair'] = { value }; httpTraceContext.inject( - setCorrelationContext(ROOT_CONTEXT, correlationContext), + setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter ); assert.deepStrictEqual( - carrier[CORRELATION_CONTEXT_HEADER], + carrier[BAGGAGE_HEADER], 'key1=d4cda95b,key3=c88815a7' ); }); it('should skip all keys that surpassed the max limit of the header', () => { - const correlationContext: CorrelationContext = {}; + const baggage: Baggage = {}; const zeroPad = (num: number, places: number) => String(num).padStart(places, '0'); @@ -89,7 +87,7 @@ describe('HttpCorrelationContext', () => { // key=value with same size , 1024 => 8 keys for (let i = 0; i < 9; ++i) { const index = zeroPad(i, 510); - correlationContext[`k${index}`] = { value: `${index}` }; + baggage[`k${index}`] = { value: `${index}` }; } // Build expected @@ -101,42 +99,42 @@ describe('HttpCorrelationContext', () => { expected = expected.slice(0, -1); httpTraceContext.inject( - setCorrelationContext(ROOT_CONTEXT, correlationContext), + setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter ); - assert.deepStrictEqual(carrier[CORRELATION_CONTEXT_HEADER], expected); + assert.deepStrictEqual(carrier[BAGGAGE_HEADER], expected); }); }); describe('.extract()', () => { it('should extract context of a sampled span from carrier', () => { - carrier[CORRELATION_CONTEXT_HEADER] = + carrier[BAGGAGE_HEADER] = 'key1=d4cda95b,key3=c88815a7, keyn = valn, keym =valm'; - const extractedCorrelationContext = getCorrelationContext( + const extractedBaggage = getBaggage( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); - const expected: CorrelationContext = { + const expected: Baggage = { key1: { value: 'd4cda95b' }, key3: { value: 'c88815a7' }, keyn: { value: 'valn' }, keym: { value: 'valm' }, }; - assert.deepStrictEqual(extractedCorrelationContext, expected); + assert.deepStrictEqual(extractedBaggage, expected); }); }); describe('fields()', () => { it('returns the fields used by the baggage spec', () => { - const propagator = new HttpCorrelationContext(); - assert.deepStrictEqual(propagator.fields(), [CORRELATION_CONTEXT_HEADER]); + const propagator = new HttpBaggage(); + assert.deepStrictEqual(propagator.fields(), [BAGGAGE_HEADER]); }); }); it('returns undefined if header is missing', () => { assert.deepStrictEqual( - getCorrelationContext( + getBaggage( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ), undefined @@ -144,14 +142,13 @@ describe('HttpCorrelationContext', () => { }); it('returns keys with their properties', () => { - carrier[CORRELATION_CONTEXT_HEADER] = - 'key1=d4cda95b,key3=c88815a7;prop1=value1'; - const expected: CorrelationContext = { + carrier[BAGGAGE_HEADER] = 'key1=d4cda95b,key3=c88815a7;prop1=value1'; + const expected: Baggage = { key1: { value: 'd4cda95b' }, key3: { value: 'c88815a7;prop1=value1' }, }; assert.deepStrictEqual( - getCorrelationContext( + getBaggage( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ), expected @@ -163,28 +160,28 @@ describe('HttpCorrelationContext', () => { string, { header: string; - correlationContext: CorrelationContext | undefined; + baggage: Baggage | undefined; } > = { invalidNoKeyValuePair: { header: '289371298nekjh2939299283jbk2b', - correlationContext: undefined, + baggage: undefined, }, invalidDoubleEqual: { header: 'key1==value;key2=value2', - correlationContext: undefined, + baggage: undefined, }, invalidWrongKeyValueFormat: { header: 'key1:value;key2=value2', - correlationContext: undefined, + baggage: undefined, }, invalidDoubleSemicolon: { header: 'key1:value;;key2=value2', - correlationContext: undefined, + baggage: undefined, }, mixInvalidAndValidKeys: { header: 'key1==value,key2=value2', - correlationContext: { + baggage: { key2: { value: 'value2', }, @@ -192,14 +189,14 @@ describe('HttpCorrelationContext', () => { }, }; Object.getOwnPropertyNames(testCases).forEach(testCase => { - carrier[CORRELATION_CONTEXT_HEADER] = testCases[testCase].header; + carrier[BAGGAGE_HEADER] = testCases[testCase].header; - const extractedSpanContext = getCorrelationContext( + const extractedSpanContext = getBaggage( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual( extractedSpanContext, - testCases[testCase].correlationContext, + testCases[testCase].baggage, testCase ); }); diff --git a/packages/opentelemetry-sdk-node/README.md b/packages/opentelemetry-sdk-node/README.md index d1bd7203a3..9eb01d4a34 100644 --- a/packages/opentelemetry-sdk-node/README.md +++ b/packages/opentelemetry-sdk-node/README.md @@ -90,7 +90,7 @@ Use a custom context manager. Default: [AsyncHooksContextManager](../opentelemet ### textMapPropagator -Use a custom propagator. Default: [CompositePropagator](../opentelemetry-core/src/context/propagation/composite.ts) using [W3C Trace Context](../opentelemetry-core/README.md#httptracecontext-propagator) and [Correlation Context](../opentelemetry-core/README.md#correlation-context-propagator) +Use a custom propagator. Default: [CompositePropagator](../opentelemetry-core/src/context/propagation/composite.ts) using [W3C Trace Context](../opentelemetry-core/README.md#httptracecontext-propagator) and [Baggage](../opentelemetry-core/README.md#baggage-propagator) ### logger diff --git a/packages/opentelemetry-shim-opentracing/src/shim.ts b/packages/opentelemetry-shim-opentracing/src/shim.ts index 3865098152..f24fb4c6a8 100644 --- a/packages/opentelemetry-shim-opentracing/src/shim.ts +++ b/packages/opentelemetry-shim-opentracing/src/shim.ts @@ -15,11 +15,7 @@ */ import * as api from '@opentelemetry/api'; -import { - NoopLogger, - setCorrelationContext, - getCorrelationContext, -} from '@opentelemetry/core'; +import { NoopLogger } from '@opentelemetry/core'; import * as opentracing from 'opentracing'; import { Attributes, AttributeValue } from '@opentelemetry/api'; @@ -71,15 +67,12 @@ function getContextWithParent(options: opentracing.SpanOptions) { */ export class SpanContextShim extends opentracing.SpanContext { private readonly _spanContext: api.SpanContext; - private _correlationContext: api.CorrelationContext; + private _baggage: api.Baggage; - constructor( - spanContext: api.SpanContext, - correlationContext: api.CorrelationContext - ) { + constructor(spanContext: api.SpanContext, baggage: api.Baggage) { super(); this._spanContext = spanContext; - this._correlationContext = correlationContext; + this._baggage = baggage; } /** @@ -90,10 +83,10 @@ export class SpanContextShim extends opentracing.SpanContext { } /** - * Returns the underlying {@link api.CorrelationContext} + * Returns the underlying {@link api.Baggage} */ - getCorrelationContext(): api.CorrelationContext { - return this._correlationContext; + getBaggage(): api.Baggage { + return this._baggage; } /** @@ -111,11 +104,11 @@ export class SpanContextShim extends opentracing.SpanContext { } getBaggageItem(key: string): string | undefined { - return this._correlationContext[key]?.value; + return this._baggage[key]?.value; } setBaggageItem(key: string, value: string) { - this._correlationContext = Object.assign({}, this._correlationContext, { + this._baggage = Object.assign({}, this._baggage, { [key]: { value }, }); } @@ -146,19 +139,19 @@ export class TracerShim extends opentracing.Tracer { getContextWithParent(options) ); - let correlationContext: api.CorrelationContext = {}; + let baggage: api.Baggage = {}; if (options.childOf instanceof SpanShim) { const shimContext = options.childOf.context() as SpanContextShim; - correlationContext = shimContext.getCorrelationContext(); + baggage = shimContext.getBaggage(); } else if (options.childOf instanceof SpanContextShim) { - correlationContext = options.childOf.getCorrelationContext(); + baggage = options.childOf.getBaggage(); } if (options.tags) { span.setAttributes(options.tags); } - return new SpanShim(this, span, correlationContext); + return new SpanShim(this, span, baggage); } _inject( @@ -168,16 +161,16 @@ export class TracerShim extends opentracing.Tracer { ): void { const spanContextShim: SpanContextShim = spanContext as SpanContextShim; const oTelSpanContext: api.SpanContext = spanContextShim.getSpanContext(); - const oTelSpanCorrelationContext: api.CorrelationContext = spanContextShim.getCorrelationContext(); + const oTelSpanBaggage: api.Baggage = spanContextShim.getBaggage(); if (!carrier || typeof carrier !== 'object') return; switch (format) { case opentracing.FORMAT_HTTP_HEADERS: case opentracing.FORMAT_TEXT_MAP: { api.propagation.inject( - setCorrelationContext( + api.setBaggage( api.setExtractedSpanContext(api.ROOT_CONTEXT, oTelSpanContext), - oTelSpanCorrelationContext + oTelSpanBaggage ), carrier ); @@ -203,12 +196,12 @@ export class TracerShim extends opentracing.Tracer { carrier ); const spanContext = api.getParentSpanContext(context); - const correlationContext = getCorrelationContext(context); + const baggage = api.getBaggage(context); if (!spanContext) { return null; } - return new SpanContextShim(spanContext, correlationContext || {}); + return new SpanContextShim(spanContext, baggage || {}); } case opentracing.FORMAT_BINARY: { // @todo: Implement binary format @@ -235,14 +228,10 @@ export class SpanShim extends opentracing.Span { private readonly _contextShim: SpanContextShim; private readonly _tracerShim: TracerShim; - constructor( - tracerShim: TracerShim, - span: api.Span, - correlationContext: api.CorrelationContext - ) { + constructor(tracerShim: TracerShim, span: api.Span, baggage: api.Baggage) { super(); this._span = span; - this._contextShim = new SpanContextShim(span.context(), correlationContext); + this._contextShim = new SpanContextShim(span.context(), baggage); this._tracerShim = tracerShim; } diff --git a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts index e55310d938..ba0b3b461d 100644 --- a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts +++ b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts @@ -22,7 +22,7 @@ import { timeInputToHrTime, HttpTraceContext, CompositePropagator, - HttpCorrelationContext, + HttpBaggage, } from '@opentelemetry/core'; import { INVALID_SPAN_CONTEXT, propagation } from '@opentelemetry/api'; import { performance } from 'perf_hooks'; @@ -34,7 +34,7 @@ describe('OpenTracing Shim', () => { ); opentracing.initGlobalTracer(shimTracer); const compositePropagator = new CompositePropagator({ - propagators: [new HttpTraceContext(), new HttpCorrelationContext()], + propagators: [new HttpTraceContext(), new HttpBaggage()], }); propagation.setGlobalPropagator(compositePropagator); diff --git a/packages/opentelemetry-tracing/src/BasicTracerProvider.ts b/packages/opentelemetry-tracing/src/BasicTracerProvider.ts index 570e2ed66d..a4b4885330 100644 --- a/packages/opentelemetry-tracing/src/BasicTracerProvider.ts +++ b/packages/opentelemetry-tracing/src/BasicTracerProvider.ts @@ -18,7 +18,7 @@ import * as api from '@opentelemetry/api'; import { ConsoleLogger, HttpTraceContext, - HttpCorrelationContext, + HttpBaggage, CompositePropagator, } from '@opentelemetry/core'; import { SpanProcessor, Tracer } from '.'; @@ -87,7 +87,7 @@ export class BasicTracerProvider implements api.TracerProvider { api.trace.setGlobalTracerProvider(this); if (config.propagator === undefined) { config.propagator = new CompositePropagator({ - propagators: [new HttpCorrelationContext(), new HttpTraceContext()], + propagators: [new HttpBaggage(), new HttpTraceContext()], }); }