Skip to content

Commit

Permalink
fix(release health): Only create sessions if the correct methods are …
Browse files Browse the repository at this point in the history
…defined (#3281)
  • Loading branch information
lobsterkatie committed Mar 5, 2021
1 parent 478af3a commit 5997e04
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,23 @@ function startSessionTracking(): void {

const hub = getCurrentHub();

hub.startSession();
hub.captureSession();

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

hub.startSession();
hub.captureSession();

// We want to create a session for every navigation as well
addInstrumentationHandler({
callback: () => {
hub.startSession();
hub.captureSession();
},
type: 'history',
});
}
}

0 comments on commit 5997e04

Please sign in to comment.