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