Skip to content

Commit 5997e04

Browse files
authored
fix(release health): Only create sessions if the correct methods are defined (#3281)
1 parent 478af3a commit 5997e04

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
@@ -189,15 +189,23 @@ function startSessionTracking(): void {
189189

190190
const hub = getCurrentHub();
191191

192-
hub.startSession();
193-
hub.captureSession();
194-
195-
// We want to create a session for every navigation as well
196-
addInstrumentationHandler({
197-
callback: () => {
198-
hub.startSession();
199-
hub.captureSession();
200-
},
201-
type: 'history',
202-
});
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+
});
210+
}
203211
}

0 commit comments

Comments
 (0)