diff --git a/packages/core/src/tracing/idletransaction.ts b/packages/core/src/tracing/idletransaction.ts index 49c7b64ea4a0..48fd2e50356e 100644 --- a/packages/core/src/tracing/idletransaction.ts +++ b/packages/core/src/tracing/idletransaction.ts @@ -13,6 +13,17 @@ export const TRACING_DEFAULTS = { heartbeatInterval: 5000, }; +const FINISH_REASON_TAG = 'finishReason'; + +const IDLE_TRANSACTION_FINISH_REASONS = [ + 'heartbeatFailed', + 'idleTimeout', + 'documentHidden', + 'finalTimeout', + 'externalFinish', + 'cancelled', +]; + /** * @inheritDoc */ @@ -79,6 +90,8 @@ export class IdleTransaction extends Transaction { */ private _idleTimeoutID: ReturnType | undefined; + private _finishReason: typeof IDLE_TRANSACTION_FINISH_REASONS[number] = IDLE_TRANSACTION_FINISH_REASONS[4]; + public constructor( transactionContext: TransactionContext, private readonly _idleHub: Hub, @@ -111,6 +124,7 @@ export class IdleTransaction extends Transaction { setTimeout(() => { if (!this._finished) { this.setStatus('deadline_exceeded'); + this._finishReason = IDLE_TRANSACTION_FINISH_REASONS[3]; this.finish(); } }, this._finalTimeout); @@ -121,6 +135,10 @@ export class IdleTransaction extends Transaction { this._finished = true; this.activities = {}; + if (this.op === 'ui.action.click') { + this.setTag(FINISH_REASON_TAG, this._finishReason); + } + if (this.spanRecorder) { __DEBUG_BUILD__ && logger.log('[Tracing] finishing IdleTransaction', new Date(endTimestamp * 1000).toISOString(), this.op); @@ -227,6 +245,7 @@ export class IdleTransaction extends Transaction { this._idleTimeoutCanceledPermanently = restartOnChildSpanChange === false; if (Object.keys(this.activities).length === 0 && this._idleTimeoutCanceledPermanently) { + this._finishReason = IDLE_TRANSACTION_FINISH_REASONS[5]; this.finish(endTimestamp); } } @@ -239,6 +258,7 @@ export class IdleTransaction extends Transaction { this.cancelIdleTimeout(); this._idleTimeoutID = setTimeout(() => { if (!this._finished && Object.keys(this.activities).length === 0) { + this._finishReason = IDLE_TRANSACTION_FINISH_REASONS[1]; this.finish(endTimestamp); } }, this._idleTimeout); @@ -270,6 +290,7 @@ export class IdleTransaction extends Transaction { if (Object.keys(this.activities).length === 0) { const endTimestamp = timestampWithMs(); if (this._idleTimeoutCanceledPermanently) { + this._finishReason = IDLE_TRANSACTION_FINISH_REASONS[5]; this.finish(endTimestamp); } else { // We need to add the timeout here to have the real endtimestamp of the transaction @@ -302,6 +323,7 @@ export class IdleTransaction extends Transaction { if (this._heartbeatCounter >= 3) { __DEBUG_BUILD__ && logger.log('[Tracing] Transaction finished because of no change for 3 heart beats'); this.setStatus('deadline_exceeded'); + this._finishReason = IDLE_TRANSACTION_FINISH_REASONS[0]; this.finish(); } else { this._pingHeartbeat();