Skip to content

Commit 7f87dd2

Browse files
authored
ref: Add captureSession guard for startSessionTracking method (#3429)
* ref: Add captureSession guard for startSessionTracking method
1 parent c91b32c commit 7f87dd2

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

packages/browser/src/sdk.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,25 @@ function startSessionTracking(): void {
189189

190190
const hub = getCurrentHub();
191191

192-
if ('startSession' in hub) {
193-
// The only way for this to be false is for there to be a version mismatch between @sentry/browser (>= 6.0.0) and
194-
// @sentry/hub (< 5.27.0). In the simple case, there won't ever be such a mismatch, because the two packages are
195-
// pinned at the same version in package.json, but there are edge cases where it's possible'. See
196-
// https://github.com/getsentry/sentry-javascript/issues/3234 and
197-
// https://github.com/getsentry/sentry-javascript/issues/3207.
198-
199-
hub.startSession();
200-
hub.captureSession();
201-
202-
// We want to create a session for every navigation as well
203-
addInstrumentationHandler({
204-
callback: () => {
205-
hub.startSession();
206-
hub.captureSession();
207-
},
208-
type: 'history',
209-
});
192+
// The only way for this to be false is for there to be a version mismatch between @sentry/browser (>= 6.0.0) and
193+
// @sentry/hub (< 5.27.0). In the simple case, there won't ever be such a mismatch, because the two packages are
194+
// pinned at the same version in package.json, but there are edge cases where it's possible. See
195+
// https://github.com/getsentry/sentry-javascript/issues/3207 and
196+
// https://github.com/getsentry/sentry-javascript/issues/3234 and
197+
// https://github.com/getsentry/sentry-javascript/issues/3278.
198+
if (typeof hub.startSession !== 'function' || typeof hub.captureSession !== 'function') {
199+
return;
210200
}
201+
202+
hub.startSession();
203+
hub.captureSession();
204+
205+
// We want to create a session for every navigation as well
206+
addInstrumentationHandler({
207+
callback: () => {
208+
hub.startSession();
209+
hub.captureSession();
210+
},
211+
type: 'history',
212+
});
211213
}

0 commit comments

Comments
 (0)