Skip to content

Commit

Permalink
fix(api): add public 'fields' function to api.propagator (#1813)
Browse files Browse the repository at this point in the history
* fix(api): add public 'fields' function to api.propagator

* chore: remove redundant comment

Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
  • Loading branch information
blumamir and dyladan committed Jan 13, 2021
1 parent 139d9db commit fadebf3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/opentelemetry-api/src/api/propagation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ export interface TextMapPropagator<Carrier = any> {

/**
* 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[];
}
Expand Down
7 changes: 7 additions & 0 deletions packages/opentelemetry-api/test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
});
});
});

0 comments on commit fadebf3

Please sign in to comment.