-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(browser): Add
browserSessionIntegration
(#14551)
- Loading branch information
Showing
10 changed files
with
77 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils'; | ||
import { captureSession, defineIntegration, logger, startSession } from '@sentry/core'; | ||
import { DEBUG_BUILD } from '../debug-build'; | ||
import { WINDOW } from '../helpers'; | ||
|
||
/** | ||
* When added, automatically creates sessions which allow you to track adoption and crashes (crash free rate) in your Releases in Sentry. | ||
* More information: https://docs.sentry.io/product/releases/health/ | ||
* | ||
* Note: In order for session tracking to work, you need to set up Releases: https://docs.sentry.io/product/releases/ | ||
*/ | ||
export const browserSessionIntegration = defineIntegration(() => { | ||
return { | ||
name: 'BrowserSession', | ||
setupOnce() { | ||
if (typeof WINDOW.document === 'undefined') { | ||
DEBUG_BUILD && | ||
logger.warn('Using the `browserSessionIntegration` in non-browser environments is not supported.'); | ||
return; | ||
} | ||
|
||
// The session duration for browser sessions does not track a meaningful | ||
// concept that can be used as a metric. | ||
// Automatically captured sessions are akin to page views, and thus we | ||
// discard their duration. | ||
startSession({ ignoreDuration: true }); | ||
captureSession(); | ||
|
||
// We want to create a session for every navigation as well | ||
addHistoryInstrumentationHandler(({ from, to }) => { | ||
// Don't create an additional session for the initial route or if the location did not change | ||
if (from !== undefined && from !== to) { | ||
startSession({ ignoreDuration: true }); | ||
captureSession(); | ||
} | ||
}); | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters