@@ -77,6 +77,14 @@ export class IdleTransaction extends Transaction {
77
77
*/
78
78
private _idleTimeoutID : ReturnType < typeof global . setTimeout > | undefined ;
79
79
80
+ /**
81
+ *
82
+ * Defaults to `externalFinish`, which means transaction.finish() was called outside of the idle transaction (for example,
83
+ * by a navigation transaction ending the previous pageload/navigation in some routing instrumentation).
84
+ * @default 'externalFinish'
85
+ */
86
+ private _finishReason : typeof IDLE_TRANSACTION_FINISH_REASONS [ number ] = IDLE_TRANSACTION_FINISH_REASONS [ 4 ] ;
87
+
80
88
public constructor (
81
89
transactionContext : TransactionContext ,
82
90
private readonly _idleHub ?: Hub ,
@@ -114,7 +122,7 @@ export class IdleTransaction extends Transaction {
114
122
this . _startIdleTimeout ( ) ;
115
123
global . setTimeout ( ( ) => {
116
124
if ( ! this . _finished ) {
117
- this . setTag ( FINISH_REASON_TAG , IDLE_TRANSACTION_FINISH_REASONS [ 3 ] ) ;
125
+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 3 ] ; /* 'finalTimeout' */
118
126
this . finish ( ) ;
119
127
}
120
128
} , this . _finalTimeout ) ;
@@ -125,6 +133,8 @@ export class IdleTransaction extends Transaction {
125
133
this . _finished = true ;
126
134
this . activities = { } ;
127
135
136
+ this . setTag ( FINISH_REASON_TAG , this . _finishReason ) ;
137
+
128
138
if ( this . spanRecorder ) {
129
139
logger . log ( '[Tracing] finishing IdleTransaction' , new Date ( endTimestamp * 1000 ) . toISOString ( ) , this . op ) ;
130
140
@@ -207,7 +217,7 @@ export class IdleTransaction extends Transaction {
207
217
}
208
218
209
219
/**
210
- * Creates an idletimeout
220
+ * Cancels the existing idletimeout, if there is one
211
221
*/
212
222
private _cancelIdleTimeout ( ) : void {
213
223
if ( this . _idleTimeoutID ) {
@@ -219,12 +229,12 @@ export class IdleTransaction extends Transaction {
219
229
/**
220
230
* Creates an idletimeout
221
231
*/
222
- private _startIdleTimeout ( end ?: Parameters < IdleTransaction [ 'finish' ] > [ 0 ] ) : void {
232
+ private _startIdleTimeout ( endTimestamp ?: Parameters < IdleTransaction [ 'finish' ] > [ 0 ] ) : void {
223
233
this . _cancelIdleTimeout ( ) ;
224
234
this . _idleTimeoutID = global . setTimeout ( ( ) => {
225
235
if ( ! this . _finished && Object . keys ( this . activities ) . length === 0 ) {
226
- this . setTag ( FINISH_REASON_TAG , IDLE_TRANSACTION_FINISH_REASONS [ 1 ] ) ;
227
- this . finish ( end ) ;
236
+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 1 ] ; /* 'idleTimeout' */
237
+ this . finish ( endTimestamp ) ;
228
238
}
229
239
} , this . _idleTimeout ) ;
230
240
}
@@ -256,8 +266,8 @@ export class IdleTransaction extends Transaction {
256
266
const timeout = this . _idleTimeout ;
257
267
// We need to add the timeout here to have the real endtimestamp of the transaction
258
268
// Remember timestampWithMs is in seconds, timeout is in ms
259
- const end = timestampWithMs ( ) + timeout / 1000 ;
260
- this . _startIdleTimeout ( end ) ;
269
+ const endTimestamp = timestampWithMs ( ) + timeout / 1000 ;
270
+ this . _startIdleTimeout ( endTimestamp ) ;
261
271
}
262
272
}
263
273
@@ -284,7 +294,7 @@ export class IdleTransaction extends Transaction {
284
294
if ( this . _heartbeatCounter >= 3 ) {
285
295
logger . log ( `[Tracing] Transaction finished because of no change for 3 heart beats` ) ;
286
296
this . setStatus ( 'deadline_exceeded' ) ;
287
- this . setTag ( FINISH_REASON_TAG , IDLE_TRANSACTION_FINISH_REASONS [ 0 ] ) ;
297
+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 0 ] ; /* 'heartbeatFailed' */
288
298
this . finish ( ) ;
289
299
} else {
290
300
this . _pingHeartbeat ( ) ;
0 commit comments