private SpanContextInformation invokeEventListener() { return invokeEventListener(true); }
private SpanContextInformation invokeEventListener(boolean sampled) { when(tracingPlugin.isSampled(any())).thenReturn(sampled); SpanWrappingTracer spanWrappingTracer = initTracer(); final SpanWrappingTracer.SpanWrappingSpanBuilder spanBuilder = spanWrappingTracer.buildSpan("test"); spanBuilder.withTag(Tags.SAMPLING_PRIORITY.getKey(), sampled ? 1 : 0); span = spanBuilder.startManual(); final SpanContextInformation contextInformation = SpanContextInformation.forSpan(span); contextInformation.setPreExecutionInterceptorContext(new PreExecutionInterceptorContext(contextInformation)); contextInformation.setPostExecutionInterceptorContext(new PostExecutionInterceptorContext(contextInformation)); span.finish(); return contextInformation; }
@Test public void testProfileThisExecutionDeactive() throws Exception { doReturn(0d).when(tracingPlugin).getProfilerRateLimitPerMinute(); final SpanContextInformation spanContext = invokeEventListener(); assertThat(spanContext.getCallTree()).isNull(); }
@Test public void testRateLimiting() throws Exception { when(tracingPlugin.getProfilerRateLimitPerMinute()).thenReturn(1d); final SpanContextInformation spanContext1 = invokeEventListener(); assertNotNull(spanContext1.getCallTree()); final SpanContextInformation spanContext2 = invokeEventListener(); assertNotNull(spanContext2.getCallTree()); }
@Test public void testDontActivateProfilerWhenSpanIsNotSampled() throws Exception { doReturn(1000000d).when(tracingPlugin).getProfilerRateLimitPerMinute(); final SpanContextInformation spanContext = invokeEventListener(false); assertThat(spanContext.getCallTree()).isNull(); }
@Test public void testProfileThisExecutionAlwaysActive() throws Exception { doReturn(1000000d).when(tracingPlugin).getProfilerRateLimitPerMinute(); final SpanContextInformation spanContext = invokeEventListener(); assertThat(spanContext.getCallTree()).isNotNull(); assertThat(span.getStringTag(SpanUtils.CALL_TREE_JSON)).isNotNull(); assertThat(span.getStringTag(SpanUtils.CALL_TREE_ASCII)).isNotNull(); }
@Test public void testExcludeCallTreeTags() throws Exception { doReturn(1000000d).when(tracingPlugin).getProfilerRateLimitPerMinute(); when(tracingPlugin.getExcludedTags()).thenReturn(Arrays.asList(SpanUtils.CALL_TREE_JSON, SpanUtils.CALL_TREE_ASCII)); final SpanContextInformation spanContext = invokeEventListener(); assertThat(spanContext.getCallTree()).isNotNull(); assertThat(span.getStringTag(SpanUtils.CALL_TREE_JSON)).isNull(); assertThat(span.getStringTag(SpanUtils.CALL_TREE_ASCII)).isNull(); }