File tree 3 files changed +9
-13
lines changed
3 files changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -11,27 +11,23 @@ describe('Hub', () => {
11
11
jest . useRealTimers ( ) ;
12
12
} ) ;
13
13
14
- describe ( 'getSpan ' , ( ) => {
14
+ describe ( 'getTransaction ' , ( ) => {
15
15
test ( 'simple invoke' , ( ) => {
16
16
const hub = new Hub ( new BrowserClient ( { tracesSampleRate : 1 } ) ) ;
17
17
const transaction = hub . startTransaction ( { name : 'foo' } ) ;
18
18
hub . configureScope ( scope => {
19
19
scope . setSpan ( transaction ) ;
20
20
} ) ;
21
21
hub . configureScope ( s => {
22
- s . getTransaction ( t => {
23
- expect ( t ) . toBe ( transaction ) ;
24
- } ) ;
22
+ expect ( s . getTransaction ( ) ) . toBe ( transaction ) ;
25
23
} ) ;
26
24
} ) ;
27
25
28
26
test ( 'not invoke' , ( ) => {
29
27
const hub = new Hub ( new BrowserClient ( { tracesSampleRate : 1 } ) ) ;
30
28
const transaction = hub . startTransaction ( { name : 'foo' } ) ;
31
29
hub . configureScope ( s => {
32
- s . getTransaction ( _ => {
33
- expect ( true ) . toBe ( false ) ;
34
- } ) ;
30
+ expect ( s . getTransaction ( ) ) . toBeUndefined ( ) ;
35
31
} ) ;
36
32
transaction . finish ( ) ;
37
33
} ) ;
Original file line number Diff line number Diff line change @@ -229,13 +229,14 @@ export class Scope implements ScopeInterface {
229
229
/**
230
230
* @inheritDoc
231
231
*/
232
- public getTransaction ( callback : ( transaction : Transaction ) => void ) : void {
232
+ public getTransaction ( ) : Transaction | undefined {
233
233
const span = this . getSpan ( ) as Span & { spanRecorder : { spans : Span [ ] } } ;
234
234
if ( span ) {
235
235
if ( span . spanRecorder && span . spanRecorder . spans [ 0 ] ) {
236
- callback ( span . spanRecorder . spans [ 0 ] as Transaction ) ;
236
+ return span . spanRecorder . spans [ 0 ] as Transaction ;
237
237
}
238
238
}
239
+ return undefined ;
239
240
}
240
241
241
242
/**
Original file line number Diff line number Diff line change @@ -90,15 +90,14 @@ export interface Scope {
90
90
setSpan ( span ?: Span ) : this;
91
91
92
92
/**
93
- * Returns the current set span if there is one
93
+ * Returns the `Span` if there is one
94
94
*/
95
95
getSpan ( ) : Span | undefined ;
96
96
97
97
/**
98
- * Callback to retrieve an ongoing Transaction in case there is one.
99
- * @param callback Will only be invoked in case there is an active transaction
98
+ * Returns the `Transaction` if there is one
100
99
*/
101
- getTransaction ( callback : ( transaction : Transaction ) => void ) : void ;
100
+ getTransaction ( ) : Transaction | undefined ;
102
101
103
102
/**
104
103
* Updates the scope with provided data. Can work in three variations:
You can’t perform that action at this time.
0 commit comments