From fadebf353c63427120ef1a4741d74f1027bb903c Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Thu, 14 Jan 2021 00:07:46 +0200 Subject: [PATCH] fix(api): add public 'fields' function to api.propagator (#1813) * fix(api): add public 'fields' function to api.propagator * chore: remove redundant comment Co-authored-by: Daniel Dyla --- packages/opentelemetry-api/src/api/propagation.ts | 7 +++++++ .../src/context/propagation/TextMapPropagator.ts | 3 --- packages/opentelemetry-api/test/api/api.test.ts | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/opentelemetry-api/src/api/propagation.ts b/packages/opentelemetry-api/src/api/propagation.ts index a07b88b94d..b99dada22a 100644 --- a/packages/opentelemetry-api/src/api/propagation.ts +++ b/packages/opentelemetry-api/src/api/propagation.ts @@ -96,6 +96,13 @@ export class PropagationAPI { return this._getGlobalPropagator().extract(context, carrier, getter); } + /** + * Return a list of all fields which may be used by the propagator. + */ + public fields(): string[] { + return this._getGlobalPropagator().fields(); + } + /** Remove the global propagator */ public disable() { delete _global[GLOBAL_PROPAGATION_API_KEY]; diff --git a/packages/opentelemetry-api/src/context/propagation/TextMapPropagator.ts b/packages/opentelemetry-api/src/context/propagation/TextMapPropagator.ts index 59f2d39f8a..b659a9704d 100644 --- a/packages/opentelemetry-api/src/context/propagation/TextMapPropagator.ts +++ b/packages/opentelemetry-api/src/context/propagation/TextMapPropagator.ts @@ -67,9 +67,6 @@ export interface TextMapPropagator { /** * Return a list of all fields which may be used by the propagator. - * - * This list should be used to clear fields before calling inject if a carrier is - * used more than once. */ fields(): string[]; } diff --git a/packages/opentelemetry-api/test/api/api.test.ts b/packages/opentelemetry-api/test/api/api.test.ts index 01aaf32df6..cc02a460f8 100644 --- a/packages/opentelemetry-api/test/api/api.test.ts +++ b/packages/opentelemetry-api/test/api/api.test.ts @@ -150,6 +150,13 @@ describe('API', () => { assert.strictEqual(data.carrier, carrier); assert.strictEqual(data.getter, getter); }); + + it('fields', () => { + api.propagation.setGlobalPropagator(new TestTextMapPropagation()); + + const fields = api.propagation.fields(); + assert.deepStrictEqual(fields, ['TestField']); + }); }); }); });