diff --git a/src/global_tracer.ts b/src/global_tracer.ts index 4d7f1a3..88e8cf7 100644 --- a/src/global_tracer.ts +++ b/src/global_tracer.ts @@ -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: // @@ -43,6 +44,7 @@ const globalTracerDelegate = new GlobalTracerDelegate(); */ export function initGlobalTracer(tracer: Tracer): void { _globalTracer = tracer; + _isRegistered = true; } /** @@ -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; +} diff --git a/src/test/opentracing_api.ts b/src/test/opentracing_api.ts index ec4892b..73a1a77 100644 --- a/src/test/opentracing_api.ts +++ b/src/test/opentracing_api.ts @@ -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', () => { @@ -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);