1
1
import { Hub } from '@sentry/hub' ;
2
2
import { TransactionContext } from '@sentry/types' ;
3
- import { logger , timestampWithMs } from '@sentry/utils' ;
3
+ import { getGlobalObject , logger , timestampWithMs } from '@sentry/utils' ;
4
4
5
5
import { FINISH_REASON_TAG , IDLE_TRANSACTION_FINISH_REASONS } from './constants' ;
6
6
import { Span , SpanRecorder } from './span' ;
@@ -9,6 +9,8 @@ import { Transaction } from './transaction';
9
9
export const DEFAULT_IDLE_TIMEOUT = 1000 ;
10
10
export const HEARTBEAT_INTERVAL = 5000 ;
11
11
12
+ const global = getGlobalObject < Window > ( ) ;
13
+
12
14
/**
13
15
* @inheritDoc
14
16
*/
@@ -71,7 +73,7 @@ export class IdleTransaction extends Transaction {
71
73
* If a transaction is created and no activities are added, we want to make sure that
72
74
* it times out properly. This is cleared and not used when activities are added.
73
75
*/
74
- private _initTimeout : ReturnType < typeof setTimeout > | undefined ;
76
+ private _initTimeout : ReturnType < typeof global . setTimeout > | undefined ;
75
77
76
78
public constructor (
77
79
transactionContext : TransactionContext ,
@@ -96,7 +98,7 @@ export class IdleTransaction extends Transaction {
96
98
_idleHub . configureScope ( scope => scope . setSpan ( this ) ) ;
97
99
}
98
100
99
- this . _initTimeout = setTimeout ( ( ) => {
101
+ this . _initTimeout = global . setTimeout ( ( ) => {
100
102
if ( ! this . _finished ) {
101
103
this . finish ( ) ;
102
104
}
@@ -221,7 +223,7 @@ export class IdleTransaction extends Transaction {
221
223
// Remember timestampWithMs is in seconds, timeout is in ms
222
224
const end = timestampWithMs ( ) + timeout / 1000 ;
223
225
224
- setTimeout ( ( ) => {
226
+ global . setTimeout ( ( ) => {
225
227
if ( ! this . _finished ) {
226
228
this . setTag ( FINISH_REASON_TAG , IDLE_TRANSACTION_FINISH_REASONS [ 1 ] ) ;
227
229
this . finish ( end ) ;
@@ -265,7 +267,7 @@ export class IdleTransaction extends Transaction {
265
267
*/
266
268
private _pingHeartbeat ( ) : void {
267
269
logger . log ( `pinging Heartbeat -> current counter: ${ this . _heartbeatCounter } ` ) ;
268
- setTimeout ( ( ) => {
270
+ global . setTimeout ( ( ) => {
269
271
this . _beat ( ) ;
270
272
} , HEARTBEAT_INTERVAL ) ;
271
273
}
0 commit comments