@@ -13,7 +13,7 @@ import {
1313 spanToJSON ,
1414 uuid4 ,
1515} from '@sentry/core' ;
16- import type { NodeClient } from '@sentry/node' ;
16+ import type { NodeClient , NodeOptions } from '@sentry/node' ;
1717import { DEBUG_BUILD } from './debug-build' ;
1818import { NODE_MAJOR , NODE_VERSION } from './nodeVersion' ;
1919import { MAX_PROFILE_DURATION_MS , maybeProfileSpan , stopSpanProfile } from './spanProfileUtils' ;
@@ -445,34 +445,51 @@ export const _nodeProfilingIntegration = ((): ProfilingIntegration<NodeClient> =
445445 DEBUG_BUILD && logger . log ( '[Profiling] Profiling integration setup.' ) ;
446446 const options = client . getOptions ( ) ;
447447
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+ }
470474 }
471475 }
472476 } ,
473477 } ;
474478} ) satisfies IntegrationFn ;
475479
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+
476493/**
477494 * We need this integration in order to send data to Sentry. We hook into the event processor
478495 * and inspect each event to see if it is a transaction event and if that transaction event
0 commit comments