1
1
/* eslint-disable max-lines */
2
2
import { Hub } from '@sentry/hub' ;
3
3
import { TransactionContext } from '@sentry/types' ;
4
- import { getGlobalObject , logger , timestampWithMs } from '@sentry/utils' ;
4
+ import { logger , timestampWithMs } from '@sentry/utils' ;
5
5
6
6
import { IS_DEBUG_BUILD } from './flags' ;
7
7
import { Span , SpanRecorder } from './span' ;
@@ -11,8 +11,6 @@ export const DEFAULT_IDLE_TIMEOUT = 1000;
11
11
export const DEFAULT_FINAL_TIMEOUT = 30000 ;
12
12
export const HEARTBEAT_INTERVAL = 5000 ;
13
13
14
- const global = getGlobalObject < Window > ( ) ;
15
-
16
14
/**
17
15
* @inheritDoc
18
16
*/
@@ -72,15 +70,16 @@ export class IdleTransaction extends Transaction {
72
70
private readonly _beforeFinishCallbacks : BeforeFinishCallback [ ] = [ ] ;
73
71
74
72
/**
75
- * Timer that tracks a
73
+ * Timer that tracks Transaction idleTimeout
76
74
*/
77
- private _idleTimeoutID : ReturnType < typeof global . setTimeout > | undefined ;
75
+ private _idleTimeoutID : ReturnType < typeof setTimeout > | undefined ;
78
76
79
77
public constructor (
80
78
transactionContext : TransactionContext ,
81
79
private readonly _idleHub : Hub ,
82
80
/**
83
- * The time to wait in ms until the idle transaction will be finished.
81
+ * The time to wait in ms until the idle transaction will be finished. This timer is started each time
82
+ * there are no active spans on this transaction.
84
83
*/
85
84
private readonly _idleTimeout : number = DEFAULT_IDLE_TIMEOUT ,
86
85
/**
@@ -103,7 +102,7 @@ export class IdleTransaction extends Transaction {
103
102
}
104
103
105
104
this . _startIdleTimeout ( ) ;
106
- global . setTimeout ( ( ) => {
105
+ setTimeout ( ( ) => {
107
106
if ( ! this . _finished ) {
108
107
this . setStatus ( 'deadline_exceeded' ) ;
109
108
this . finish ( ) ;
@@ -114,7 +113,6 @@ export class IdleTransaction extends Transaction {
114
113
/** {@inheritDoc } */
115
114
public finish ( endTimestamp : number = timestampWithMs ( ) ) : string | undefined {
116
115
this . _finished = true ;
117
- this . _cancelIdleTimeout ( ) ;
118
116
this . activities = { } ;
119
117
120
118
if ( this . spanRecorder ) {
@@ -206,7 +204,7 @@ export class IdleTransaction extends Transaction {
206
204
*/
207
205
private _cancelIdleTimeout ( ) : void {
208
206
if ( this . _idleTimeoutID ) {
209
- global . clearTimeout ( this . _idleTimeoutID ) ;
207
+ clearTimeout ( this . _idleTimeoutID ) ;
210
208
this . _idleTimeoutID = undefined ;
211
209
}
212
210
}
@@ -216,7 +214,7 @@ export class IdleTransaction extends Transaction {
216
214
*/
217
215
private _startIdleTimeout ( endTimestamp ?: Parameters < IdleTransaction [ 'finish' ] > [ 0 ] ) : void {
218
216
this . _cancelIdleTimeout ( ) ;
219
- this . _idleTimeoutID = global . setTimeout ( ( ) => {
217
+ this . _idleTimeoutID = setTimeout ( ( ) => {
220
218
if ( ! this . _finished && Object . keys ( this . activities ) . length === 0 ) {
221
219
this . finish ( endTimestamp ) ;
222
220
}
@@ -288,7 +286,7 @@ export class IdleTransaction extends Transaction {
288
286
*/
289
287
private _pingHeartbeat ( ) : void {
290
288
IS_DEBUG_BUILD && logger . log ( `pinging Heartbeat -> current counter: ${ this . _heartbeatCounter } ` ) ;
291
- global . setTimeout ( ( ) => {
289
+ setTimeout ( ( ) => {
292
290
this . _beat ( ) ;
293
291
} , HEARTBEAT_INTERVAL ) ;
294
292
}
@@ -297,14 +295,12 @@ export class IdleTransaction extends Transaction {
297
295
/**
298
296
* Reset transaction on scope to `undefined`
299
297
*/
300
- function clearActiveTransaction ( hub ?: Hub ) : void {
301
- if ( hub ) {
302
- const scope = hub . getScope ( ) ;
303
- if ( scope ) {
304
- const transaction = scope . getTransaction ( ) ;
305
- if ( transaction ) {
306
- scope . setSpan ( undefined ) ;
307
- }
298
+ function clearActiveTransaction ( hub : Hub ) : void {
299
+ const scope = hub . getScope ( ) ;
300
+ if ( scope ) {
301
+ const transaction = scope . getTransaction ( ) ;
302
+ if ( transaction ) {
303
+ scope . setSpan ( undefined ) ;
308
304
}
309
305
}
310
306
}
0 commit comments