From 8ef395a0ea236346d9f4af8eb572869934f17518 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Fri, 28 Feb 2020 12:44:08 -0500 Subject: [PATCH 1/6] feat: add composite propagator --- .../src/context/propagation/composite.ts | 45 +++++++ packages/opentelemetry-core/src/index.ts | 1 + .../test/context/composite.test.ts | 123 ++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 packages/opentelemetry-core/src/context/propagation/composite.ts create mode 100644 packages/opentelemetry-core/test/context/composite.test.ts diff --git a/packages/opentelemetry-core/src/context/propagation/composite.ts b/packages/opentelemetry-core/src/context/propagation/composite.ts new file mode 100644 index 0000000000..5deb7a3b73 --- /dev/null +++ b/packages/opentelemetry-core/src/context/propagation/composite.ts @@ -0,0 +1,45 @@ +/*! + * Copyright 2019, 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 { Carrier, Context, HttpTextFormat } from '@opentelemetry/api'; + +/** Combines multiple propagators into a single propagator. */ +export class CompositePropagator implements HttpTextFormat { + private _propagators: HttpTextFormat[]; + constructor(...propagators: HttpTextFormat[]) { + this._propagators = propagators; + } + + inject(context: Context, carrier: Carrier) { + for (const propagator of this._propagators) { + try { + propagator.inject(context, carrier); + } catch { } + } + } + + extract(context: Context, carrier: Carrier): Context { + return this._propagators.reduce( + (ctx, propagator) => { + try { + return propagator.extract(ctx, carrier) + } catch { } + return ctx; + }, + context + ); + } +} diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index 61168c30bc..002f17ea91 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -21,6 +21,7 @@ export * from './common/types'; export * from './version'; export * from './context/context'; export * from './context/propagation/B3Format'; +export * from './context/propagation/composite'; export * from './context/propagation/HttpTraceContext'; export * from './platform'; export * from './trace/instrumentation/BasePlugin'; diff --git a/packages/opentelemetry-core/test/context/composite.test.ts b/packages/opentelemetry-core/test/context/composite.test.ts new file mode 100644 index 0000000000..9d972f50eb --- /dev/null +++ b/packages/opentelemetry-core/test/context/composite.test.ts @@ -0,0 +1,123 @@ +/*! + * Copyright 2019, 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 { Context } from '@opentelemetry/scope-base'; +import * as assert from 'assert'; +import { CompositePropagator, HttpTraceContext, randomSpanId, randomTraceId } from '../../src'; +import { setExtractedSpanContext, getExtractedSpanContext } from '../../src/context/context'; +import { B3Format, X_B3_SPAN_ID, X_B3_TRACE_ID, X_B3_SAMPLED } from '../../src/context/propagation/B3Format'; +import { TRACE_PARENT_HEADER, TRACE_STATE_HEADER } from '../../src/context/propagation/HttpTraceContext'; +import { TraceState } from '../../src/trace/TraceState'; +import { HttpTextFormat, SpanContext } from '@opentelemetry/api'; + +describe('Composite Propagator', () => { + let traceId: string; + let spanId: string; + + beforeEach(() => { + traceId = randomTraceId(); + spanId = randomSpanId(); + }); + + describe('inject', () => { + let carrier: { [key: string]: unknown }; + let spanContext: SpanContext; + let ctxWithSpanContext: Context; + + beforeEach(() => { + carrier = {}; + spanContext = { + spanId, + traceId, + traceFlags: 1, + traceState: new TraceState("foo=bar") + }; + ctxWithSpanContext = setExtractedSpanContext(Context.ROOT_CONTEXT, spanContext) + }); + + it('should inject context using all configured propagators', () => { + const composite = new CompositePropagator(new B3Format(), new HttpTraceContext()); + composite.inject(ctxWithSpanContext, carrier); + + assert.strictEqual(carrier[X_B3_TRACE_ID], traceId) + assert.strictEqual(carrier[X_B3_SPAN_ID], spanId) + assert.strictEqual(carrier[X_B3_SAMPLED], 1) + assert.strictEqual(carrier[TRACE_PARENT_HEADER], `00-${traceId}-${spanId}-01`) + assert.strictEqual(carrier[TRACE_STATE_HEADER], 'foo=bar') + }); + + it('should not throw', () => { + const composite = new CompositePropagator(new ThrowingPropagator(), new HttpTraceContext()); + composite.inject(ctxWithSpanContext, carrier); + + assert.strictEqual(carrier[TRACE_PARENT_HEADER], `00-${traceId}-${spanId}-01`); + }); + }); + + describe('extract', () => { + let carrier: { [key: string]: unknown }; + + beforeEach(() => { + carrier = { + [X_B3_TRACE_ID]: traceId, + [X_B3_SPAN_ID]: spanId, + [X_B3_SAMPLED]: 1, + [TRACE_PARENT_HEADER]: `00-${traceId}-${spanId}-01`, + [TRACE_STATE_HEADER]: 'foo=bar', + } + }); + + it('should extract context using all configured propagators', () => { + const composite = new CompositePropagator(new B3Format(), new HttpTraceContext()); + const spanContext = getExtractedSpanContext(composite.extract(Context.ROOT_CONTEXT, carrier)); + + if (!spanContext) { + throw new Error("no extracted context"); + } + + assert.strictEqual(spanContext.traceId, traceId) + assert.strictEqual(spanContext.spanId, spanId) + assert.strictEqual(spanContext.traceFlags, 1) + assert.strictEqual(spanContext.isRemote, true) + assert.strictEqual(spanContext.traceState!.get("foo"), "bar") + }); + + it('should not throw', () => { + const composite = new CompositePropagator(new ThrowingPropagator(), new HttpTraceContext()); + const spanContext = getExtractedSpanContext(composite.extract(Context.ROOT_CONTEXT, carrier)); + + if (!spanContext) { + throw new Error("no extracted context"); + } + + assert.strictEqual(spanContext.traceId, traceId) + assert.strictEqual(spanContext.spanId, spanId) + assert.strictEqual(spanContext.traceFlags, 1) + assert.strictEqual(spanContext.isRemote, true) + assert.strictEqual(spanContext.traceState!.get("foo"), "bar") + }); + }) +}); + +class ThrowingPropagator implements HttpTextFormat { + inject(context: Context, carrier: unknown) { + throw new Error('this propagator throws') + } + + extract(context: Context, carrier: unknown): Context { + throw new Error('This propagator throws') + } +} From b4c5e4a06d016227b8a2a244290a86d09ede5252 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Fri, 28 Feb 2020 15:15:11 -0500 Subject: [PATCH 2/6] chore: lint --- .../src/context/propagation/composite.ts | 39 ++-- .../test/context/composite.test.ts | 221 +++++++++++------- 2 files changed, 149 insertions(+), 111 deletions(-) diff --git a/packages/opentelemetry-core/src/context/propagation/composite.ts b/packages/opentelemetry-core/src/context/propagation/composite.ts index 5deb7a3b73..c2810aee73 100644 --- a/packages/opentelemetry-core/src/context/propagation/composite.ts +++ b/packages/opentelemetry-core/src/context/propagation/composite.ts @@ -18,28 +18,25 @@ import { Carrier, Context, HttpTextFormat } from '@opentelemetry/api'; /** Combines multiple propagators into a single propagator. */ export class CompositePropagator implements HttpTextFormat { - private _propagators: HttpTextFormat[]; - constructor(...propagators: HttpTextFormat[]) { - this._propagators = propagators; - } + private _propagators: HttpTextFormat[]; + constructor(...propagators: HttpTextFormat[]) { + this._propagators = propagators; + } - inject(context: Context, carrier: Carrier) { - for (const propagator of this._propagators) { - try { - propagator.inject(context, carrier); - } catch { } - } + inject(context: Context, carrier: Carrier) { + for (const propagator of this._propagators) { + try { + propagator.inject(context, carrier); + } catch {} } + } - extract(context: Context, carrier: Carrier): Context { - return this._propagators.reduce( - (ctx, propagator) => { - try { - return propagator.extract(ctx, carrier) - } catch { } - return ctx; - }, - context - ); - } + extract(context: Context, carrier: Carrier): Context { + return this._propagators.reduce((ctx, propagator) => { + try { + return propagator.extract(ctx, carrier); + } catch {} + return ctx; + }, context); + } } diff --git a/packages/opentelemetry-core/test/context/composite.test.ts b/packages/opentelemetry-core/test/context/composite.test.ts index 9d972f50eb..bba8c7c253 100644 --- a/packages/opentelemetry-core/test/context/composite.test.ts +++ b/packages/opentelemetry-core/test/context/composite.test.ts @@ -16,108 +16,149 @@ import { Context } from '@opentelemetry/scope-base'; import * as assert from 'assert'; -import { CompositePropagator, HttpTraceContext, randomSpanId, randomTraceId } from '../../src'; -import { setExtractedSpanContext, getExtractedSpanContext } from '../../src/context/context'; -import { B3Format, X_B3_SPAN_ID, X_B3_TRACE_ID, X_B3_SAMPLED } from '../../src/context/propagation/B3Format'; -import { TRACE_PARENT_HEADER, TRACE_STATE_HEADER } from '../../src/context/propagation/HttpTraceContext'; +import { + CompositePropagator, + HttpTraceContext, + randomSpanId, + randomTraceId, +} from '../../src'; +import { + setExtractedSpanContext, + getExtractedSpanContext, +} from '../../src/context/context'; +import { + B3Format, + X_B3_SPAN_ID, + X_B3_TRACE_ID, + X_B3_SAMPLED, +} from '../../src/context/propagation/B3Format'; +import { + TRACE_PARENT_HEADER, + TRACE_STATE_HEADER, +} from '../../src/context/propagation/HttpTraceContext'; import { TraceState } from '../../src/trace/TraceState'; import { HttpTextFormat, SpanContext } from '@opentelemetry/api'; describe('Composite Propagator', () => { - let traceId: string; - let spanId: string; + let traceId: string; + let spanId: string; + + beforeEach(() => { + traceId = randomTraceId(); + spanId = randomSpanId(); + }); + + describe('inject', () => { + let carrier: { [key: string]: unknown }; + let spanContext: SpanContext; + let ctxWithSpanContext: Context; beforeEach(() => { - traceId = randomTraceId(); - spanId = randomSpanId(); + carrier = {}; + spanContext = { + spanId, + traceId, + traceFlags: 1, + traceState: new TraceState('foo=bar'), + }; + ctxWithSpanContext = setExtractedSpanContext( + Context.ROOT_CONTEXT, + spanContext + ); + }); + + it('should inject context using all configured propagators', () => { + const composite = new CompositePropagator( + new B3Format(), + new HttpTraceContext() + ); + composite.inject(ctxWithSpanContext, carrier); + + assert.strictEqual(carrier[X_B3_TRACE_ID], traceId); + assert.strictEqual(carrier[X_B3_SPAN_ID], spanId); + assert.strictEqual(carrier[X_B3_SAMPLED], 1); + assert.strictEqual( + carrier[TRACE_PARENT_HEADER], + `00-${traceId}-${spanId}-01` + ); + assert.strictEqual(carrier[TRACE_STATE_HEADER], 'foo=bar'); }); - describe('inject', () => { - let carrier: { [key: string]: unknown }; - let spanContext: SpanContext; - let ctxWithSpanContext: Context; - - beforeEach(() => { - carrier = {}; - spanContext = { - spanId, - traceId, - traceFlags: 1, - traceState: new TraceState("foo=bar") - }; - ctxWithSpanContext = setExtractedSpanContext(Context.ROOT_CONTEXT, spanContext) - }); - - it('should inject context using all configured propagators', () => { - const composite = new CompositePropagator(new B3Format(), new HttpTraceContext()); - composite.inject(ctxWithSpanContext, carrier); - - assert.strictEqual(carrier[X_B3_TRACE_ID], traceId) - assert.strictEqual(carrier[X_B3_SPAN_ID], spanId) - assert.strictEqual(carrier[X_B3_SAMPLED], 1) - assert.strictEqual(carrier[TRACE_PARENT_HEADER], `00-${traceId}-${spanId}-01`) - assert.strictEqual(carrier[TRACE_STATE_HEADER], 'foo=bar') - }); - - it('should not throw', () => { - const composite = new CompositePropagator(new ThrowingPropagator(), new HttpTraceContext()); - composite.inject(ctxWithSpanContext, carrier); - - assert.strictEqual(carrier[TRACE_PARENT_HEADER], `00-${traceId}-${spanId}-01`); - }); + it('should not throw', () => { + const composite = new CompositePropagator( + new ThrowingPropagator(), + new HttpTraceContext() + ); + composite.inject(ctxWithSpanContext, carrier); + + assert.strictEqual( + carrier[TRACE_PARENT_HEADER], + `00-${traceId}-${spanId}-01` + ); }); + }); + + describe('extract', () => { + let carrier: { [key: string]: unknown }; - describe('extract', () => { - let carrier: { [key: string]: unknown }; - - beforeEach(() => { - carrier = { - [X_B3_TRACE_ID]: traceId, - [X_B3_SPAN_ID]: spanId, - [X_B3_SAMPLED]: 1, - [TRACE_PARENT_HEADER]: `00-${traceId}-${spanId}-01`, - [TRACE_STATE_HEADER]: 'foo=bar', - } - }); - - it('should extract context using all configured propagators', () => { - const composite = new CompositePropagator(new B3Format(), new HttpTraceContext()); - const spanContext = getExtractedSpanContext(composite.extract(Context.ROOT_CONTEXT, carrier)); - - if (!spanContext) { - throw new Error("no extracted context"); - } - - assert.strictEqual(spanContext.traceId, traceId) - assert.strictEqual(spanContext.spanId, spanId) - assert.strictEqual(spanContext.traceFlags, 1) - assert.strictEqual(spanContext.isRemote, true) - assert.strictEqual(spanContext.traceState!.get("foo"), "bar") - }); - - it('should not throw', () => { - const composite = new CompositePropagator(new ThrowingPropagator(), new HttpTraceContext()); - const spanContext = getExtractedSpanContext(composite.extract(Context.ROOT_CONTEXT, carrier)); - - if (!spanContext) { - throw new Error("no extracted context"); - } - - assert.strictEqual(spanContext.traceId, traceId) - assert.strictEqual(spanContext.spanId, spanId) - assert.strictEqual(spanContext.traceFlags, 1) - assert.strictEqual(spanContext.isRemote, true) - assert.strictEqual(spanContext.traceState!.get("foo"), "bar") - }); - }) + beforeEach(() => { + carrier = { + [X_B3_TRACE_ID]: traceId, + [X_B3_SPAN_ID]: spanId, + [X_B3_SAMPLED]: 1, + [TRACE_PARENT_HEADER]: `00-${traceId}-${spanId}-01`, + [TRACE_STATE_HEADER]: 'foo=bar', + }; + }); + + it('should extract context using all configured propagators', () => { + const composite = new CompositePropagator( + new B3Format(), + new HttpTraceContext() + ); + const spanContext = getExtractedSpanContext( + composite.extract(Context.ROOT_CONTEXT, carrier) + ); + + if (!spanContext) { + throw new Error('no extracted context'); + } + + assert.strictEqual(spanContext.traceId, traceId); + assert.strictEqual(spanContext.spanId, spanId); + assert.strictEqual(spanContext.traceFlags, 1); + assert.strictEqual(spanContext.isRemote, true); + assert.strictEqual(spanContext.traceState!.get('foo'), 'bar'); + }); + + it('should not throw', () => { + const composite = new CompositePropagator( + new ThrowingPropagator(), + new HttpTraceContext() + ); + const spanContext = getExtractedSpanContext( + composite.extract(Context.ROOT_CONTEXT, carrier) + ); + + if (!spanContext) { + throw new Error('no extracted context'); + } + + assert.strictEqual(spanContext.traceId, traceId); + assert.strictEqual(spanContext.spanId, spanId); + assert.strictEqual(spanContext.traceFlags, 1); + assert.strictEqual(spanContext.isRemote, true); + assert.strictEqual(spanContext.traceState!.get('foo'), 'bar'); + }); + }); }); class ThrowingPropagator implements HttpTextFormat { - inject(context: Context, carrier: unknown) { - throw new Error('this propagator throws') - } + inject(context: Context, carrier: unknown) { + throw new Error('this propagator throws'); + } - extract(context: Context, carrier: unknown): Context { - throw new Error('This propagator throws') - } + extract(context: Context, carrier: unknown): Context { + throw new Error('This propagator throws'); + } } From 2b92e15880c49b8aff6139ce6759a1646345e8b0 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Mar 2020 14:28:42 -0500 Subject: [PATCH 3/6] chore: review comments --- .../src/context/propagation/composite.ts | 62 ++++++++++++++++--- .../test/context/composite.test.ts | 28 ++++----- 2 files changed, 67 insertions(+), 23 deletions(-) diff --git a/packages/opentelemetry-core/src/context/propagation/composite.ts b/packages/opentelemetry-core/src/context/propagation/composite.ts index c2810aee73..1b088aa918 100644 --- a/packages/opentelemetry-core/src/context/propagation/composite.ts +++ b/packages/opentelemetry-core/src/context/propagation/composite.ts @@ -1,5 +1,5 @@ /*! - * Copyright 2019, OpenTelemetry Authors + * Copyright 2020, OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,29 +14,77 @@ * limitations under the License. */ -import { Carrier, Context, HttpTextFormat } from '@opentelemetry/api'; +import { Carrier, Context, HttpTextFormat, Logger } from '@opentelemetry/api'; +import { NoopLogger } from '../../common/NoopLogger'; /** Combines multiple propagators into a single propagator. */ export class CompositePropagator implements HttpTextFormat { - private _propagators: HttpTextFormat[]; - constructor(...propagators: HttpTextFormat[]) { - this._propagators = propagators; + private readonly _propagators: HttpTextFormat[]; + private readonly _logger: Logger; + + /** + * Construct a composite propagator from a list of propagators. + * + * @param config Configuration object for composite propagator + */ + constructor(config: CompositePropagatorConfig = {}) { + this._propagators = config.propagators ?? []; + this._logger = config.logger ?? new NoopLogger(); } + /** + * Run each of the configured propagators with the given context and carrier. + * Propagators are run in the order they are configured, so if multiple + * propagators write the same carrier key, the propagator later in the list + * will "win". + * + * @param context Context to inject + * @param carrier Carrier into which context will be injected + */ inject(context: Context, carrier: Carrier) { for (const propagator of this._propagators) { try { propagator.inject(context, carrier); - } catch {} + } catch (err) { + this._logger.error( + `Failed to inject with ${propagator.constructor.name}. Err: ${err.message}` + ); + } } } + /** + * Run each of the configured propagators with the given context and carrier. + * Propagators are run in the order they are configured, so if multiple + * propagators write the same context key, the propagator later in the list + * will "win". + * + * @param context Context to add values to + * @param carrier Carrier from which to extract context + */ extract(context: Context, carrier: Carrier): Context { return this._propagators.reduce((ctx, propagator) => { try { return propagator.extract(ctx, carrier); - } catch {} + } catch (err) { + this._logger.error( + `Failed to inject with ${propagator.constructor.name}. Err: ${err.message}` + ); + } return ctx; }, context); } } + +/** Configuration object for composite propagator */ +export interface CompositePropagatorConfig { + /** + * List of propagators to run. Propagators run in the + * list order. If a propagator later in the list writes the same context + * key as a propagator earlier in the list, the later on will "win". + */ + propagators?: HttpTextFormat[]; + + /** Instance of logger */ + logger?: Logger; +} diff --git a/packages/opentelemetry-core/test/context/composite.test.ts b/packages/opentelemetry-core/test/context/composite.test.ts index bba8c7c253..55b4b8ea8f 100644 --- a/packages/opentelemetry-core/test/context/composite.test.ts +++ b/packages/opentelemetry-core/test/context/composite.test.ts @@ -68,10 +68,9 @@ describe('Composite Propagator', () => { }); it('should inject context using all configured propagators', () => { - const composite = new CompositePropagator( - new B3Format(), - new HttpTraceContext() - ); + const composite = new CompositePropagator({ + propagators: [new B3Format(), new HttpTraceContext()], + }); composite.inject(ctxWithSpanContext, carrier); assert.strictEqual(carrier[X_B3_TRACE_ID], traceId); @@ -85,10 +84,9 @@ describe('Composite Propagator', () => { }); it('should not throw', () => { - const composite = new CompositePropagator( - new ThrowingPropagator(), - new HttpTraceContext() - ); + const composite = new CompositePropagator({ + propagators: [new ThrowingPropagator(), new HttpTraceContext()], + }); composite.inject(ctxWithSpanContext, carrier); assert.strictEqual( @@ -112,10 +110,9 @@ describe('Composite Propagator', () => { }); it('should extract context using all configured propagators', () => { - const composite = new CompositePropagator( - new B3Format(), - new HttpTraceContext() - ); + const composite = new CompositePropagator({ + propagators: [new B3Format(), new HttpTraceContext()], + }); const spanContext = getExtractedSpanContext( composite.extract(Context.ROOT_CONTEXT, carrier) ); @@ -132,10 +129,9 @@ describe('Composite Propagator', () => { }); it('should not throw', () => { - const composite = new CompositePropagator( - new ThrowingPropagator(), - new HttpTraceContext() - ); + const composite = new CompositePropagator({ + propagators: [new ThrowingPropagator(), new HttpTraceContext()], + }); const spanContext = getExtractedSpanContext( composite.extract(Context.ROOT_CONTEXT, carrier) ); From 8fe82002f39f87a532f019c4294df210fcddb675 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Mar 2020 14:32:47 -0500 Subject: [PATCH 4/6] chore: change error log to warn --- .../opentelemetry-core/src/context/propagation/composite.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry-core/src/context/propagation/composite.ts b/packages/opentelemetry-core/src/context/propagation/composite.ts index 1b088aa918..65578b8aab 100644 --- a/packages/opentelemetry-core/src/context/propagation/composite.ts +++ b/packages/opentelemetry-core/src/context/propagation/composite.ts @@ -46,7 +46,7 @@ export class CompositePropagator implements HttpTextFormat { try { propagator.inject(context, carrier); } catch (err) { - this._logger.error( + this._logger.warn( `Failed to inject with ${propagator.constructor.name}. Err: ${err.message}` ); } @@ -67,7 +67,7 @@ export class CompositePropagator implements HttpTextFormat { try { return propagator.extract(ctx, carrier); } catch (err) { - this._logger.error( + this._logger.warn( `Failed to inject with ${propagator.constructor.name}. Err: ${err.message}` ); } From 1661dd1d3cfc66a5207e7592ac580f8386bc917e Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Mar 2020 14:44:24 -0500 Subject: [PATCH 5/6] chore: move composite propagator config to types file --- .../src/context/propagation/composite.ts | 18 ++--------- .../src/context/propagation/types.ts | 30 +++++++++++++++++++ packages/opentelemetry-core/src/index.ts | 1 + 3 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 packages/opentelemetry-core/src/context/propagation/types.ts diff --git a/packages/opentelemetry-core/src/context/propagation/composite.ts b/packages/opentelemetry-core/src/context/propagation/composite.ts index 65578b8aab..73cd84d08b 100644 --- a/packages/opentelemetry-core/src/context/propagation/composite.ts +++ b/packages/opentelemetry-core/src/context/propagation/composite.ts @@ -16,6 +16,7 @@ import { Carrier, Context, HttpTextFormat, Logger } from '@opentelemetry/api'; import { NoopLogger } from '../../common/NoopLogger'; +import { CompositePropagatorConfig } from './types'; /** Combines multiple propagators into a single propagator. */ export class CompositePropagator implements HttpTextFormat { @@ -37,7 +38,7 @@ export class CompositePropagator implements HttpTextFormat { * Propagators are run in the order they are configured, so if multiple * propagators write the same carrier key, the propagator later in the list * will "win". - * + * * @param context Context to inject * @param carrier Carrier into which context will be injected */ @@ -58,7 +59,7 @@ export class CompositePropagator implements HttpTextFormat { * Propagators are run in the order they are configured, so if multiple * propagators write the same context key, the propagator later in the list * will "win". - * + * * @param context Context to add values to * @param carrier Carrier from which to extract context */ @@ -75,16 +76,3 @@ export class CompositePropagator implements HttpTextFormat { }, context); } } - -/** Configuration object for composite propagator */ -export interface CompositePropagatorConfig { - /** - * List of propagators to run. Propagators run in the - * list order. If a propagator later in the list writes the same context - * key as a propagator earlier in the list, the later on will "win". - */ - propagators?: HttpTextFormat[]; - - /** Instance of logger */ - logger?: Logger; -} diff --git a/packages/opentelemetry-core/src/context/propagation/types.ts b/packages/opentelemetry-core/src/context/propagation/types.ts new file mode 100644 index 0000000000..ff4a95a4f4 --- /dev/null +++ b/packages/opentelemetry-core/src/context/propagation/types.ts @@ -0,0 +1,30 @@ +/*! + * Copyright 2020, 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 { HttpTextFormat, Logger } from '@opentelemetry/api'; + +/** Configuration object for composite propagator */ +export interface CompositePropagatorConfig { + /** + * List of propagators to run. Propagators run in the + * list order. If a propagator later in the list writes the same context + * key as a propagator earlier in the list, the later on will "win". + */ + propagators?: HttpTextFormat[]; + + /** Instance of logger */ + logger?: Logger; +} diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index 002f17ea91..7fb711d43a 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -23,6 +23,7 @@ export * from './context/context'; export * from './context/propagation/B3Format'; export * from './context/propagation/composite'; export * from './context/propagation/HttpTraceContext'; +export * from './context/propagation/types'; export * from './platform'; export * from './trace/instrumentation/BasePlugin'; export * from './trace/NoRecordingSpan'; From 1b8b5b1c95c93664cfa372a7cd1374b8ccb2126e Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Tue, 3 Mar 2020 00:21:42 -0500 Subject: [PATCH 6/6] Update packages/opentelemetry-core/src/context/propagation/composite.ts Co-Authored-By: Olivier Albertini --- .../opentelemetry-core/src/context/propagation/composite.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opentelemetry-core/src/context/propagation/composite.ts b/packages/opentelemetry-core/src/context/propagation/composite.ts index 73cd84d08b..c1a2906658 100644 --- a/packages/opentelemetry-core/src/context/propagation/composite.ts +++ b/packages/opentelemetry-core/src/context/propagation/composite.ts @@ -26,7 +26,7 @@ export class CompositePropagator implements HttpTextFormat { /** * Construct a composite propagator from a list of propagators. * - * @param config Configuration object for composite propagator + * @param [config] Configuration object for composite propagator */ constructor(config: CompositePropagatorConfig = {}) { this._propagators = config.propagators ?? [];