Skip to content

Commit 0c12184

Browse files
Flarnamayurkale22dyladan
committed
chore: remove tracer apis not part of spec (open-telemetry#1764)
Co-authored-by: Mayur Kale <[email protected]> Co-authored-by: Daniel Dyla <[email protected]>
1 parent 0ae3e85 commit 0c12184

File tree

8 files changed

+4
-122
lines changed

8 files changed

+4
-122
lines changed

api/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ const api = require("@opentelemetry/api");
160160
const tracer = api.trace.getTracer("my-library-name", "0.2.3");
161161

162162
async function doSomething() {
163-
const span = tracer.startSpan("doSomething", { parent: tracer.getCurrentSpan() });
163+
const span = tracer.startSpan("doSomething");
164164
try {
165165
const result = await doSomethingElse();
166166
span.end();

api/src/api/global-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ export function makeGetter<T>(
6565
* version. If the global API is not compatible with the API package
6666
* attempting to get it, a NOOP API implementation will be returned.
6767
*/
68-
export const API_BACKWARDS_COMPATIBILITY_VERSION = 2;
68+
export const API_BACKWARDS_COMPATIBILITY_VERSION = 3;

api/src/trace/NoopTracer.ts

-15
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ import { getSpanContext } from '../context/context';
2424
* No-op implementations of {@link Tracer}.
2525
*/
2626
export class NoopTracer implements Tracer {
27-
getCurrentSpan(): Span {
28-
return NOOP_SPAN;
29-
}
30-
3127
// startSpan starts a noop span.
3228
startSpan(name: string, options?: SpanOptions, context?: Context): Span {
3329
const root = Boolean(options?.root);
@@ -46,17 +42,6 @@ export class NoopTracer implements Tracer {
4642
return NOOP_SPAN;
4743
}
4844
}
49-
50-
withSpan<T extends (...args: unknown[]) => ReturnType<T>>(
51-
span: Span,
52-
fn: T
53-
): ReturnType<T> {
54-
return fn();
55-
}
56-
57-
bind<T>(target: T, _span?: Span): T {
58-
return target;
59-
}
6045
}
6146

6247
function isSpanContext(spanContext: any): spanContext is SpanContext {

api/src/trace/ProxyTracer.ts

-15
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,10 @@ export class ProxyTracer implements Tracer {
3131
public readonly version?: string
3232
) {}
3333

34-
getCurrentSpan(): Span | undefined {
35-
return this._getTracer().getCurrentSpan();
36-
}
37-
3834
startSpan(name: string, options?: SpanOptions): Span {
3935
return this._getTracer().startSpan(name, options);
4036
}
4137

42-
withSpan<T extends (...args: unknown[]) => ReturnType<T>>(
43-
span: Span,
44-
fn: T
45-
): ReturnType<T> {
46-
return this._getTracer().withSpan(span, fn);
47-
}
48-
49-
bind<T>(target: T, span?: Span): T {
50-
return this._getTracer().bind(target, span);
51-
}
52-
5338
/**
5439
* Try to get a tracer from the proxy tracer provider.
5540
* If the proxy tracer provider has no delegate, return a noop tracer.

api/src/trace/tracer.ts

+2-45
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,9 @@ import { SpanOptions } from './SpanOptions';
2727
*/
2828
export interface Tracer {
2929
/**
30-
* Returns the current Span from the current context if available.
30+
* Starts a new {@link Span}. Start the span without setting it on context.
3131
*
32-
* If there is no Span associated with the current context, `undefined` is
33-
* returned.
34-
*
35-
* To install a {@link Span} to the current Context use
36-
* {@link Tracer.withSpan}.
37-
*
38-
* @returns Span The currently active Span
39-
*/
40-
getCurrentSpan(): Span | undefined;
41-
42-
/**
43-
* Starts a new {@link Span}. Start the span without setting it as the current
44-
* span in this tracer's context.
45-
*
46-
* This method do NOT modify the current Context. To install a {@link
47-
* Span} to the current Context use {@link Tracer.withSpan}.
32+
* This method do NOT modify the current Context.
4833
*
4934
* @param name The name of the span
5035
* @param [options] SpanOptions used for span creation
@@ -56,32 +41,4 @@ export interface Tracer {
5641
* span.end();
5742
*/
5843
startSpan(name: string, options?: SpanOptions, context?: Context): Span;
59-
60-
/**
61-
* Executes the function given by fn within the context provided by Span.
62-
*
63-
* This is a convenience method for creating spans attached to the tracer's
64-
* context. Applications that need more control over the span lifetime should
65-
* use {@link Tracer.startSpan} instead.
66-
*
67-
* @param span The span that provides the context
68-
* @param fn The function to be executed inside the provided context
69-
* @example
70-
* tracer.withSpan(span, () => {
71-
* tracer.getCurrentSpan().addEvent("parent's event");
72-
* doSomeOtherWork(); // Here "span" is the current Span.
73-
* });
74-
*/
75-
withSpan<T extends (...args: unknown[]) => ReturnType<T>>(
76-
span: Span,
77-
fn: T
78-
): ReturnType<T>;
79-
80-
/**
81-
* Bind a span as the target's context or propagate the current one.
82-
*
83-
* @param target Any object to which a context need to be set
84-
* @param [context] Optionally specify the context which you want to bind
85-
*/
86-
bind<T>(target: T, context?: Span): T;
8744
}

api/test/api/api.test.ts

-16
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ import api, {
3636
} from '../../src';
3737

3838
describe('API', () => {
39-
const functions = ['getCurrentSpan', 'startSpan', 'withSpan'];
40-
4139
it('should expose a tracer provider via getTracerProvider', () => {
4240
const tracer = api.trace.getTracerProvider();
4341
assert.ok(tracer);
@@ -59,20 +57,6 @@ describe('API', () => {
5957
metrics.disable();
6058
});
6159

62-
it('should not crash', () => {
63-
functions.forEach(fn => {
64-
const tracer = api.trace.getTracerProvider();
65-
try {
66-
((tracer as unknown) as { [fn: string]: Function })[fn](); // Try to run the function
67-
assert.ok(true, fn);
68-
} catch (err) {
69-
if (err.message !== 'Method not implemented.') {
70-
assert.ok(true, fn);
71-
}
72-
}
73-
});
74-
});
75-
7660
it('should use the global tracer provider', () => {
7761
api.trace.setGlobalTracerProvider(new TestTracerProvider());
7862
const tracer = api.trace.getTracerProvider().getTracer('name');

api/test/noop-implementations/noop-tracer.test.ts

-18
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,6 @@ describe('NoopTracer', () => {
4040
}),
4141
NOOP_SPAN
4242
);
43-
44-
assert.deepStrictEqual(tracer.getCurrentSpan(), NOOP_SPAN);
45-
});
46-
47-
it('should not crash when .withSpan()', done => {
48-
const tracer = new NoopTracer();
49-
tracer.withSpan(NOOP_SPAN, () => {
50-
return done();
51-
});
52-
});
53-
54-
it('should not crash when .bind()', done => {
55-
const tracer = new NoopTracer();
56-
const fn = () => {
57-
return done();
58-
};
59-
const patchedFn = tracer.bind(fn, NOOP_SPAN);
60-
return patchedFn();
6143
});
6244

6345
it('should propagate valid spanContext on the span (from context)', () => {

api/test/proxy-implementations/proxy-tracer.test.ts

-11
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ describe('ProxyTracer', () => {
5656
}),
5757
NOOP_SPAN
5858
);
59-
60-
assert.deepStrictEqual(tracer.getCurrentSpan(), NOOP_SPAN);
6159
});
6260
});
6361

@@ -96,18 +94,9 @@ describe('ProxyTracer', () => {
9694
beforeEach(() => {
9795
delegateSpan = new NoopSpan();
9896
delegateTracer = {
99-
bind(target) {
100-
return target;
101-
},
102-
getCurrentSpan() {
103-
return delegateSpan;
104-
},
10597
startSpan() {
10698
return delegateSpan;
10799
},
108-
withSpan(span, fn) {
109-
return fn();
110-
},
111100
};
112101

113102
tracer = provider.getTracer('test');

0 commit comments

Comments
 (0)