RateLimitingPreExecutionInterceptor extends PreExecutionSpanInterceptor { @Override public void interceptReport(PreExecutionInterceptorContext context) { if (rateLimiter == null) { return; } if (isRateExceeded(rateLimiter) && isRoot(context.getSpanContext().getSpanWrapper())) { context.shouldNotReport(getClass()); } }  @Override void init(ConfigurationRegistry configuration); static RateLimiter getRateLimiter(double creditsPerMinute); @Override void interceptReport(PreExecutionInterceptorContext context); static boolean isRateExceeded(RateLimiter rateLimiter);  }
@Test public void testRateNotExceededThenExceededSpan() throws Exception { tracingPlugin.getDefaultRateLimitSpansPerMinuteOption().update(60d, SimpleSource.NAME); interceptor.interceptReport(context); assertTrue(context.isReport()); interceptor.interceptReport(context); assertFalse(context.isReport()); }
@Test public void testRateExceededThenNotExceededSpan() throws Exception { tracingPlugin.getDefaultRateLimitSpansPerMinuteOption().update(60.0, SimpleSource.NAME); interceptor.interceptReport(context); assertTrue(context.isReport()); interceptor.interceptReport(context); assertFalse(context.isReport()); }
@Test public void testNeverReportSpan() throws Exception { tracingPlugin.getDefaultRateLimitSpansPerMinuteOption().update(0d, SimpleSource.NAME); interceptor.interceptReport(context); assertFalse(context.isReport()); interceptor.interceptReport(context); assertFalse(context.isReport()); }
@Test public void testAlwaysReportSpan() throws Exception { tracingPlugin.getDefaultRateLimitSpansPerMinuteOption().update(1_000_000.0, SimpleSource.NAME); interceptor.interceptReport(context); assertTrue(context.isReport()); }