File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,14 +15,19 @@ export function SpanD(name: string): MethodDecorator {
1515 const original = descriptor . value ;
1616
1717 descriptor . value = function ( ...args : any [ ] ) {
18- const tracer = TracingModule . tracer ;
18+ let context : any ;
19+ try {
20+ context = AsyncContext . getInstance ( ) . get ( TRACER_CARRIER_INFO ) ;
21+ } catch ( err ) {
22+ return original . apply ( this , args ) ;
23+ }
1924
20- let context = AsyncContext . getInstance ( ) . get ( TRACER_CARRIER_INFO ) ;
2125 if ( ! context ) {
2226 context = { } ;
2327 AsyncContext . getInstance ( ) . set ( TRACER_CARRIER_INFO , context ) ;
2428 }
2529
30+ const tracer = TracingModule . tracer ;
2631 const ctx = tracer . extract ( FORMAT_TEXT_MAP , context ) ;
2732
2833 let span : Span ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Created by Rain on 2020/7/22
3+ */
4+ import * as assert from 'assert' ;
5+ import { SpanD } from '../lib' ;
6+
7+ class Test2Spec {
8+ @SpanD ( 'Test2Spc' )
9+ say ( ) {
10+ return 's' ;
11+ }
12+ }
13+
14+ describe ( 'test2' , ( ) => {
15+ it ( ' async context not run before spanD run ' , ( ) => {
16+ const test = new Test2Spec ( ) ;
17+
18+ assert . strictEqual ( test . say ( ) , 's' ) ;
19+ } ) ;
20+ } ) ;
You can’t perform that action at this time.
0 commit comments