Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improvement] Set the default sampler to random with 1% #158

Merged
merged 2 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void testPopulatesNewTrace_whenParentTraceIsPresent() throws IOException

@Test
public void testAddsIsSampledHeader_whenTraceIsObservable() throws IOException {
Tracer.initTrace(Optional.of(true), Tracers.randomId());
OkhttpTraceInterceptor.INSTANCE.intercept(chain);
verify(chain).proceed(requestCaptor.capture());
assertThat(requestCaptor.getValue().header(TraceHttpHeaders.IS_SAMPLED)).isEqualTo("1");
Expand Down
2 changes: 1 addition & 1 deletion tracing/src/main/java/com/palantir/tracing/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private Tracer() {}
private static volatile Consumer<Span> compositeObserver = span -> { };

// Thread-safe since stateless
private static volatile TraceSampler sampler = AlwaysSampler.INSTANCE;
private static volatile TraceSampler sampler = new RandomSampler(0.01f);

/**
* Creates a new trace, but does not set it as the current trace. The new trace is {@link Trace#isObservable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import org.jmock.lib.concurrent.DeterministicScheduler;
Expand Down Expand Up @@ -98,6 +99,7 @@ public void testJsonFormatToLog() throws Exception {
DeterministicScheduler executor = new DeterministicScheduler();
Tracer.subscribe(TEST_OBSERVER, AsyncSlf4jSpanObserver.of(
"serviceName", Inet4Address.getLoopbackAddress(), logger, executor));
Tracer.initTrace(Optional.of(true), Tracers.randomId());
Tracer.startSpan("operation");
Span span = Tracer.completeSpan().get();
verify(appender, never()).doAppend(any(ILoggingEvent.class)); // async logger only fires when executor runs
Expand All @@ -118,6 +120,7 @@ public void testJsonFormatToLog() throws Exception {
public void testDefaultConstructorDeterminesIpAddress() throws Exception {
DeterministicScheduler executor = new DeterministicScheduler();
Tracer.subscribe(TEST_OBSERVER, AsyncSlf4jSpanObserver.of("serviceName", executor));
Tracer.initTrace(Optional.of(true), Tracers.randomId());
Tracer.startSpan("operation");
Span span = Tracer.completeSpan().get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void doesNotLeakEnqueueSpan() {

@Test
public void completesBothDeferredSpans() {
Tracer.initTrace(Optional.empty(), "defaultTraceId");
Tracer.initTrace(Optional.of(true), "defaultTraceId");
Tracer.startSpan("defaultSpan");
AsyncTracer asyncTracer = new AsyncTracer();
List<String> observedSpans = Lists.newArrayList();
Tracer.subscribe(
Expand Down