Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/core/src/tracing/idletransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -79,6 +90,8 @@ export class IdleTransaction extends Transaction {
*/
private _idleTimeoutID: ReturnType<typeof setTimeout> | undefined;

private _finishReason: typeof IDLE_TRANSACTION_FINISH_REASONS[number] = IDLE_TRANSACTION_FINISH_REASONS[4];

public constructor(
transactionContext: TransactionContext,
private readonly _idleHub: Hub,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down