@@ -13,7 +13,7 @@ import {
13
13
spanToJSON ,
14
14
uuid4 ,
15
15
} from '@sentry/core' ;
16
- import type { NodeClient } from '@sentry/node' ;
16
+ import type { NodeClient , NodeOptions } from '@sentry/node' ;
17
17
import { DEBUG_BUILD } from './debug-build' ;
18
18
import { NODE_MAJOR , NODE_VERSION } from './nodeVersion' ;
19
19
import { MAX_PROFILE_DURATION_MS , maybeProfileSpan , stopSpanProfile } from './spanProfileUtils' ;
@@ -445,34 +445,51 @@ export const _nodeProfilingIntegration = ((): ProfilingIntegration<NodeClient> =
445
445
DEBUG_BUILD && logger . log ( '[Profiling] Profiling integration setup.' ) ;
446
446
const options = client . getOptions ( ) ;
447
447
448
- const mode =
449
- ( options . profilesSampleRate === undefined ||
450
- options . profilesSampleRate === null ||
451
- options . profilesSampleRate === 0 ) &&
452
- ! options . profilesSampler
453
- ? 'continuous'
454
- : 'span' ;
455
- switch ( mode ) {
456
- case 'continuous' : {
457
- DEBUG_BUILD && logger . log ( '[Profiling] Continuous profiler mode enabled.' ) ;
458
- this . _profiler . initialize ( client ) ;
459
- break ;
460
- }
461
- // Default to span profiling when no mode profiler mode is set
462
- case 'span' :
463
- case undefined : {
464
- DEBUG_BUILD && logger . log ( '[Profiling] Span profiler mode enabled.' ) ;
465
- setupAutomatedSpanProfiling ( client ) ;
466
- break ;
467
- }
468
- default : {
469
- DEBUG_BUILD && logger . warn ( `[Profiling] Unknown profiler mode: ${ mode } , profiler was not initialized` ) ;
448
+ const profilingAPIVersion = getProfilingMode ( options ) ;
449
+
450
+ if ( profilingAPIVersion === 'legacy' ) {
451
+ const mode =
452
+ ( options . profilesSampleRate === undefined ||
453
+ options . profilesSampleRate === null ||
454
+ options . profilesSampleRate === 0 ) &&
455
+ ! options . profilesSampler
456
+ ? 'continuous'
457
+ : 'span' ;
458
+ switch ( mode ) {
459
+ case 'continuous' : {
460
+ DEBUG_BUILD && logger . log ( '[Profiling] Continuous profiler mode enabled.' ) ;
461
+ this . _profiler . initialize ( client ) ;
462
+ break ;
463
+ }
464
+ // Default to span profiling when no mode profiler mode is set
465
+ case 'span' :
466
+ case undefined : {
467
+ DEBUG_BUILD && logger . log ( '[Profiling] Span profiler mode enabled.' ) ;
468
+ setupAutomatedSpanProfiling ( client ) ;
469
+ break ;
470
+ }
471
+ default : {
472
+ DEBUG_BUILD && logger . warn ( `[Profiling] Unknown profiler mode: ${ mode } , profiler was not initialized` ) ;
473
+ }
470
474
}
471
475
}
472
476
} ,
473
477
} ;
474
478
} ) satisfies IntegrationFn ;
475
479
480
+ /**
481
+ * Determines the profiling mode based on the options.
482
+ * @param options
483
+ * @returns 'legacy' if the options are using the legacy profiling API, 'current' if the options are using the current profiling API
484
+ */
485
+ function getProfilingMode ( options : NodeOptions ) : 'legacy' | 'current' {
486
+ if ( 'profilesSampleRate' in options || 'profilesSampler' in options ) {
487
+ return 'legacy' ;
488
+ }
489
+
490
+ return 'current' ;
491
+ }
492
+
476
493
/**
477
494
* We need this integration in order to send data to Sentry. We hook into the event processor
478
495
* and inspect each event to see if it is a transaction event and if that transaction event
0 commit comments