@@ -2,10 +2,11 @@ import * as Sentry from '@sentry/node';
22
33import { getMainCarrier } from '@sentry/core' ;
44import type { NodeClientOptions } from '@sentry/node/build/types/types' ;
5+ import type { ProfilingIntegration } from '@sentry/types' ;
56import type { ProfileChunk , Transport } from '@sentry/types' ;
67import { GLOBAL_OBJ , createEnvelope , logger } from '@sentry/utils' ;
78import { CpuProfilerBindings } from '../src/cpu_profiler' ;
8- import { type ProfilingIntegration , _nodeProfilingIntegration } from '../src/integration' ;
9+ import { _nodeProfilingIntegration } from '../src/integration' ;
910
1011function makeClientWithHooks ( ) : [ Sentry . NodeClient , Transport ] {
1112 const integration = _nodeProfilingIntegration ( ) ;
@@ -299,7 +300,7 @@ describe('automated span instrumentation', () => {
299300 Sentry . setCurrentClient ( client ) ;
300301 client . init ( ) ;
301302
302- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
303+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
303304 if ( ! integration ) {
304305 throw new Error ( 'Profiling integration not found' ) ;
305306 }
@@ -390,7 +391,7 @@ describe('continuous profiling', () => {
390391 } ) ;
391392 afterEach ( ( ) => {
392393 const client = Sentry . getClient ( ) ;
393- const integration = client ?. getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
394+ const integration = client ?. getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
394395
395396 if ( integration ) {
396397 integration . _profiler . stop ( ) ;
@@ -432,7 +433,7 @@ describe('continuous profiling', () => {
432433
433434 const transportSpy = jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
434435
435- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
436+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
436437 if ( ! integration ) {
437438 throw new Error ( 'Profiling integration not found' ) ;
438439 }
@@ -446,7 +447,7 @@ describe('continuous profiling', () => {
446447 expect ( profile . client_sdk . version ) . toEqual ( expect . stringMatching ( / \d + \. \d + \. \d + / ) ) ;
447448 } ) ;
448449
449- it ( 'initializes the continuous profiler and binds the sentry client ' , ( ) => {
450+ it ( 'initializes the continuous profiler' , ( ) => {
450451 const startProfilingSpy = jest . spyOn ( CpuProfilerBindings , 'startProfiling' ) ;
451452
452453 const [ client ] = makeContinuousProfilingClient ( ) ;
@@ -455,14 +456,13 @@ describe('continuous profiling', () => {
455456
456457 expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
457458
458- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
459+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
459460 if ( ! integration ) {
460461 throw new Error ( 'Profiling integration not found' ) ;
461462 }
462463 integration . _profiler . start ( ) ;
463464
464465 expect ( integration . _profiler ) . toBeDefined ( ) ;
465- expect ( integration . _profiler [ '_client' ] ) . toBe ( client ) ;
466466 } ) ;
467467
468468 it ( 'starts a continuous profile' , ( ) => {
@@ -473,7 +473,7 @@ describe('continuous profiling', () => {
473473 client . init ( ) ;
474474
475475 expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
476- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
476+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
477477 if ( ! integration ) {
478478 throw new Error ( 'Profiling integration not found' ) ;
479479 }
@@ -490,7 +490,7 @@ describe('continuous profiling', () => {
490490 client . init ( ) ;
491491
492492 expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
493- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
493+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
494494 if ( ! integration ) {
495495 throw new Error ( 'Profiling integration not found' ) ;
496496 }
@@ -509,7 +509,7 @@ describe('continuous profiling', () => {
509509 client . init ( ) ;
510510
511511 expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
512- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
512+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
513513 if ( ! integration ) {
514514 throw new Error ( 'Profiling integration not found' ) ;
515515 }
@@ -529,7 +529,7 @@ describe('continuous profiling', () => {
529529 client . init ( ) ;
530530
531531 expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
532- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
532+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
533533 if ( ! integration ) {
534534 throw new Error ( 'Profiling integration not found' ) ;
535535 }
@@ -548,7 +548,7 @@ describe('continuous profiling', () => {
548548 client . init ( ) ;
549549
550550 expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
551- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
551+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
552552 if ( ! integration ) {
553553 throw new Error ( 'Profiling integration not found' ) ;
554554 }
@@ -604,7 +604,7 @@ describe('continuous profiling', () => {
604604
605605 const transportSpy = jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
606606
607- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
607+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
608608 if ( ! integration ) {
609609 throw new Error ( 'Profiling integration not found' ) ;
610610 }
@@ -632,7 +632,7 @@ describe('continuous profiling', () => {
632632 } ,
633633 } ) ;
634634
635- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
635+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
636636 if ( ! integration ) {
637637 throw new Error ( 'Profiling integration not found' ) ;
638638 }
@@ -692,7 +692,7 @@ describe('span profiling mode', () => {
692692 Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
693693
694694 expect ( startProfilingSpy ) . toHaveBeenCalled ( ) ;
695- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
695+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
696696
697697 if ( ! integration ) {
698698 throw new Error ( 'Profiling integration not found' ) ;
@@ -703,6 +703,10 @@ describe('span profiling mode', () => {
703703 } ) ;
704704} ) ;
705705describe ( 'continuous profiling mode' , ( ) => {
706+ beforeEach ( ( ) => {
707+ jest . clearAllMocks ( ) ;
708+ } ) ;
709+
706710 it . each ( [
707711 [ 'profilesSampleRate=0' , makeClientOptions ( { profilesSampleRate : 0 } ) ] ,
708712 [ 'profilesSampleRate=undefined' , makeClientOptions ( { profilesSampleRate : undefined } ) ] ,
@@ -739,7 +743,7 @@ describe('continuous profiling mode', () => {
739743
740744 jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
741745
742- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
746+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
743747 if ( ! integration ) {
744748 throw new Error ( 'Profiling integration not found' ) ;
745749 }
@@ -750,4 +754,31 @@ describe('continuous profiling mode', () => {
750754 Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
751755 expect ( startProfilingSpy ) . toHaveBeenCalledTimes ( callCount ) ;
752756 } ) ;
757+
758+ it ( 'top level methods proxy to integration' , ( ) => {
759+ const client = new Sentry . NodeClient ( {
760+ ...makeClientOptions ( { profilesSampleRate : undefined } ) ,
761+ dsn : 'https://7fa19397baaf433f919fbe02228d5470@o1137848.ingest.sentry.io/6625302' ,
762+ tracesSampleRate : 1 ,
763+ transport : _opts =>
764+ Sentry . makeNodeTransport ( {
765+ url : 'https://7fa19397baaf433f919fbe02228d5470@o1137848.ingest.sentry.io/6625302' ,
766+ recordDroppedEvent : ( ) => {
767+ return undefined ;
768+ } ,
769+ } ) ,
770+ integrations : [ _nodeProfilingIntegration ( ) ] ,
771+ } ) ;
772+
773+ Sentry . setCurrentClient ( client ) ;
774+ client . init ( ) ;
775+
776+ const startProfilingSpy = jest . spyOn ( CpuProfilerBindings , 'startProfiling' ) ;
777+ const stopProfilingSpy = jest . spyOn ( CpuProfilerBindings , 'stopProfiling' ) ;
778+
779+ Sentry . profiler . startProfiler ( ) ;
780+ expect ( startProfilingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
781+ Sentry . profiler . stopProfiler ( ) ;
782+ expect ( stopProfilingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
783+ } ) ;
753784} ) ;
0 commit comments