Remover RateSampler and sampler config options
MODIFY
dd-trace-ot/src/main/java/datadog/trace/common/DDTraceConfig.java
dd-trace-ot/src/main/java/datadog/trace/common/DDTraceConfig.java
@@ -23,16 +23,12 @@ public class DDTraceConfig extends Properties {
public static final String WRITER_TYPE = "writer.type";
public static final String AGENT_HOST = "agent.host";
public static final String AGENT_PORT = "agent.port";
- public static final String SAMPLER_TYPE = "sampler.type";
- public static final String SAMPLER_RATE = "sampler.rate";
public static final String PRIORITY_SAMPLING = "priority.sampling";
private final String serviceName = getPropOrEnv(PREFIX + SERVICE_NAME);
private final String writerType = getPropOrEnv(PREFIX + WRITER_TYPE);
private final String agentHost = getPropOrEnv(PREFIX + AGENT_HOST);
private final String agentPort = getPropOrEnv(PREFIX + AGENT_PORT);
- private final String samplerType = getPropOrEnv(PREFIX + SAMPLER_TYPE);
- private final String samplerRate = getPropOrEnv(PREFIX + SAMPLER_RATE);
private final String prioritySampling = getPropOrEnv(PREFIX + PRIORITY_SAMPLING);
public DDTraceConfig() {
@@ -43,16 +39,12 @@ public class DDTraceConfig extends Properties {
defaults.setProperty(WRITER_TYPE, Writer.DD_AGENT_WRITER_TYPE);
defaults.setProperty(AGENT_HOST, DDAgentWriter.DEFAULT_HOSTNAME);
defaults.setProperty(AGENT_PORT, String.valueOf(DDAgentWriter.DEFAULT_PORT));
- defaults.setProperty(SAMPLER_TYPE, Sampler.ALL_SAMPLER_TYPE);
- defaults.setProperty(SAMPLER_RATE, "1.0");
super.defaults = defaults;
setIfNotNull(SERVICE_NAME, serviceName);
setIfNotNull(WRITER_TYPE, writerType);
setIfNotNull(AGENT_HOST, agentHost);
setIfNotNull(AGENT_PORT, agentPort);
- setIfNotNull(SAMPLER_TYPE, samplerType);
- setIfNotNull(SAMPLER_RATE, samplerRate);
setIfNotNull(PRIORITY_SAMPLING, prioritySampling);
}

MODIFY
dd-trace-ot/src/main/java/datadog/trace/common/sampling/RateByServiceSampler.java
dd-trace-ot/src/main/java/datadog/trace/common/sampling/RateByServiceSampler.java
+
package datadog.trace.common.sampling;
import com.fasterxml.jackson.databind.JsonNode;
@@ -80,4 +81,54 @@ public class RateByServiceSampler implements Sampler, ResponseListener {
private Builder() {}
}
+
+ /**
+ * This sampler sample the traces at a predefined rate.
+ *
+ * <p>Keep (100 * `sample_rate`)% of the traces. It samples randomly, its main purpose is to
+ * reduce the integration footprint.
+ */
+ private static class RateSampler extends AbstractSampler {
+
+ /** The sample rate used */
+ private final double sampleRate;
+
+ public RateSampler(final String sampleRate) {
+ this(sampleRate == null ? 1 : Double.valueOf(sampleRate));
+ }
+
+ /**
+ * Build an instance of the sampler. The Sample rate is fixed for each instance.
+ *
+ * @param sampleRate a number [0,1] representing the rate ratio.
+ */
+ public RateSampler(double sampleRate) {
+
+ if (sampleRate <= 0) {
+ sampleRate = 1;
+ log.error("SampleRate is negative or null, disabling the sampler");
+ } else if (sampleRate > 1) {
+ sampleRate = 1;
+ }
+
+ this.sampleRate = sampleRate;
+ log.debug("Initializing the RateSampler, sampleRate: {} %", this.sampleRate * 100);
+ }
+
+ @Override
+ public boolean doSample(final DDSpan span) {
+ final boolean sample = Math.random() <= this.sampleRate;
+ log.debug("{} - Span is sampled: {}", span, sample);
+ return sample;
+ }
+
+ public double getSampleRate() {
+ return this.sampleRate;
+ }
+
+ @Override
+ public String toString() {
+ return "RateSampler { sampleRate=" + sampleRate + " }";
+ }
+ }
}

DELETE
dd-trace-ot/src/main/java/datadog/trace/common/sampling/RateSampler.java
-package datadog.trace.common.sampling;
-
-import com.google.auto.service.AutoService;
-import datadog.opentracing.DDSpan;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * This sampler sample the traces at a predefined rate.
- *
- * <p>Keep (100 * `sample_rate`)% of the traces. It samples randomly, its main purpose is to reduce
- * the integration footprint.
- */
-@Slf4j
-@AutoService(Sampler.class)
-public class RateSampler extends AbstractSampler {
-
- /** The sample rate used */
- private final double sampleRate;
-
- public RateSampler(final String sampleRate) {
- this(sampleRate == null ? 1 : Double.valueOf(sampleRate));
- }
-
- /**
- * Build an instance of the sampler. The Sample rate is fixed for each instance.
- *
- * @param sampleRate a number [0,1] representing the rate ratio.
- */
- public RateSampler(double sampleRate) {
-
- if (sampleRate <= 0) {
- sampleRate = 1;
- log.error("SampleRate is negative or null, disabling the sampler");
- } else if (sampleRate > 1) {
- sampleRate = 1;
- }
-
- this.sampleRate = sampleRate;
- log.debug("Initializing the RateSampler, sampleRate: {} %", this.sampleRate * 100);
- }
-
- @Override
- public boolean doSample(final DDSpan span) {
- final boolean sample = Math.random() <= this.sampleRate;
- log.debug("{} - Span is sampled: {}", span, sample);
- return sample;
- }
-
- public double getSampleRate() {
- return this.sampleRate;
- }
-
- @Override
- public String toString() {
- return "RateSampler { sampleRate=" + sampleRate + " }";
- }
-}

MODIFY
dd-trace-ot/src/main/java/datadog/trace/common/sampling/Sampler.java
dd-trace-ot/src/main/java/datadog/trace/common/sampling/Sampler.java
package datadog.trace.common.sampling;
import datadog.opentracing.DDSpan;
-import datadog.trace.common.DDTraceConfig;
import java.util.Properties;
-import lombok.extern.slf4j.Slf4j;
/** Main interface to sample a collection of traces. */
public interface Sampler {
static final String ALL_SAMPLER_TYPE = AllSampler.class.getSimpleName();
- static final String RATE_SAMPLER_TYPE = RateSampler.class.getSimpleName();
/**
* Sample a collection of traces based on the parent span
@@ -18,29 +15,9 @@ public interface Sampler {
*/
boolean sample(DDSpan span);
- @Slf4j
final class Builder {
public static Sampler forConfig(final Properties config) {
- final Sampler sampler;
-
- if (config != null) {
- final String configuredType = config.getProperty(DDTraceConfig.SAMPLER_TYPE);
- if (RATE_SAMPLER_TYPE.equals(configuredType)) {
- sampler = new RateSampler(config.getProperty(DDTraceConfig.SAMPLER_RATE));
- } else if (ALL_SAMPLER_TYPE.equals(configuredType)) {
- sampler = new AllSampler();
- } else {
- log.warn(
- "Sampler type not configured correctly: Type {} not recognized. Defaulting to AllSampler.",
- configuredType);
- sampler = new AllSampler();
- }
- } else {
- log.warn(
- "Sampler type not configured correctly: No config provided! Defaulting to AllSampler.");
- sampler = new AllSampler();
- }
- return sampler;
+ return new AllSampler();
}
private Builder() {}

MODIFY
dd-trace-ot/src/test/groovy/datadog/trace/DDTraceConfigTest.groovy
dd-trace-ot/src/test/groovy/datadog/trace/DDTraceConfigTest.groovy
@@ -3,7 +3,6 @@ package datadog.trace
import datadog.opentracing.DDTracer
import datadog.trace.common.DDTraceConfig
import datadog.trace.common.sampling.AllSampler
-import datadog.trace.common.sampling.RateSampler
import datadog.trace.common.writer.DDAgentWriter
import datadog.trace.common.writer.ListWriter
import datadog.trace.common.writer.LoggingWriter
@@ -52,8 +51,6 @@ class DDTraceConfigTest extends Specification {
System.clearProperty(PREFIX + WRITER_TYPE)
System.clearProperty(PREFIX + AGENT_HOST)
System.clearProperty(PREFIX + AGENT_PORT)
- System.clearProperty(PREFIX + SAMPLER_TYPE)
- System.clearProperty(PREFIX + SAMPLER_RATE)
}
def "verify env override"() {
@@ -73,8 +70,6 @@ class DDTraceConfigTest extends Specification {
config.getProperty(WRITER_TYPE) == "DDAgentWriter"
config.getProperty(AGENT_HOST) == "localhost"
config.getProperty(AGENT_PORT) == "8126"
- config.getProperty(SAMPLER_TYPE) == "AllSampler"
- config.getProperty(SAMPLER_RATE) == "1.0"
when:
config = new DDTraceConfig("A different service name")
@@ -84,56 +79,45 @@ class DDTraceConfigTest extends Specification {
config.getProperty(WRITER_TYPE) == "DDAgentWriter"
config.getProperty(AGENT_HOST) == "localhost"
config.getProperty(AGENT_PORT) == "8126"
- config.getProperty(SAMPLER_TYPE) == "AllSampler"
- config.getProperty(SAMPLER_RATE) == "1.0"
}
def "specify overrides via system properties"() {
when:
System.setProperty(PREFIX + SERVICE_NAME, "something else")
System.setProperty(PREFIX + WRITER_TYPE, LoggingWriter.simpleName)
- System.setProperty(PREFIX + SAMPLER_TYPE, RateSampler.simpleName)
- System.setProperty(PREFIX + SAMPLER_RATE, ".5")
def tracer = new DDTracer()
then:
tracer.serviceName == "something else"
tracer.writer instanceof LoggingWriter
- tracer.sampler.toString() == "RateSampler { sampleRate=0.5 }"
}
def "specify overrides via env vars"() {
when:
overrideEnvMap.put(propToEnvName(PREFIX + SERVICE_NAME), "still something else")
overrideEnvMap.put(propToEnvName(PREFIX + WRITER_TYPE), LoggingWriter.simpleName)
- overrideEnvMap.put(propToEnvName(PREFIX + SAMPLER_TYPE), AllSampler.simpleName)
def tracer = new DDTracer()
then:
tracer.serviceName == "still something else"
tracer.writer instanceof LoggingWriter
- tracer.sampler instanceof AllSampler
}
def "sys props override env vars"() {
when:
overrideEnvMap.put(propToEnvName(PREFIX + SERVICE_NAME), "still something else")
overrideEnvMap.put(propToEnvName(PREFIX + WRITER_TYPE), ListWriter.simpleName)
- overrideEnvMap.put(propToEnvName(PREFIX + SAMPLER_TYPE), AllSampler.simpleName)
System.setProperty(PREFIX + SERVICE_NAME, "what we actually want")
System.setProperty(PREFIX + WRITER_TYPE, DDAgentWriter.simpleName)
System.setProperty(PREFIX + AGENT_HOST, "somewhere")
System.setProperty(PREFIX + AGENT_PORT, "9999")
- System.setProperty(PREFIX + SAMPLER_TYPE, RateSampler.simpleName)
- System.setProperty(PREFIX + SAMPLER_RATE, ".9")
def tracer = new DDTracer()
then:
tracer.serviceName == "what we actually want"
tracer.writer.toString() == "DDAgentWriter { api=DDApi { tracesEndpoint=http://somewhere:9999/v0.3/traces } }"
- tracer.sampler.toString() == "RateSampler { sampleRate=0.9 }"
}
def "verify defaults on tracer"() {
@@ -164,8 +148,5 @@ class DDTraceConfigTest extends Specification {
"writer" | "writer.type" | "LoggingWriter" | "LoggingWriter { }"
"writer" | "agent.host" | "somethingelse" | "DDAgentWriter { api=DDApi { tracesEndpoint=http://somethingelse:8126/v0.3/traces } }"
"writer" | "agent.port" | "9999" | "DDAgentWriter { api=DDApi { tracesEndpoint=http://localhost:9999/v0.3/traces } }"
- "sampler" | "default" | "default" | "AllSampler { sample=true }"
- "sampler" | "sampler.type" | "RateSampler" | "RateSampler { sampleRate=1.0 }"
- "sampler" | "sampler.rate" | "100" | "AllSampler { sample=true }"
}
}

DELETE
dd-trace-ot/src/test/java/datadog/opentracing/DDTracerTest.java
-package datadog.opentracing;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import datadog.trace.common.sampling.RateSampler;
-import datadog.trace.common.writer.Writer;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.Queue;
-import org.junit.Test;
-
-public class DDTracerTest {
-
- @Test
- public void write() throws Exception {
-
- final Writer writer = mock(Writer.class);
- final RateSampler sampler = mock(RateSampler.class);
- final DDSpan span = mock(DDSpan.class);
-
- // Rate 0.5
- when(sampler.sample(any(DDSpan.class))).thenReturn(true).thenReturn(false);
-
- final Queue<DDSpan> spans = new LinkedList<>();
- spans.add(span);
- spans.add(span);
- spans.add(span);
-
- final DDTracer tracer = new DDTracer(DDTracer.UNASSIGNED_DEFAULT_SERVICE_NAME, writer, sampler);
-
- tracer.write(spans);
- tracer.write(spans);
-
- verify(sampler, times(2)).sample(span);
- verify(writer, times(1)).write(new ArrayList<>(spans));
- }
-}

DELETE
dd-trace-ot/src/test/java/datadog/trace/api/sampling/RateSamplerTest.java
-package datadog.trace.api.sampling;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-import datadog.opentracing.DDSpan;
-import datadog.trace.common.sampling.RateSampler;
-import datadog.trace.common.sampling.Sampler;
-import org.junit.Test;
-
-public class RateSamplerTest {
-
- @Test
- public void testRateSampler() {
-
- final DDSpan mockSpan = mock(DDSpan.class);
-
- final double sampleRate = 0.35;
- final int iterations = 1000;
- final Sampler sampler = new RateSampler(sampleRate);
-
- int kept = 0;
-
- for (int i = 0; i < iterations; i++) {
- if (sampler.sample(mockSpan)) {
- kept++;
- }
- }
- // FIXME test has to be more predictable
- // assertThat(((double) kept / iterations)).isBetween(sampleRate - 0.02, sampleRate + 0.02);
-
- }
-
- @Test
- public void testRateBoundaries() {
-
- RateSampler sampler = new RateSampler(1000);
- assertThat(sampler.getSampleRate()).isEqualTo(1);
-
- sampler = new RateSampler(-1000);
- assertThat(sampler.getSampleRate()).isEqualTo(1);
-
- sampler = new RateSampler(0.337);
- assertThat(sampler.getSampleRate()).isEqualTo(0.337);
- }
-}

Remover RateSampler and sampler config options