11import { Hub } from '@sentry/hub' ;
22import { TransactionContext } from '@sentry/types' ;
3- import { logger , timestampWithMs } from '@sentry/utils' ;
3+ import { getGlobalObject , logger , timestampWithMs } from '@sentry/utils' ;
44
55import { FINISH_REASON_TAG , IDLE_TRANSACTION_FINISH_REASONS } from './constants' ;
66import { Span , SpanRecorder } from './span' ;
@@ -9,6 +9,8 @@ import { Transaction } from './transaction';
99export const DEFAULT_IDLE_TIMEOUT = 1000 ;
1010export const HEARTBEAT_INTERVAL = 5000 ;
1111
12+ const global = getGlobalObject < Window > ( ) ;
13+
1214/**
1315 * @inheritDoc
1416 */
@@ -71,7 +73,7 @@ export class IdleTransaction extends Transaction {
7173 * If a transaction is created and no activities are added, we want to make sure that
7274 * it times out properly. This is cleared and not used when activities are added.
7375 */
74- private _initTimeout : ReturnType < typeof setTimeout > | undefined ;
76+ private _initTimeout : ReturnType < typeof global . setTimeout > | undefined ;
7577
7678 public constructor (
7779 transactionContext : TransactionContext ,
@@ -96,7 +98,7 @@ export class IdleTransaction extends Transaction {
9698 _idleHub . configureScope ( scope => scope . setSpan ( this ) ) ;
9799 }
98100
99- this . _initTimeout = setTimeout ( ( ) => {
101+ this . _initTimeout = global . setTimeout ( ( ) => {
100102 if ( ! this . _finished ) {
101103 this . finish ( ) ;
102104 }
@@ -221,7 +223,7 @@ export class IdleTransaction extends Transaction {
221223 // Remember timestampWithMs is in seconds, timeout is in ms
222224 const end = timestampWithMs ( ) + timeout / 1000 ;
223225
224- setTimeout ( ( ) => {
226+ global . setTimeout ( ( ) => {
225227 if ( ! this . _finished ) {
226228 this . setTag ( FINISH_REASON_TAG , IDLE_TRANSACTION_FINISH_REASONS [ 1 ] ) ;
227229 this . finish ( end ) ;
@@ -265,7 +267,7 @@ export class IdleTransaction extends Transaction {
265267 */
266268 private _pingHeartbeat ( ) : void {
267269 logger . log ( `pinging Heartbeat -> current counter: ${ this . _heartbeatCounter } ` ) ;
268- setTimeout ( ( ) => {
270+ global . setTimeout ( ( ) => {
269271 this . _beat ( ) ;
270272 } , HEARTBEAT_INTERVAL ) ;
271273 }
0 commit comments