@@ -2,10 +2,11 @@ import * as Sentry from '@sentry/node';
2
2
3
3
import { getMainCarrier } from '@sentry/core' ;
4
4
import type { NodeClientOptions } from '@sentry/node/build/types/types' ;
5
+ import type { ProfilingIntegration } from '@sentry/types' ;
5
6
import type { ProfileChunk , Transport } from '@sentry/types' ;
6
7
import { GLOBAL_OBJ , createEnvelope , logger } from '@sentry/utils' ;
7
8
import { CpuProfilerBindings } from '../src/cpu_profiler' ;
8
- import { type ProfilingIntegration , _nodeProfilingIntegration } from '../src/integration' ;
9
+ import { _nodeProfilingIntegration } from '../src/integration' ;
9
10
10
11
function makeClientWithHooks ( ) : [ Sentry . NodeClient , Transport ] {
11
12
const integration = _nodeProfilingIntegration ( ) ;
@@ -299,7 +300,7 @@ describe('automated span instrumentation', () => {
299
300
Sentry . setCurrentClient ( client ) ;
300
301
client . init ( ) ;
301
302
302
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
303
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
303
304
if ( ! integration ) {
304
305
throw new Error ( 'Profiling integration not found' ) ;
305
306
}
@@ -390,7 +391,7 @@ describe('continuous profiling', () => {
390
391
} ) ;
391
392
afterEach ( ( ) => {
392
393
const client = Sentry . getClient ( ) ;
393
- const integration = client ?. getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
394
+ const integration = client ?. getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
394
395
395
396
if ( integration ) {
396
397
integration . _profiler . stop ( ) ;
@@ -432,7 +433,7 @@ describe('continuous profiling', () => {
432
433
433
434
const transportSpy = jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
434
435
435
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
436
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
436
437
if ( ! integration ) {
437
438
throw new Error ( 'Profiling integration not found' ) ;
438
439
}
@@ -446,7 +447,7 @@ describe('continuous profiling', () => {
446
447
expect ( profile . client_sdk . version ) . toEqual ( expect . stringMatching ( / \d + \. \d + \. \d + / ) ) ;
447
448
} ) ;
448
449
449
- it ( 'initializes the continuous profiler and binds the sentry client ' , ( ) => {
450
+ it ( 'initializes the continuous profiler' , ( ) => {
450
451
const startProfilingSpy = jest . spyOn ( CpuProfilerBindings , 'startProfiling' ) ;
451
452
452
453
const [ client ] = makeContinuousProfilingClient ( ) ;
@@ -455,14 +456,13 @@ describe('continuous profiling', () => {
455
456
456
457
expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
457
458
458
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
459
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
459
460
if ( ! integration ) {
460
461
throw new Error ( 'Profiling integration not found' ) ;
461
462
}
462
463
integration . _profiler . start ( ) ;
463
464
464
465
expect ( integration . _profiler ) . toBeDefined ( ) ;
465
- expect ( integration . _profiler [ '_client' ] ) . toBe ( client ) ;
466
466
} ) ;
467
467
468
468
it ( 'starts a continuous profile' , ( ) => {
@@ -473,7 +473,7 @@ describe('continuous profiling', () => {
473
473
client . init ( ) ;
474
474
475
475
expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
476
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
476
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
477
477
if ( ! integration ) {
478
478
throw new Error ( 'Profiling integration not found' ) ;
479
479
}
@@ -490,7 +490,7 @@ describe('continuous profiling', () => {
490
490
client . init ( ) ;
491
491
492
492
expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
493
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
493
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
494
494
if ( ! integration ) {
495
495
throw new Error ( 'Profiling integration not found' ) ;
496
496
}
@@ -509,7 +509,7 @@ describe('continuous profiling', () => {
509
509
client . init ( ) ;
510
510
511
511
expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
512
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
512
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
513
513
if ( ! integration ) {
514
514
throw new Error ( 'Profiling integration not found' ) ;
515
515
}
@@ -529,7 +529,7 @@ describe('continuous profiling', () => {
529
529
client . init ( ) ;
530
530
531
531
expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
532
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
532
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
533
533
if ( ! integration ) {
534
534
throw new Error ( 'Profiling integration not found' ) ;
535
535
}
@@ -548,7 +548,7 @@ describe('continuous profiling', () => {
548
548
client . init ( ) ;
549
549
550
550
expect ( startProfilingSpy ) . not . toHaveBeenCalledTimes ( 1 ) ;
551
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
551
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
552
552
if ( ! integration ) {
553
553
throw new Error ( 'Profiling integration not found' ) ;
554
554
}
@@ -604,7 +604,7 @@ describe('continuous profiling', () => {
604
604
605
605
const transportSpy = jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
606
606
607
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
607
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
608
608
if ( ! integration ) {
609
609
throw new Error ( 'Profiling integration not found' ) ;
610
610
}
@@ -632,7 +632,7 @@ describe('continuous profiling', () => {
632
632
} ,
633
633
} ) ;
634
634
635
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
635
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
636
636
if ( ! integration ) {
637
637
throw new Error ( 'Profiling integration not found' ) ;
638
638
}
@@ -692,7 +692,7 @@ describe('span profiling mode', () => {
692
692
Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
693
693
694
694
expect ( startProfilingSpy ) . toHaveBeenCalled ( ) ;
695
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
695
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
696
696
697
697
if ( ! integration ) {
698
698
throw new Error ( 'Profiling integration not found' ) ;
@@ -703,6 +703,10 @@ describe('span profiling mode', () => {
703
703
} ) ;
704
704
} ) ;
705
705
describe ( 'continuous profiling mode' , ( ) => {
706
+ beforeEach ( ( ) => {
707
+ jest . clearAllMocks ( ) ;
708
+ } ) ;
709
+
706
710
it . each ( [
707
711
[ 'profilesSampleRate=0' , makeClientOptions ( { profilesSampleRate : 0 } ) ] ,
708
712
[ 'profilesSampleRate=undefined' , makeClientOptions ( { profilesSampleRate : undefined } ) ] ,
@@ -739,7 +743,7 @@ describe('continuous profiling mode', () => {
739
743
740
744
jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
741
745
742
- const integration = client . getIntegrationByName < ProfilingIntegration > ( 'ProfilingIntegration' ) ;
746
+ const integration = client . getIntegrationByName < ProfilingIntegration < Sentry . NodeClient > > ( 'ProfilingIntegration' ) ;
743
747
if ( ! integration ) {
744
748
throw new Error ( 'Profiling integration not found' ) ;
745
749
}
@@ -750,4 +754,31 @@ describe('continuous profiling mode', () => {
750
754
Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
751
755
expect ( startProfilingSpy ) . toHaveBeenCalledTimes ( callCount ) ;
752
756
} ) ;
757
+
758
+ it ( 'top level methods proxy to integration' , ( ) => {
759
+ const client = new Sentry . NodeClient ( {
760
+ ...makeClientOptions ( { profilesSampleRate : undefined } ) ,
761
+ dsn :
'https://[email protected] /6625302' ,
762
+ tracesSampleRate : 1 ,
763
+ transport : _opts =>
764
+ Sentry . makeNodeTransport ( {
765
+ url :
'https://[email protected] /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
+ } ) ;
753
784
} ) ;
0 commit comments