@@ -7,11 +7,18 @@ describe('api', () => {
77 let mockBatchAdd : jasmine . Spy
88 let mockRumGetInternalContext : jasmine . Spy
99
10+ function initTransport ( overrides : Record < string , unknown > = { } ) {
11+ resetDebuggerTransport ( )
12+ initDebuggerTransport ( { service : 'test-service' , env : 'test-env' , ...overrides } as any , {
13+ add : mockBatchAdd ,
14+ } as any )
15+ }
16+
1017 beforeEach ( ( ) => {
1118 clearProbes ( )
1219
1320 mockBatchAdd = jasmine . createSpy ( 'batchAdd' )
14- initDebuggerTransport ( { service : 'test-service' , env : 'test-env' } as any , { add : mockBatchAdd } as any )
21+ initTransport ( )
1522
1623 // Mock DD_RUM global for context
1724 mockRumGetInternalContext = jasmine . createSpy ( 'getInternalContext' ) . and . returnValue ( {
@@ -519,6 +526,85 @@ describe('api', () => {
519526 // Should only get 25 calls (global limit)
520527 expect ( mockBatchAdd ) . toHaveBeenCalledTimes ( 25 )
521528 } )
529+
530+ it ( 'should respect configured global snapshot rate limit' , ( ) => {
531+ initTransport ( { maxSnapshotsPerSecondGlobally : 2 } )
532+
533+ for ( let i = 0 ; i < 3 ; i ++ ) {
534+ const probe : Probe = {
535+ id : `configured-global-probe-${ i } ` ,
536+ version : 0 ,
537+ type : 'LOG_PROBE' ,
538+ where : { typeName : 'TestClass' , methodName : `configuredGlobal${ i } ` } ,
539+ template : 'Test' ,
540+ captureSnapshot : true ,
541+ capture : { } ,
542+ sampling : { snapshotsPerSecond : 5000 } ,
543+ evaluateAt : 'ENTRY' ,
544+ }
545+ addProbe ( probe )
546+ }
547+
548+ for ( let i = 0 ; i < 3 ; i ++ ) {
549+ const probes = getProbes ( `TestClass;configuredGlobal${ i } ` ) !
550+ onEntry ( probes , { } , { } )
551+ onReturn ( probes , null , { } , { } , { } )
552+ }
553+
554+ expect ( mockBatchAdd ) . toHaveBeenCalledTimes ( 2 )
555+ } )
556+ } )
557+
558+ describe ( 'configured per-second budgets' , ( ) => {
559+ it ( 'should respect configured default snapshot per-probe rate limit' , ( ) => {
560+ initTransport ( { maxSnapshotsPerSecondPerProbe : 0.5 } )
561+
562+ const probe : Probe = {
563+ id : 'configured-snapshot-rate-probe' ,
564+ version : 0 ,
565+ type : 'LOG_PROBE' ,
566+ where : { typeName : 'TestClass' , methodName : 'configuredSnapshotRate' } ,
567+ template : 'Test' ,
568+ captureSnapshot : true ,
569+ capture : { maxReferenceDepth : 1 } ,
570+ sampling : { } ,
571+ evaluateAt : 'ENTRY' ,
572+ }
573+ addProbe ( probe )
574+
575+ const probes = getProbes ( 'TestClass;configuredSnapshotRate' ) !
576+ onEntry ( probes , { } , { } )
577+ onReturn ( probes , null , { } , { } , { } )
578+ onEntry ( probes , { } , { } )
579+ onReturn ( probes , null , { } , { } , { } )
580+
581+ expect ( mockBatchAdd ) . toHaveBeenCalledTimes ( 1 )
582+ } )
583+
584+ it ( 'should respect configured default non-snapshot per-probe rate limit' , ( ) => {
585+ initTransport ( { maxNonSnapshotsPerSecondPerProbe : 1 } )
586+
587+ const probe : Probe = {
588+ id : 'configured-non-snapshot-rate-probe' ,
589+ version : 0 ,
590+ type : 'LOG_PROBE' ,
591+ where : { typeName : 'TestClass' , methodName : 'configuredNonSnapshotRate' } ,
592+ template : 'Test' ,
593+ captureSnapshot : false ,
594+ capture : { } ,
595+ sampling : { } ,
596+ evaluateAt : 'ENTRY' ,
597+ }
598+ addProbe ( probe )
599+
600+ const probes = getProbes ( 'TestClass;configuredNonSnapshotRate' ) !
601+ onEntry ( probes , { } , { } )
602+ onReturn ( probes , null , { } , { } , { } )
603+ onEntry ( probes , { } , { } )
604+ onReturn ( probes , null , { } , { } , { } )
605+
606+ expect ( mockBatchAdd ) . toHaveBeenCalledTimes ( 1 )
607+ } )
522608 } )
523609
524610 describe ( 'active entries cleanup' , ( ) => {
0 commit comments