@@ -13,6 +13,17 @@ export const TRACING_DEFAULTS = {
1313 heartbeatInterval : 5000 ,
1414} ;
1515
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+
1627/**
1728 * @inheritDoc
1829 */
@@ -79,6 +90,8 @@ export class IdleTransaction extends Transaction {
7990 */
8091 private _idleTimeoutID : ReturnType < typeof setTimeout > | undefined ;
8192
93+ private _finishReason : typeof IDLE_TRANSACTION_FINISH_REASONS [ number ] = IDLE_TRANSACTION_FINISH_REASONS [ 4 ] ;
94+
8295 public constructor (
8396 transactionContext : TransactionContext ,
8497 private readonly _idleHub : Hub ,
@@ -111,6 +124,7 @@ export class IdleTransaction extends Transaction {
111124 setTimeout ( ( ) => {
112125 if ( ! this . _finished ) {
113126 this . setStatus ( 'deadline_exceeded' ) ;
127+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 3 ] ;
114128 this . finish ( ) ;
115129 }
116130 } , this . _finalTimeout ) ;
@@ -121,6 +135,10 @@ export class IdleTransaction extends Transaction {
121135 this . _finished = true ;
122136 this . activities = { } ;
123137
138+ if ( this . op === 'ui.action.click' ) {
139+ this . setTag ( FINISH_REASON_TAG , this . _finishReason ) ;
140+ }
141+
124142 if ( this . spanRecorder ) {
125143 __DEBUG_BUILD__ &&
126144 logger . log ( '[Tracing] finishing IdleTransaction' , new Date ( endTimestamp * 1000 ) . toISOString ( ) , this . op ) ;
@@ -227,6 +245,7 @@ export class IdleTransaction extends Transaction {
227245 this . _idleTimeoutCanceledPermanently = restartOnChildSpanChange === false ;
228246
229247 if ( Object . keys ( this . activities ) . length === 0 && this . _idleTimeoutCanceledPermanently ) {
248+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 5 ] ;
230249 this . finish ( endTimestamp ) ;
231250 }
232251 }
@@ -239,6 +258,7 @@ export class IdleTransaction extends Transaction {
239258 this . cancelIdleTimeout ( ) ;
240259 this . _idleTimeoutID = setTimeout ( ( ) => {
241260 if ( ! this . _finished && Object . keys ( this . activities ) . length === 0 ) {
261+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 1 ] ;
242262 this . finish ( endTimestamp ) ;
243263 }
244264 } , this . _idleTimeout ) ;
@@ -270,6 +290,7 @@ export class IdleTransaction extends Transaction {
270290 if ( Object . keys ( this . activities ) . length === 0 ) {
271291 const endTimestamp = timestampWithMs ( ) ;
272292 if ( this . _idleTimeoutCanceledPermanently ) {
293+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 5 ] ;
273294 this . finish ( endTimestamp ) ;
274295 } else {
275296 // We need to add the timeout here to have the real endtimestamp of the transaction
@@ -302,6 +323,7 @@ export class IdleTransaction extends Transaction {
302323 if ( this . _heartbeatCounter >= 3 ) {
303324 __DEBUG_BUILD__ && logger . log ( '[Tracing] Transaction finished because of no change for 3 heart beats' ) ;
304325 this . setStatus ( 'deadline_exceeded' ) ;
326+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 0 ] ;
305327 this . finish ( ) ;
306328 } else {
307329 this . _pingHeartbeat ( ) ;
0 commit comments