This repository was archived by the owner on Nov 10, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +56
-23
lines changed Expand file tree Collapse file tree 3 files changed +56
-23
lines changed Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
- import { getSpanContext } from '../trace /context-utils ' ;
17
+ import { ContextAPI } from '../api /context' ;
18
18
import { Context } from '../context/types' ;
19
+ import { getSpanContext } from '../trace/context-utils' ;
19
20
import { NonRecordingSpan } from './NonRecordingSpan' ;
20
21
import { Span } from './span' ;
21
22
import { isSpanContextValid } from './spancontext-utils' ;
@@ -48,12 +49,28 @@ export class NoopTracer implements Tracer {
48
49
49
50
startActiveSpan < F extends ( span : Span ) => ReturnType < F > > (
50
51
name : string ,
51
- options : SpanOptions ,
52
- context : Context ,
53
- fn : F
54
- ) {
55
- const span = this . startSpan ( name , options , context ) ;
56
- return fn ( span ) ;
52
+ optionsOrFn : SpanOptions | F ,
53
+ contextOrFn ?: Context | F ,
54
+ fn ?: F
55
+ ) : ReturnType < F > {
56
+ if ( typeof optionsOrFn === 'function' ) {
57
+ const span = this . startSpan (
58
+ name ,
59
+ undefined ,
60
+ ContextAPI . getInstance ( ) . active ( )
61
+ ) ;
62
+ return optionsOrFn ( span ) ;
63
+ } else if ( typeof contextOrFn === 'function' ) {
64
+ const span = this . startSpan (
65
+ name ,
66
+ optionsOrFn ,
67
+ ContextAPI . getInstance ( ) . active ( )
68
+ ) ;
69
+ return contextOrFn ( span ) ;
70
+ } else {
71
+ const span = this . startSpan ( name , optionsOrFn , contextOrFn ) ;
72
+ return fn ! ( span ) ;
73
+ }
57
74
}
58
75
}
59
76
Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
+ import { ContextAPI } from '../api/context' ;
17
18
import { Context } from '../context/types' ;
18
19
import { NOOP_TRACER } from './NoopTracer' ;
19
20
import { ProxyTracerProvider } from './ProxyTracerProvider' ;
@@ -40,12 +41,28 @@ export class ProxyTracer implements Tracer {
40
41
41
42
startActiveSpan < F extends ( span : Span ) => ReturnType < F > > (
42
43
name : string ,
43
- options : SpanOptions ,
44
- context : Context ,
45
- fn : F
46
- ) {
47
- const span = this . startSpan ( name , options , context ) ;
48
- return fn ( span ) ;
44
+ optionsOrFn : SpanOptions | F ,
45
+ contextOrFn ?: Context | F ,
46
+ fn ?: F
47
+ ) : ReturnType < F > {
48
+ if ( typeof optionsOrFn === 'function' ) {
49
+ const span = this . startSpan (
50
+ name ,
51
+ undefined ,
52
+ ContextAPI . getInstance ( ) . active ( )
53
+ ) ;
54
+ return optionsOrFn ( span ) ;
55
+ } else if ( typeof contextOrFn === 'function' ) {
56
+ const span = this . startSpan (
57
+ name ,
58
+ optionsOrFn ,
59
+ ContextAPI . getInstance ( ) . active ( )
60
+ ) ;
61
+ return contextOrFn ( span ) ;
62
+ } else {
63
+ const span = this . startSpan ( name , optionsOrFn , contextOrFn ) ;
64
+ return fn ! ( span ) ;
65
+ }
49
66
}
50
67
51
68
/**
Original file line number Diff line number Diff line change @@ -52,16 +52,15 @@ export interface Tracer {
52
52
* span.end();
53
53
* });
54
54
*/
55
- // todo: figure out overloading
56
- // startActiveSpan?<F extends (span: Span) => ReturnType<F>>(
57
- // name: string,
58
- // fn: F
59
- // ): ReturnType<F>;
60
- // startActiveSpan?<F extends (span: Span) => ReturnType<F>>(
61
- // name: string,
62
- // options: SpanOptions,
63
- // fn: F
64
- // ): ReturnType<F>;
55
+ startActiveSpan ?< F extends ( span : Span ) => ReturnType < F > > (
56
+ name : string ,
57
+ fn : F
58
+ ) : ReturnType < F > ;
59
+ startActiveSpan ?< F extends ( span : Span ) => ReturnType < F > > (
60
+ name : string ,
61
+ options : SpanOptions ,
62
+ fn : F
63
+ ) : ReturnType < F > ;
65
64
startActiveSpan ?< F extends ( span : Span ) => ReturnType < F > > (
66
65
name : string ,
67
66
options : SpanOptions ,
You can’t perform that action at this time.
0 commit comments