SamplingTraceExporter implements TraceExporter { @Override public void maybeExport(Supplier<TraceDescription> traceDescriptionSupplier) { if (samplingStrategy.shouldSample()) { wrappedExporter.maybeExport(traceDescriptionSupplier); } } SamplingTraceExporter(TraceExporter wrappedExporter, SamplingStrategy samplingStrategy); @Override void maybeExport(Supplier<TraceDescription> traceDescriptionSupplier);  }
@Test public void sampling_decision_is_deferred_to_provided_sampler() { var exporter = mock(TraceExporter.class); var sampler = mock(SamplingStrategy.class); when(sampler.shouldSample()).thenReturn(true, false); var samplingExporter = new SamplingTraceExporter(exporter, sampler); samplingExporter.maybeExport(() -> new TraceDescription(null, "")); verify(exporter, times(1)).maybeExport(any()); samplingExporter.maybeExport(() -> new TraceDescription(null, "")); verify(exporter, times(1)).maybeExport(any()); }