44 dropUndefinedKeys ,
55 endSession ,
66 functionToStringIntegration ,
7- getClient ,
87 getCurrentScope ,
98 getIntegrationsToSetup ,
109 getIsolationScope ,
@@ -14,8 +13,8 @@ import {
1413 logger ,
1514 propagationContextFromHeaders ,
1615 requestDataIntegration ,
16+ serverRequestSessionIntegration ,
1717 stackParserFromStackParserOptions ,
18- startSession ,
1918} from '@sentry/core' ;
2019import {
2120 enhanceDscWithOpenTelemetryRootSpanName ,
@@ -76,14 +75,21 @@ export function getDefaultIntegrationsWithoutPerformance(): Integration[] {
7675
7776/** Get the default integrations for the Node SDK. */
7877export function getDefaultIntegrations ( options : Options ) : Integration [ ] {
79- return [
78+ const integrations = [
8079 ...getDefaultIntegrationsWithoutPerformance ( ) ,
8180 // We only add performance integrations if tracing is enabled
8281 // Note that this means that without tracing enabled, e.g. `expressIntegration()` will not be added
8382 // This means that generally request isolation will work (because that is done by httpIntegration)
8483 // But `transactionName` will not be set automatically
8584 ...( shouldAddPerformanceIntegrations ( options ) ? getAutoPerformanceIntegrations ( ) : [ ] ) ,
8685 ] ;
86+
87+ // TODO(v9): Make this a default default integration
88+ if ( options . autoSessionTracking ) {
89+ integrations . push ( serverRequestSessionIntegration ( ) ) ;
90+ }
91+
92+ return integrations ;
8793}
8894
8995function shouldAddPerformanceIntegrations ( options : Options ) : boolean {
@@ -156,8 +162,9 @@ function _init(
156162
157163 logger . log ( `Running in ${ isCjs ( ) ? 'CommonJS' : 'ESM' } mode.` ) ;
158164
165+ // TODO(V9): Unconditionally call startSessionTracking
159166 if ( options . autoSessionTracking ) {
160- startSessionTracking ( ) ;
167+ startSessionTracking ( client ) ;
161168 }
162169
163170 client . startClientReportTracking ( ) ;
@@ -308,17 +315,11 @@ function updateScopeFromEnvVariables(): void {
308315 getCurrentScope ( ) . setPropagationContext ( propagationContext ) ;
309316 }
310317}
311-
312318/**
313319 * Enable automatic Session Tracking for the node process.
314320 */
315- function startSessionTracking ( ) : void {
316- const client = getClient < NodeClient > ( ) ;
317- if ( client && client . getOptions ( ) . autoSessionTracking ) {
318- client . initSessionFlusher ( ) ;
319- }
320-
321- startSession ( ) ;
321+ function startSessionTracking ( client : NodeClient ) : void {
322+ client . initSessionFlusher ( ) ;
322323
323324 // Emitted in the case of healthy sessions, error of `mechanism.handled: true` and unhandledrejections because
324325 // The 'beforeExit' event is not emitted for conditions causing explicit termination,
0 commit comments