@@ -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 ( {
@@ -550,6 +560,85 @@ describe('api', () => {
550560 // Should only get 25 calls (global limit)
551561 expect ( mockBatchAdd ) . toHaveBeenCalledTimes ( 25 )
552562 } )
563+
564+ it ( 'should respect configured global snapshot rate limit' , ( ) => {
565+ initTransport ( { maxSnapshotsPerSecondGlobally : 2 } )
566+
567+ for ( let i = 0 ; i < 3 ; i ++ ) {
568+ const probe : Probe = {
569+ id : `configured-global-probe-${ i } ` ,
570+ version : 0 ,
571+ type : 'LOG_PROBE' ,
572+ where : { typeName : 'TestClass' , methodName : `configuredGlobal${ i } ` } ,
573+ template : 'Test' ,
574+ captureSnapshot : true ,
575+ capture : { } ,
576+ sampling : { snapshotsPerSecond : 5000 } ,
577+ evaluateAt : 'ENTRY' ,
578+ }
579+ addProbe ( probe )
580+ }
581+
582+ for ( let i = 0 ; i < 3 ; i ++ ) {
583+ const probes = getProbes ( `TestClass;configuredGlobal${ i } ` ) !
584+ onEntry ( probes , { } , { } )
585+ onReturn ( probes , null , { } , { } , { } )
586+ }
587+
588+ expect ( mockBatchAdd ) . toHaveBeenCalledTimes ( 2 )
589+ } )
590+ } )
591+
592+ describe ( 'configured per-second budgets' , ( ) => {
593+ it ( 'should respect configured default snapshot per-probe rate limit' , ( ) => {
594+ initTransport ( { maxSnapshotsPerSecondPerProbe : 0.5 } )
595+
596+ const probe : Probe = {
597+ id : 'configured-snapshot-rate-probe' ,
598+ version : 0 ,
599+ type : 'LOG_PROBE' ,
600+ where : { typeName : 'TestClass' , methodName : 'configuredSnapshotRate' } ,
601+ template : 'Test' ,
602+ captureSnapshot : true ,
603+ capture : { maxReferenceDepth : 1 } ,
604+ sampling : { } ,
605+ evaluateAt : 'ENTRY' ,
606+ }
607+ addProbe ( probe )
608+
609+ const probes = getProbes ( 'TestClass;configuredSnapshotRate' ) !
610+ onEntry ( probes , { } , { } )
611+ onReturn ( probes , null , { } , { } , { } )
612+ onEntry ( probes , { } , { } )
613+ onReturn ( probes , null , { } , { } , { } )
614+
615+ expect ( mockBatchAdd ) . toHaveBeenCalledTimes ( 1 )
616+ } )
617+
618+ it ( 'should respect configured default non-snapshot per-probe rate limit' , ( ) => {
619+ initTransport ( { maxNonSnapshotsPerSecondPerProbe : 1 } )
620+
621+ const probe : Probe = {
622+ id : 'configured-non-snapshot-rate-probe' ,
623+ version : 0 ,
624+ type : 'LOG_PROBE' ,
625+ where : { typeName : 'TestClass' , methodName : 'configuredNonSnapshotRate' } ,
626+ template : 'Test' ,
627+ captureSnapshot : false ,
628+ capture : { } ,
629+ sampling : { } ,
630+ evaluateAt : 'ENTRY' ,
631+ }
632+ addProbe ( probe )
633+
634+ const probes = getProbes ( 'TestClass;configuredNonSnapshotRate' ) !
635+ onEntry ( probes , { } , { } )
636+ onReturn ( probes , null , { } , { } , { } )
637+ onEntry ( probes , { } , { } )
638+ onReturn ( probes , null , { } , { } , { } )
639+
640+ expect ( mockBatchAdd ) . toHaveBeenCalledTimes ( 1 )
641+ } )
553642 } )
554643
555644 describe ( 'active entries cleanup' , ( ) => {
0 commit comments