From 041a71e9f4bdaa7556e6b8722b212efb59268322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Thu, 27 May 2021 17:45:50 +0200 Subject: [PATCH 1/3] fix: Normalize session duration rounding; Dont trigger session on initial navigation --- packages/browser/src/sdk.ts | 6 +++++- packages/hub/src/session.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index 82bcdc161d66..b6ab661f4859 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -204,7 +204,11 @@ function startSessionTracking(): void { // We want to create a session for every navigation as well addInstrumentationHandler({ - callback: () => { + callback: ({ from, to }) => { + // Don't create additional session for the initial route or when the location did not change + if (from === undefined || from === to) { + return; + } hub.startSession(); hub.captureSession(); }, diff --git a/packages/hub/src/session.ts b/packages/hub/src/session.ts index 49f3d168e187..36d9871deb68 100644 --- a/packages/hub/src/session.ts +++ b/packages/hub/src/session.ts @@ -66,7 +66,11 @@ export class Session implements SessionInterface { if (typeof context.duration === 'number') { this.duration = context.duration; } else { - this.duration = this.timestamp - this.started; + // Otherwise: + // hub.startSession(); + // hub.captureSession(); + // can produce either 0 or 1, depending on the mood + this.duration = Math.floor(this.timestamp - this.started); } if (context.release) { this.release = context.release; From ce3faabf72202e60e99ca51437cb3bd9b09f3e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Thu, 27 May 2021 18:41:40 +0200 Subject: [PATCH 2/3] Update packages/browser/src/sdk.ts Co-authored-by: Abhijeet Prasad --- packages/browser/src/sdk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index b6ab661f4859..444e06ecbe90 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -205,7 +205,7 @@ function startSessionTracking(): void { // We want to create a session for every navigation as well addInstrumentationHandler({ callback: ({ from, to }) => { - // Don't create additional session for the initial route or when the location did not change + // Don't create an additional session for the initial route or if the location did not change if (from === undefined || from === to) { return; } From 91c76557e21d779108906d5d56dedaee32531d7a Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Fri, 28 May 2021 16:25:49 +0200 Subject: [PATCH 3/3] Revert changes to packages/hub/src/session.ts We'll fix the reporting of session durations separately later. --- packages/hub/src/session.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/hub/src/session.ts b/packages/hub/src/session.ts index 36d9871deb68..49f3d168e187 100644 --- a/packages/hub/src/session.ts +++ b/packages/hub/src/session.ts @@ -66,11 +66,7 @@ export class Session implements SessionInterface { if (typeof context.duration === 'number') { this.duration = context.duration; } else { - // Otherwise: - // hub.startSession(); - // hub.captureSession(); - // can produce either 0 or 1, depending on the mood - this.duration = Math.floor(this.timestamp - this.started); + this.duration = this.timestamp - this.started; } if (context.release) { this.release = context.release;