1
- import { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils' ;
2
1
import {
3
- captureSession ,
4
2
consoleSandbox ,
5
3
dedupeIntegration ,
6
4
functionToStringIntegration ,
@@ -13,7 +11,6 @@ import {
13
11
lastEventId ,
14
12
logger ,
15
13
stackParserFromStackParserOptions ,
16
- startSession ,
17
14
supportsFetch ,
18
15
} from '@sentry/core' ;
19
16
import type { Client , DsnLike , Integration , Options , UserFeedback } from '@sentry/core' ;
@@ -23,19 +20,20 @@ import { DEBUG_BUILD } from './debug-build';
23
20
import { WINDOW } from './helpers' ;
24
21
import { breadcrumbsIntegration } from './integrations/breadcrumbs' ;
25
22
import { browserApiErrorsIntegration } from './integrations/browserapierrors' ;
23
+ import { browserSessionIntegration } from './integrations/browsersession' ;
26
24
import { globalHandlersIntegration } from './integrations/globalhandlers' ;
27
25
import { httpContextIntegration } from './integrations/httpcontext' ;
28
26
import { linkedErrorsIntegration } from './integrations/linkederrors' ;
29
27
import { defaultStackParser } from './stack-parsers' ;
30
28
import { makeFetchTransport } from './transports/fetch' ;
31
29
32
30
/** Get the default integrations for the browser SDK. */
33
- export function getDefaultIntegrations ( _options : Options ) : Integration [ ] {
31
+ export function getDefaultIntegrations ( options : Options ) : Integration [ ] {
34
32
/**
35
33
* Note: Please make sure this stays in sync with Angular SDK, which re-exports
36
34
* `getDefaultIntegrations` but with an adjusted set of integrations.
37
35
*/
38
- return [
36
+ const integrations = [
39
37
inboundFiltersIntegration ( ) ,
40
38
functionToStringIntegration ( ) ,
41
39
browserApiErrorsIntegration ( ) ,
@@ -45,6 +43,12 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
45
43
dedupeIntegration ( ) ,
46
44
httpContextIntegration ( ) ,
47
45
] ;
46
+
47
+ if ( options . autoSessionTracking !== false ) {
48
+ integrations . push ( browserSessionIntegration ( ) ) ;
49
+ }
50
+
51
+ return integrations ;
48
52
}
49
53
50
54
function applyDefaultOptions ( optionsArg : BrowserOptions = { } ) : BrowserOptions {
@@ -187,13 +191,7 @@ export function init(browserOptions: BrowserOptions = {}): Client | undefined {
187
191
transport : options . transport || makeFetchTransport ,
188
192
} ;
189
193
190
- const client = initAndBind ( BrowserClient , clientOptions ) ;
191
-
192
- if ( options . autoSessionTracking ) {
193
- startSessionTracking ( ) ;
194
- }
195
-
196
- return client ;
194
+ return initAndBind ( BrowserClient , clientOptions ) ;
197
195
}
198
196
199
197
/**
@@ -308,32 +306,6 @@ export function onLoad(callback: () => void): void {
308
306
callback ( ) ;
309
307
}
310
308
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
-
337
309
/**
338
310
* Captures user feedback and sends it to Sentry.
339
311
*
0 commit comments