Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
add support for knowing if a global tracer has been registered
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeGoldsmith committed Dec 11, 2018
1 parent 3b03e8e commit 08a0b83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/global_tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Tracer from './tracer';

const noopTracer = new Tracer();
let _globalTracer: Tracer | null = null;
let _isRegistered: boolean = false;

// Allows direct importing/requiring of the global tracer:
//
Expand Down Expand Up @@ -43,6 +44,7 @@ const globalTracerDelegate = new GlobalTracerDelegate();
*/
export function initGlobalTracer(tracer: Tracer): void {
_globalTracer = tracer;
_isRegistered = true;
}

/**
Expand All @@ -55,3 +57,10 @@ export function globalTracer(): Tracer {
// order.
return globalTracerDelegate;
}

/**
* Returns true if a global tracer has been registered, otherwise false.
*/
export function isGlobalTracerRegistered(): boolean {
return _isRegistered;
}
5 changes: 4 additions & 1 deletion src/test/opentracing_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function opentracingAPITests(): void {
'childOf',
'followsFrom',
'initGlobalTracer',
'globalTracer'
'globalTracer',
'isGlobalTracerRegistered'
];
for (const name of funcs) {
it(name + ' should be a function', () => {
Expand All @@ -47,7 +48,9 @@ export function opentracingAPITests(): void {
});

it('should use the global tracer', () => {
expect(opentracing.isGlobalTracerRegistered()).to.equal(false);
opentracing.initGlobalTracer(new TestTracer());
expect(opentracing.isGlobalTracerRegistered()).to.equal(true);
const tracer = opentracing.globalTracer();
const span = tracer.startSpan('test');
expect(span).to.equal(dummySpan);
Expand Down

0 comments on commit 08a0b83

Please sign in to comment.