Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): add public 'fields' function to api.propagator #1813

Merged
merged 5 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 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,16 @@ export class PropagationAPI {
return this._getGlobalPropagator().extract(context, carrier, getter);
}

/**
* 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.
*/
dyladan marked this conversation as resolved.
Show resolved Hide resolved
public fields(): string[] {
return this._getGlobalPropagator().fields();
}

/** Remove the global propagator */
public disable() {
delete _global[GLOBAL_PROPAGATION_API_KEY];
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']);
});
});
});
});