From 58f4a435efca703021bbe5e5e42586415dd32cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20St=C3=B6bich?= Date: Mon, 21 Dec 2020 23:12:42 +0100 Subject: [PATCH] chore: remove tracer apis not part of spec (#1764) Co-authored-by: Mayur Kale Co-authored-by: Daniel Dyla --- api/README.md | 2 +- api/src/api/global-utils.ts | 2 +- api/src/trace/NoopTracer.ts | 15 ------ api/src/trace/ProxyTracer.ts | 15 ------ api/src/trace/tracer.ts | 47 +------------------ api/test/api/api.test.ts | 16 ------- .../noop-implementations/noop-tracer.test.ts | 18 ------- .../proxy-tracer.test.ts | 11 ----- 8 files changed, 4 insertions(+), 122 deletions(-) diff --git a/api/README.md b/api/README.md index 180ab4c7e2..0f91bb0bca 100644 --- a/api/README.md +++ b/api/README.md @@ -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(); diff --git a/api/src/api/global-utils.ts b/api/src/api/global-utils.ts index 297836e009..5d6ad7de3e 100644 --- a/api/src/api/global-utils.ts +++ b/api/src/api/global-utils.ts @@ -65,4 +65,4 @@ export function makeGetter( * 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; diff --git a/api/src/trace/NoopTracer.ts b/api/src/trace/NoopTracer.ts index 239db89b22..bb25bcbe1d 100644 --- a/api/src/trace/NoopTracer.ts +++ b/api/src/trace/NoopTracer.ts @@ -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); @@ -46,17 +42,6 @@ export class NoopTracer implements Tracer { return NOOP_SPAN; } } - - withSpan ReturnType>( - span: Span, - fn: T - ): ReturnType { - return fn(); - } - - bind(target: T, _span?: Span): T { - return target; - } } function isSpanContext(spanContext: any): spanContext is SpanContext { diff --git a/api/src/trace/ProxyTracer.ts b/api/src/trace/ProxyTracer.ts index e2216eed5e..c6e22433e7 100644 --- a/api/src/trace/ProxyTracer.ts +++ b/api/src/trace/ProxyTracer.ts @@ -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 ReturnType>( - span: Span, - fn: T - ): ReturnType { - return this._getTracer().withSpan(span, fn); - } - - bind(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. diff --git a/api/src/trace/tracer.ts b/api/src/trace/tracer.ts index 6ba051cfee..abc72a53f3 100644 --- a/api/src/trace/tracer.ts +++ b/api/src/trace/tracer.ts @@ -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 @@ -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 ReturnType>( - span: Span, - fn: T - ): ReturnType; - - /** - * 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(target: T, context?: Span): T; } diff --git a/api/test/api/api.test.ts b/api/test/api/api.test.ts index d2ca5daab5..01aaf32df6 100644 --- a/api/test/api/api.test.ts +++ b/api/test/api/api.test.ts @@ -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); @@ -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'); diff --git a/api/test/noop-implementations/noop-tracer.test.ts b/api/test/noop-implementations/noop-tracer.test.ts index 232428e48d..3730968323 100644 --- a/api/test/noop-implementations/noop-tracer.test.ts +++ b/api/test/noop-implementations/noop-tracer.test.ts @@ -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)', () => { diff --git a/api/test/proxy-implementations/proxy-tracer.test.ts b/api/test/proxy-implementations/proxy-tracer.test.ts index 7a110cbfa3..41db382f3d 100644 --- a/api/test/proxy-implementations/proxy-tracer.test.ts +++ b/api/test/proxy-implementations/proxy-tracer.test.ts @@ -56,8 +56,6 @@ describe('ProxyTracer', () => { }), NOOP_SPAN ); - - assert.deepStrictEqual(tracer.getCurrentSpan(), NOOP_SPAN); }); }); @@ -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');