Skip to content

Commit

Permalink
chore: remove tracer apis not part of spec (open-telemetry#1764)
Browse files Browse the repository at this point in the history
Co-authored-by: Mayur Kale <mayurkale@google.com>
Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
  • Loading branch information
3 people committed Feb 18, 2021
1 parent e0fa277 commit 58f4a43
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 122 deletions.
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const api = require("@opentelemetry/api");
const tracer = api.trace.getTracer("my-library-name", "0.2.3");

async function doSomething() {
const span = tracer.startSpan("doSomething", { parent: tracer.getCurrentSpan() });
const span = tracer.startSpan("doSomething");
try {
const result = await doSomethingElse();
span.end();
Expand Down
2 changes: 1 addition & 1 deletion api/src/api/global-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ export function makeGetter<T>(
* version. If the global API is not compatible with the API package
* attempting to get it, a NOOP API implementation will be returned.
*/
export const API_BACKWARDS_COMPATIBILITY_VERSION = 2;
export const API_BACKWARDS_COMPATIBILITY_VERSION = 3;
15 changes: 0 additions & 15 deletions api/src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ import { getSpanContext } from '../context/context';
* No-op implementations of {@link Tracer}.
*/
export class NoopTracer implements Tracer {
getCurrentSpan(): Span {
return NOOP_SPAN;
}

// startSpan starts a noop span.
startSpan(name: string, options?: SpanOptions, context?: Context): Span {
const root = Boolean(options?.root);
Expand All @@ -46,17 +42,6 @@ export class NoopTracer implements Tracer {
return NOOP_SPAN;
}
}

withSpan<T extends (...args: unknown[]) => ReturnType<T>>(
span: Span,
fn: T
): ReturnType<T> {
return fn();
}

bind<T>(target: T, _span?: Span): T {
return target;
}
}

function isSpanContext(spanContext: any): spanContext is SpanContext {
Expand Down
15 changes: 0 additions & 15 deletions api/src/trace/ProxyTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,10 @@ export class ProxyTracer implements Tracer {
public readonly version?: string
) {}

getCurrentSpan(): Span | undefined {
return this._getTracer().getCurrentSpan();
}

startSpan(name: string, options?: SpanOptions): Span {
return this._getTracer().startSpan(name, options);
}

withSpan<T extends (...args: unknown[]) => ReturnType<T>>(
span: Span,
fn: T
): ReturnType<T> {
return this._getTracer().withSpan(span, fn);
}

bind<T>(target: T, span?: Span): T {
return this._getTracer().bind(target, span);
}

/**
* Try to get a tracer from the proxy tracer provider.
* If the proxy tracer provider has no delegate, return a noop tracer.
Expand Down
47 changes: 2 additions & 45 deletions api/src/trace/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,9 @@ import { SpanOptions } from './SpanOptions';
*/
export interface Tracer {
/**
* Returns the current Span from the current context if available.
* Starts a new {@link Span}. Start the span without setting it on context.
*
* If there is no Span associated with the current context, `undefined` is
* returned.
*
* To install a {@link Span} to the current Context use
* {@link Tracer.withSpan}.
*
* @returns Span The currently active Span
*/
getCurrentSpan(): Span | undefined;

/**
* Starts a new {@link Span}. Start the span without setting it as the current
* span in this tracer's context.
*
* This method do NOT modify the current Context. To install a {@link
* Span} to the current Context use {@link Tracer.withSpan}.
* This method do NOT modify the current Context.
*
* @param name The name of the span
* @param [options] SpanOptions used for span creation
Expand All @@ -56,32 +41,4 @@ export interface Tracer {
* span.end();
*/
startSpan(name: string, options?: SpanOptions, context?: Context): Span;

/**
* Executes the function given by fn within the context provided by Span.
*
* This is a convenience method for creating spans attached to the tracer's
* context. Applications that need more control over the span lifetime should
* use {@link Tracer.startSpan} instead.
*
* @param span The span that provides the context
* @param fn The function to be executed inside the provided context
* @example
* tracer.withSpan(span, () => {
* tracer.getCurrentSpan().addEvent("parent's event");
* doSomeOtherWork(); // Here "span" is the current Span.
* });
*/
withSpan<T extends (...args: unknown[]) => ReturnType<T>>(
span: Span,
fn: T
): ReturnType<T>;

/**
* Bind a span as the target's context or propagate the current one.
*
* @param target Any object to which a context need to be set
* @param [context] Optionally specify the context which you want to bind
*/
bind<T>(target: T, context?: Span): T;
}
16 changes: 0 additions & 16 deletions api/test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import api, {
} from '../../src';

describe('API', () => {
const functions = ['getCurrentSpan', 'startSpan', 'withSpan'];

it('should expose a tracer provider via getTracerProvider', () => {
const tracer = api.trace.getTracerProvider();
assert.ok(tracer);
Expand All @@ -59,20 +57,6 @@ describe('API', () => {
metrics.disable();
});

it('should not crash', () => {
functions.forEach(fn => {
const tracer = api.trace.getTracerProvider();
try {
((tracer as unknown) as { [fn: string]: Function })[fn](); // Try to run the function
assert.ok(true, fn);
} catch (err) {
if (err.message !== 'Method not implemented.') {
assert.ok(true, fn);
}
}
});
});

it('should use the global tracer provider', () => {
api.trace.setGlobalTracerProvider(new TestTracerProvider());
const tracer = api.trace.getTracerProvider().getTracer('name');
Expand Down
18 changes: 0 additions & 18 deletions api/test/noop-implementations/noop-tracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@ describe('NoopTracer', () => {
}),
NOOP_SPAN
);

assert.deepStrictEqual(tracer.getCurrentSpan(), NOOP_SPAN);
});

it('should not crash when .withSpan()', done => {
const tracer = new NoopTracer();
tracer.withSpan(NOOP_SPAN, () => {
return done();
});
});

it('should not crash when .bind()', done => {
const tracer = new NoopTracer();
const fn = () => {
return done();
};
const patchedFn = tracer.bind(fn, NOOP_SPAN);
return patchedFn();
});

it('should propagate valid spanContext on the span (from context)', () => {
Expand Down
11 changes: 0 additions & 11 deletions api/test/proxy-implementations/proxy-tracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ describe('ProxyTracer', () => {
}),
NOOP_SPAN
);

assert.deepStrictEqual(tracer.getCurrentSpan(), NOOP_SPAN);
});
});

Expand Down Expand Up @@ -96,18 +94,9 @@ describe('ProxyTracer', () => {
beforeEach(() => {
delegateSpan = new NoopSpan();
delegateTracer = {
bind(target) {
return target;
},
getCurrentSpan() {
return delegateSpan;
},
startSpan() {
return delegateSpan;
},
withSpan(span, fn) {
return fn();
},
};

tracer = provider.getTracer('test');
Expand Down

0 comments on commit 58f4a43

Please sign in to comment.