11/* eslint-disable max-lines */
22import { Hub } from '@sentry/hub' ;
33import { TransactionContext } from '@sentry/types' ;
4- import { getGlobalObject , logger , timestampWithMs } from '@sentry/utils' ;
4+ import { logger , timestampWithMs } from '@sentry/utils' ;
55
66import { IS_DEBUG_BUILD } from './flags' ;
77import { Span , SpanRecorder } from './span' ;
@@ -11,8 +11,6 @@ export const DEFAULT_IDLE_TIMEOUT = 1000;
1111export const DEFAULT_FINAL_TIMEOUT = 30000 ;
1212export const HEARTBEAT_INTERVAL = 5000 ;
1313
14- const global = getGlobalObject < Window > ( ) ;
15-
1614/**
1715 * @inheritDoc
1816 */
@@ -72,15 +70,16 @@ export class IdleTransaction extends Transaction {
7270 private readonly _beforeFinishCallbacks : BeforeFinishCallback [ ] = [ ] ;
7371
7472 /**
75- * Timer that tracks a
73+ * Timer that tracks Transaction idleTimeout
7674 */
77- private _idleTimeoutID : ReturnType < typeof global . setTimeout > | undefined ;
75+ private _idleTimeoutID : ReturnType < typeof setTimeout > | undefined ;
7876
7977 public constructor (
8078 transactionContext : TransactionContext ,
8179 private readonly _idleHub : Hub ,
8280 /**
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.
8483 */
8584 private readonly _idleTimeout : number = DEFAULT_IDLE_TIMEOUT ,
8685 /**
@@ -103,7 +102,7 @@ export class IdleTransaction extends Transaction {
103102 }
104103
105104 this . _startIdleTimeout ( ) ;
106- global . setTimeout ( ( ) => {
105+ setTimeout ( ( ) => {
107106 if ( ! this . _finished ) {
108107 this . setStatus ( 'deadline_exceeded' ) ;
109108 this . finish ( ) ;
@@ -114,7 +113,6 @@ export class IdleTransaction extends Transaction {
114113 /** {@inheritDoc } */
115114 public finish ( endTimestamp : number = timestampWithMs ( ) ) : string | undefined {
116115 this . _finished = true ;
117- this . _cancelIdleTimeout ( ) ;
118116 this . activities = { } ;
119117
120118 if ( this . spanRecorder ) {
@@ -216,7 +214,7 @@ export class IdleTransaction extends Transaction {
216214 */
217215 private _startIdleTimeout ( endTimestamp ?: Parameters < IdleTransaction [ 'finish' ] > [ 0 ] ) : void {
218216 this . _cancelIdleTimeout ( ) ;
219- this . _idleTimeoutID = global . setTimeout ( ( ) => {
217+ this . _idleTimeoutID = setTimeout ( ( ) => {
220218 if ( ! this . _finished && Object . keys ( this . activities ) . length === 0 ) {
221219 this . finish ( endTimestamp ) ;
222220 }
@@ -288,7 +286,7 @@ export class IdleTransaction extends Transaction {
288286 */
289287 private _pingHeartbeat ( ) : void {
290288 IS_DEBUG_BUILD && logger . log ( `pinging Heartbeat -> current counter: ${ this . _heartbeatCounter } ` ) ;
291- global . setTimeout ( ( ) => {
289+ setTimeout ( ( ) => {
292290 this . _beat ( ) ;
293291 } , HEARTBEAT_INTERVAL ) ;
294292 }
@@ -297,14 +295,12 @@ export class IdleTransaction extends Transaction {
297295/**
298296 * Reset transaction on scope to `undefined`
299297 */
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 ) ;
308304 }
309305 }
310306}
0 commit comments