@@ -13,6 +13,17 @@ export const TRACING_DEFAULTS = {
13
13
heartbeatInterval : 5000 ,
14
14
} ;
15
15
16
+ const FINISH_REASON_TAG = 'finishReason' ;
17
+
18
+ const IDLE_TRANSACTION_FINISH_REASONS = [
19
+ 'heartbeatFailed' ,
20
+ 'idleTimeout' ,
21
+ 'documentHidden' ,
22
+ 'finalTimeout' ,
23
+ 'externalFinish' ,
24
+ 'cancelled' ,
25
+ ] ;
26
+
16
27
/**
17
28
* @inheritDoc
18
29
*/
@@ -79,6 +90,8 @@ export class IdleTransaction extends Transaction {
79
90
*/
80
91
private _idleTimeoutID : ReturnType < typeof setTimeout > | undefined ;
81
92
93
+ private _finishReason : typeof IDLE_TRANSACTION_FINISH_REASONS [ number ] = IDLE_TRANSACTION_FINISH_REASONS [ 4 ] ;
94
+
82
95
public constructor (
83
96
transactionContext : TransactionContext ,
84
97
private readonly _idleHub : Hub ,
@@ -111,6 +124,7 @@ export class IdleTransaction extends Transaction {
111
124
setTimeout ( ( ) => {
112
125
if ( ! this . _finished ) {
113
126
this . setStatus ( 'deadline_exceeded' ) ;
127
+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 3 ] ;
114
128
this . finish ( ) ;
115
129
}
116
130
} , this . _finalTimeout ) ;
@@ -121,6 +135,10 @@ export class IdleTransaction extends Transaction {
121
135
this . _finished = true ;
122
136
this . activities = { } ;
123
137
138
+ if ( this . op === 'ui.action.click' ) {
139
+ this . setTag ( FINISH_REASON_TAG , this . _finishReason ) ;
140
+ }
141
+
124
142
if ( this . spanRecorder ) {
125
143
__DEBUG_BUILD__ &&
126
144
logger . log ( '[Tracing] finishing IdleTransaction' , new Date ( endTimestamp * 1000 ) . toISOString ( ) , this . op ) ;
@@ -227,6 +245,7 @@ export class IdleTransaction extends Transaction {
227
245
this . _idleTimeoutCanceledPermanently = restartOnChildSpanChange === false ;
228
246
229
247
if ( Object . keys ( this . activities ) . length === 0 && this . _idleTimeoutCanceledPermanently ) {
248
+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 5 ] ;
230
249
this . finish ( endTimestamp ) ;
231
250
}
232
251
}
@@ -239,6 +258,7 @@ export class IdleTransaction extends Transaction {
239
258
this . cancelIdleTimeout ( ) ;
240
259
this . _idleTimeoutID = setTimeout ( ( ) => {
241
260
if ( ! this . _finished && Object . keys ( this . activities ) . length === 0 ) {
261
+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 1 ] ;
242
262
this . finish ( endTimestamp ) ;
243
263
}
244
264
} , this . _idleTimeout ) ;
@@ -270,6 +290,7 @@ export class IdleTransaction extends Transaction {
270
290
if ( Object . keys ( this . activities ) . length === 0 ) {
271
291
const endTimestamp = timestampWithMs ( ) ;
272
292
if ( this . _idleTimeoutCanceledPermanently ) {
293
+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 5 ] ;
273
294
this . finish ( endTimestamp ) ;
274
295
} else {
275
296
// We need to add the timeout here to have the real endtimestamp of the transaction
@@ -302,6 +323,7 @@ export class IdleTransaction extends Transaction {
302
323
if ( this . _heartbeatCounter >= 3 ) {
303
324
__DEBUG_BUILD__ && logger . log ( '[Tracing] Transaction finished because of no change for 3 heart beats' ) ;
304
325
this . setStatus ( 'deadline_exceeded' ) ;
326
+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 0 ] ;
305
327
this . finish ( ) ;
306
328
} else {
307
329
this . _pingHeartbeat ( ) ;
0 commit comments