/** * Delegates to {@link #rootSpanSamplingStrategy}'s {@link RootSpanSamplingStrategy#isNextRootSpanSampleable()} method to determine whether the next root span should be * sampled. * <br/> * NOTE: This method is not deterministic - you may get a different response every time you call it. Therefore you should not call this method multiple times for the same * root span. Call it once and store the result for a given root span. * * @return true when the next root span should be sampled, false otherwise. */ protected boolean isNextRootSpanSampleable() { return rootSpanSamplingStrategy.isNextRootSpanSampleable(); }
@Test public void isNextRootSpanSampleable_returns_true() { SampleAllTheThingsStrategy strategy = new SampleAllTheThingsStrategy(); for (int i = 0; i < 100; i++) { assertThat(strategy.isNextRootSpanSampleable()).isTrue(); } }
private void resetTracer() { Tracer.getInstance().completeRequestSpan(); Tracer.getInstance().setRootSpanSamplingStrategy(new SampleAllTheThingsStrategy()); for (SpanLifecycleListener listener : new ArrayList<>(Tracer.getInstance().getSpanLifecycleListeners())) { Tracer.getInstance().removeSpanLifecycleListener(listener); } Tracer.getInstance().setSpanLoggingRepresentation(Tracer.SpanLoggingRepresentation.JSON); }
@Test public void isNextRootSpanSampleable_should_use_strategy() { // given: known sampling strategy that is set on the Tracer RootSpanSamplingStrategy mockStrategy = mock(RootSpanSamplingStrategy.class); Tracer.getInstance().setRootSpanSamplingStrategy(mockStrategy); // when: isNextRootSpanSampleable() is called Tracer.getInstance().isNextRootSpanSampleable(); // then: the strategy's isNextRootSpanSampleable() method should have been called verify(mockStrategy).isNextRootSpanSampleable(); }