Skip to content

Commit 805b3c5

Browse files
committed
only create sessions if startSession is defined
1 parent d7798eb commit 805b3c5

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

packages/browser/src/sdk.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,23 @@ function startSessionTracking(): void {
201201

202202
const hub = getCurrentHub();
203203

204-
hub.startSession();
205-
hub.captureSession();
206-
207-
// We want to create a session for every navigation as well
208-
addInstrumentationHandler({
209-
callback: () => {
210-
hub.startSession();
211-
hub.captureSession();
212-
},
213-
type: 'history',
214-
});
204+
if ('startSession' in hub) {
205+
// The only way for this to be false is for there to be a version mismatch between @sentry/browser (>= 6.0.0) and
206+
// @sentry/hub (< 5.27.0). In the simple case, there won't ever be such a mismatch, because the two packages are
207+
// pinned at the same version in package.json, but there are edge cases where it's possible'. See
208+
// https://github.com/getsentry/sentry-javascript/issues/3234 and
209+
// https://github.com/getsentry/sentry-javascript/issues/3207.
210+
211+
hub.startSession();
212+
hub.captureSession();
213+
214+
// We want to create a session for every navigation as well
215+
addInstrumentationHandler({
216+
callback: () => {
217+
hub.startSession();
218+
hub.captureSession();
219+
},
220+
type: 'history',
221+
});
222+
}
215223
}

0 commit comments

Comments
 (0)