@@ -77,6 +77,14 @@ export class IdleTransaction extends Transaction {
7777 */
7878 private _idleTimeoutID : ReturnType < typeof global . setTimeout > | undefined ;
7979
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+
8088 public constructor (
8189 transactionContext : TransactionContext ,
8290 private readonly _idleHub ?: Hub ,
@@ -114,7 +122,7 @@ export class IdleTransaction extends Transaction {
114122 this . _startIdleTimeout ( ) ;
115123 global . setTimeout ( ( ) => {
116124 if ( ! this . _finished ) {
117- this . setTag ( FINISH_REASON_TAG , IDLE_TRANSACTION_FINISH_REASONS [ 3 ] ) ;
125+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 3 ] ; /* 'finalTimeout' */
118126 this . finish ( ) ;
119127 }
120128 } , this . _finalTimeout ) ;
@@ -125,6 +133,8 @@ export class IdleTransaction extends Transaction {
125133 this . _finished = true ;
126134 this . activities = { } ;
127135
136+ this . setTag ( FINISH_REASON_TAG , this . _finishReason ) ;
137+
128138 if ( this . spanRecorder ) {
129139 logger . log ( '[Tracing] finishing IdleTransaction' , new Date ( endTimestamp * 1000 ) . toISOString ( ) , this . op ) ;
130140
@@ -207,7 +217,7 @@ export class IdleTransaction extends Transaction {
207217 }
208218
209219 /**
210- * Creates an idletimeout
220+ * Cancels the existing idletimeout, if there is one
211221 */
212222 private _cancelIdleTimeout ( ) : void {
213223 if ( this . _idleTimeoutID ) {
@@ -219,12 +229,12 @@ export class IdleTransaction extends Transaction {
219229 /**
220230 * Creates an idletimeout
221231 */
222- private _startIdleTimeout ( end ?: Parameters < IdleTransaction [ 'finish' ] > [ 0 ] ) : void {
232+ private _startIdleTimeout ( endTimestamp ?: Parameters < IdleTransaction [ 'finish' ] > [ 0 ] ) : void {
223233 this . _cancelIdleTimeout ( ) ;
224234 this . _idleTimeoutID = global . setTimeout ( ( ) => {
225235 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 ) ;
228238 }
229239 } , this . _idleTimeout ) ;
230240 }
@@ -256,8 +266,8 @@ export class IdleTransaction extends Transaction {
256266 const timeout = this . _idleTimeout ;
257267 // We need to add the timeout here to have the real endtimestamp of the transaction
258268 // 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 ) ;
261271 }
262272 }
263273
@@ -284,7 +294,7 @@ export class IdleTransaction extends Transaction {
284294 if ( this . _heartbeatCounter >= 3 ) {
285295 logger . log ( `[Tracing] Transaction finished because of no change for 3 heart beats` ) ;
286296 this . setStatus ( 'deadline_exceeded' ) ;
287- this . setTag ( FINISH_REASON_TAG , IDLE_TRANSACTION_FINISH_REASONS [ 0 ] ) ;
297+ this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 0 ] ; /* 'heartbeatFailed' */
288298 this . finish ( ) ;
289299 } else {
290300 this . _pingHeartbeat ( ) ;
0 commit comments