1
1
import { BrowserClient } from '@sentry/browser' ;
2
2
import { Hub , Scope } from '@sentry/hub' ;
3
+ import { Span , Transaction } from '@sentry/types' ;
3
4
4
5
import { addExtensionMethods } from '../src/hubextensions' ;
5
6
@@ -36,14 +37,22 @@ describe('Hub', () => {
36
37
} ) ;
37
38
} ) ;
38
39
39
- describe ( 'start ' , ( ) => {
40
- test ( 'simple' , ( ) => {
40
+ describe ( 'startSpan ' , ( ) => {
41
+ test ( 'simple standalone Span ' , ( ) => {
41
42
const hub = new Hub ( new BrowserClient ( ) ) ;
42
43
const span = hub . startSpan ( { } ) as any ;
43
44
expect ( span . spanId ) . toBeTruthy ( ) ;
44
45
} ) ;
45
46
46
- test ( 'transaction inherits trace_id from span on scope' , ( ) => {
47
+ test ( 'simple standalone Transaction' , ( ) => {
48
+ const hub = new Hub ( new BrowserClient ( { tracesSampleRate : 1 } ) ) ;
49
+ const transaction = hub . startSpan ( { name : 'transaction' } ) as Transaction ;
50
+ expect ( transaction . spanId ) . toBeTruthy ( ) ;
51
+ // tslint:disable-next-line: no-unbound-method
52
+ expect ( transaction . setName ) . toBeTruthy ( ) ;
53
+ } ) ;
54
+
55
+ test ( 'Transaction inherits trace_id from span on scope' , ( ) => {
47
56
const myScope = new Scope ( ) ;
48
57
const hub = new Hub ( new BrowserClient ( ) , myScope ) ;
49
58
const parentSpan = hub . startSpan ( { } ) as any ;
@@ -53,6 +62,24 @@ describe('Hub', () => {
53
62
const span = hub . startSpan ( { name : 'test' } ) as any ;
54
63
expect ( span . trace_id ) . toEqual ( parentSpan . trace_id ) ;
55
64
} ) ;
65
+
66
+ test ( 'create a child if there is a Span already on the scope' , ( ) => {
67
+ const myScope = new Scope ( ) ;
68
+ const hub = new Hub ( new BrowserClient ( { tracesSampleRate : 1 } ) , myScope ) ;
69
+ const transaction = hub . startSpan ( { name : 'transaction' } ) as Transaction ;
70
+ hub . configureScope ( scope => {
71
+ scope . setSpan ( transaction ) ;
72
+ } ) ;
73
+ const span = hub . startSpan ( { } ) as Span ;
74
+ expect ( span . traceId ) . toEqual ( transaction . traceId ) ;
75
+ expect ( span . parentSpanId ) . toEqual ( transaction . spanId ) ;
76
+ hub . configureScope ( scope => {
77
+ scope . setSpan ( span ) ;
78
+ } ) ;
79
+ const span2 = hub . startSpan ( { } ) as Span ;
80
+ expect ( span2 . traceId ) . toEqual ( span . traceId ) ;
81
+ expect ( span2 . parentSpanId ) . toEqual ( span . spanId ) ;
82
+ } ) ;
56
83
} ) ;
57
84
} ) ;
58
85
} ) ;
0 commit comments