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

feature(trace): adds named tracer factory #420

Closed
wants to merge 24 commits into from
Closed
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
Prev Previous commit
Next Next commit
Adds test for noop factory
  • Loading branch information
Brandon Gonzalez committed Oct 10, 2019
commit b3e55087a5fbfdb9cd90f57970829923c4b410f1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as types from '@opentelemetry/types';
import { NoopTracerFactory } from './NoopTracerFactory';

// Acts a bridge to the global tracer factory that can be safely called before the
// global tracer is initialized. The purpose of the delegation is to avoid the
// global tracer factory is initialized. The purpose of the delegation is to avoid the
// sometimes nearly intractable initialization order problems that can arise in
// applications with a complex set of dependencies. Also allows for the factory
// to be changed/disabled during runtime without needing to change reference
Expand Down Expand Up @@ -48,13 +48,12 @@ export class TracerFactoryDelegate implements types.TracerFactory {
this._tracerFactory || this._fallbackTracerFactory;
}

// Stop the delegate from using the provided tracer. Begin to use the fallback tracer
// Stop the delegate from using the provided tracer factory. Begin to use the fallback factory
stop(): void {
this._currentTracerFactory = this._fallbackTracerFactory;
}

// -- TracerFactory interface implementation below -- //

getTracer(name?: string, version?: string): types.Tracer {
return this._currentTracerFactory.getTracer.apply(
bg451 marked this conversation as resolved.
Show resolved Hide resolved
this._currentTracerFactory,
Expand Down
12 changes: 12 additions & 0 deletions packages/opentelemetry-core/test/trace/NoopTraceFactory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as assert from 'assert';
import { NoopTracer } from '../../src/trace/NoopTracer';
import { NoopTracerFactory } from '../../src/trace/NoopTracerFactory';
import { NOOP_SPAN } from '../../src/trace/NoopSpan';

describe('NoopTracerFactory', () => {
it('should return a NOOP_SPAN', () => {
const factory = new NoopTracerFactory();
const span = factory.getTracer().startSpan('my-span')
assert.deepStrictEqual(span, NOOP_SPAN);
})
})