1- import { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils' ;
21import {
3- captureSession ,
42 consoleSandbox ,
53 dedupeIntegration ,
64 functionToStringIntegration ,
@@ -13,7 +11,6 @@ import {
1311 lastEventId ,
1412 logger ,
1513 stackParserFromStackParserOptions ,
16- startSession ,
1714 supportsFetch ,
1815} from '@sentry/core' ;
1916import type { Client , DsnLike , Integration , Options , UserFeedback } from '@sentry/core' ;
@@ -23,19 +20,20 @@ import { DEBUG_BUILD } from './debug-build';
2320import { WINDOW } from './helpers' ;
2421import { breadcrumbsIntegration } from './integrations/breadcrumbs' ;
2522import { browserApiErrorsIntegration } from './integrations/browserapierrors' ;
23+ import { browserSessionIntegration } from './integrations/browsersession' ;
2624import { globalHandlersIntegration } from './integrations/globalhandlers' ;
2725import { httpContextIntegration } from './integrations/httpcontext' ;
2826import { linkedErrorsIntegration } from './integrations/linkederrors' ;
2927import { defaultStackParser } from './stack-parsers' ;
3028import { makeFetchTransport } from './transports/fetch' ;
3129
3230/** Get the default integrations for the browser SDK. */
33- export function getDefaultIntegrations ( _options : Options ) : Integration [ ] {
31+ export function getDefaultIntegrations ( options : Options ) : Integration [ ] {
3432 /**
3533 * Note: Please make sure this stays in sync with Angular SDK, which re-exports
3634 * `getDefaultIntegrations` but with an adjusted set of integrations.
3735 */
38- return [
36+ const integrations = [
3937 inboundFiltersIntegration ( ) ,
4038 functionToStringIntegration ( ) ,
4139 browserApiErrorsIntegration ( ) ,
@@ -45,6 +43,12 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
4543 dedupeIntegration ( ) ,
4644 httpContextIntegration ( ) ,
4745 ] ;
46+
47+ if ( options . autoSessionTracking !== false ) {
48+ integrations . push ( browserSessionIntegration ( ) ) ;
49+ }
50+
51+ return integrations ;
4852}
4953
5054function applyDefaultOptions ( optionsArg : BrowserOptions = { } ) : BrowserOptions {
@@ -187,13 +191,7 @@ export function init(browserOptions: BrowserOptions = {}): Client | undefined {
187191 transport : options . transport || makeFetchTransport ,
188192 } ;
189193
190- const client = initAndBind ( BrowserClient , clientOptions ) ;
191-
192- if ( options . autoSessionTracking ) {
193- startSessionTracking ( ) ;
194- }
195-
196- return client ;
194+ return initAndBind ( BrowserClient , clientOptions ) ;
197195}
198196
199197/**
@@ -308,32 +306,6 @@ export function onLoad(callback: () => void): void {
308306 callback ( ) ;
309307}
310308
311- /**
312- * Enable automatic Session Tracking for the initial page load.
313- */
314- function startSessionTracking ( ) : void {
315- if ( typeof WINDOW . document === 'undefined' ) {
316- DEBUG_BUILD && logger . warn ( 'Session tracking in non-browser environment with @sentry/browser is not supported.' ) ;
317- return ;
318- }
319-
320- // The session duration for browser sessions does not track a meaningful
321- // concept that can be used as a metric.
322- // Automatically captured sessions are akin to page views, and thus we
323- // discard their duration.
324- startSession ( { ignoreDuration : true } ) ;
325- captureSession ( ) ;
326-
327- // We want to create a session for every navigation as well
328- addHistoryInstrumentationHandler ( ( { from, to } ) => {
329- // Don't create an additional session for the initial route or if the location did not change
330- if ( from !== undefined && from !== to ) {
331- startSession ( { ignoreDuration : true } ) ;
332- captureSession ( ) ;
333- }
334- } ) ;
335- }
336-
337309/**
338310 * Captures user feedback and sends it to Sentry.
339311 *
0 commit comments