Skip to content

Commit 682ac0b

Browse files
authored
feat: Create session on navigation (#3179)
* feat: Create session on navigation
1 parent 06d6bd8 commit 682ac0b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/browser/src/sdk.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations, SDK_VERSION } from '@sentry/core';
2-
import { getGlobalObject, SyncPromise } from '@sentry/utils';
2+
import { addInstrumentationHandler, getGlobalObject, SyncPromise } from '@sentry/utils';
33

44
import { BrowserOptions } from './backend';
55
import { BrowserClient } from './client';
@@ -249,4 +249,19 @@ function startSessionTracking(): void {
249249
fcpResolved = true;
250250
possiblyEndSession();
251251
}
252+
253+
// We want to create a session for every navigation as well
254+
addInstrumentationHandler({
255+
callback: () => {
256+
if (
257+
!getCurrentHub()
258+
.getScope()
259+
?.getSession()
260+
) {
261+
hub.startSession();
262+
hub.endSession();
263+
}
264+
},
265+
type: 'history',
266+
});
252267
}

0 commit comments

Comments
 (0)