Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Merge a7c96b0 into 7ca5a00
Browse files Browse the repository at this point in the history
  • Loading branch information
Flarna authored Jul 26, 2021
2 parents 7ca5a00 + a7c96b0 commit 82142be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/api/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ export class TraceAPI {
* @returns true if the tracer provider was successfully registered, else false
*/
public setGlobalTracerProvider(provider: TracerProvider): boolean {
this._proxyTracerProvider.setDelegate(provider);
return registerGlobal(
const success = registerGlobal(
API_NAME,
this._proxyTracerProvider,
DiagAPI.instance()
);
if (success) {
this._proxyTracerProvider.setDelegate(provider);
}
return success;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ describe('API', () => {
assert.deepStrictEqual(span, dummySpan);
});

it('should set delegate only on success', () => {
assert.strictEqual(
api.trace.setGlobalTracerProvider(new TestTracerProvider()),
true
);
assert.strictEqual(
api.trace.setGlobalTracerProvider(new NoopTracerProvider()),
false
);
assert.ok(api.trace.getTracer('name') instanceof TestTracer);
});

class TestTracer extends NoopTracer {
override startSpan(name: string, options?: SpanOptions): Span {
return dummySpan;
Expand Down

0 comments on commit 82142be

Please sign in to comment.