File tree Expand file tree Collapse file tree 2 files changed +28
-15
lines changed Expand file tree Collapse file tree 2 files changed +28
-15
lines changed Original file line number Diff line number Diff line change @@ -111,9 +111,6 @@ export class IdleTransaction extends Transaction {
111
111
super ( transactionContext , _idleHub ) ;
112
112
113
113
if ( _onScope ) {
114
- // There should only be one active transaction on the scope
115
- clearActiveTransaction ( _idleHub ) ;
116
-
117
114
// We set the transaction here on the scope so error events pick up the trace
118
115
// context and attach it to the error.
119
116
__DEBUG_BUILD__ && logger . log ( `Setting idle transaction on scope. Span ID: ${ this . spanId } ` ) ;
@@ -179,7 +176,10 @@ export class IdleTransaction extends Transaction {
179
176
180
177
// if `this._onScope` is `true`, the transaction put itself on the scope when it started
181
178
if ( this . _onScope ) {
182
- clearActiveTransaction ( this . _idleHub ) ;
179
+ const scope = this . _idleHub . getScope ( ) ;
180
+ if ( scope . getTransaction ( ) === this ) {
181
+ scope . setSpan ( undefined ) ;
182
+ }
183
183
}
184
184
185
185
return super . finish ( endTimestamp ) ;
@@ -353,13 +353,3 @@ export class IdleTransaction extends Transaction {
353
353
} , this . _heartbeatInterval ) ;
354
354
}
355
355
}
356
-
357
- /**
358
- * Reset transaction on scope to `undefined`
359
- */
360
- function clearActiveTransaction ( hub : Hub ) : void {
361
- const scope = hub . getScope ( ) ;
362
- if ( scope . getTransaction ( ) ) {
363
- scope . setSpan ( undefined ) ;
364
- }
365
- }
Original file line number Diff line number Diff line change 1
1
import { BrowserClient } from '@sentry/browser' ;
2
- import { TRACING_DEFAULTS } from '@sentry/core' ;
2
+ import { TRACING_DEFAULTS , Transaction } from '@sentry/core' ;
3
3
4
4
import { Hub , IdleTransaction , Span } from '../../core/src' ;
5
5
import { IdleTransactionSpanRecorder } from '../../core/src/tracing/idletransaction' ;
@@ -75,6 +75,29 @@ describe('IdleTransaction', () => {
75
75
expect ( s . getTransaction ( ) ) . toBe ( undefined ) ;
76
76
} ) ;
77
77
} ) ;
78
+
79
+ it ( 'does not remove transaction from scope on finish if another transaction was set there' , ( ) => {
80
+ const transaction = new IdleTransaction (
81
+ { name : 'foo' } ,
82
+ hub ,
83
+ TRACING_DEFAULTS . idleTimeout ,
84
+ TRACING_DEFAULTS . finalTimeout ,
85
+ TRACING_DEFAULTS . heartbeatInterval ,
86
+ true ,
87
+ ) ;
88
+ transaction . initSpanRecorder ( 10 ) ;
89
+
90
+ // @ts -ignore need to pass in hub
91
+ const otherTransaction = new Transaction ( { name : 'bar' } , hub ) ;
92
+ hub . getScope ( ) . setSpan ( otherTransaction ) ;
93
+
94
+ transaction . finish ( ) ;
95
+ jest . runAllTimers ( ) ;
96
+
97
+ hub . configureScope ( s => {
98
+ expect ( s . getTransaction ( ) ) . toBe ( otherTransaction ) ;
99
+ } ) ;
100
+ } ) ;
78
101
} ) ;
79
102
80
103
beforeEach ( ( ) => {
You can’t perform that action at this time.
0 commit comments