Remove sampling (#17)
This commit is contained in:
parent
d86632d648
commit
dc7d81e6d4
|
@ -16,7 +16,6 @@ public class Tags {
|
|||
public static final String PEER_SERVICE = "peer.service";
|
||||
public static final String PEER_HOSTNAME = "peer.hostname";
|
||||
public static final String PEER_PORT = "peer.port";
|
||||
public static final String SAMPLING_PRIORITY = "sampling.priority";
|
||||
public static final String SPAN_KIND = "span.kind";
|
||||
public static final String COMPONENT = "component";
|
||||
public static final String ERROR = "error";
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
apply from: "${rootDir}/gradle/java.gradle"
|
||||
|
||||
minimumBranchCoverage = 0.6
|
||||
minimumInstructionCoverage = 0.8
|
||||
excludedClassesCoverage += ['datadog.trace.agent.tooling.*']
|
||||
|
||||
configurations {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package datadog.trace.agent.decorator;
|
||||
|
||||
import datadog.trace.api.Config;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.api.AgentScope;
|
||||
import datadog.trace.instrumentation.api.AgentSpan;
|
||||
|
@ -10,24 +9,11 @@ import java.net.Inet4Address;
|
|||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public abstract class BaseDecorator {
|
||||
|
||||
protected final boolean traceAnalyticsEnabled;
|
||||
protected final float traceAnalyticsSampleRate;
|
||||
|
||||
protected BaseDecorator() {
|
||||
final Config config = Config.get();
|
||||
final String[] instrumentationNames = instrumentationNames();
|
||||
traceAnalyticsEnabled =
|
||||
instrumentationNames.length > 0
|
||||
&& config.isTraceAnalyticsIntegrationEnabled(
|
||||
new TreeSet<>(Arrays.asList(instrumentationNames)), traceAnalyticsDefault());
|
||||
traceAnalyticsSampleRate = config.getInstrumentationAnalyticsSampleRate(instrumentationNames);
|
||||
}
|
||||
protected BaseDecorator() {}
|
||||
|
||||
protected abstract String[] instrumentationNames();
|
||||
|
||||
|
@ -35,19 +21,12 @@ public abstract class BaseDecorator {
|
|||
|
||||
protected abstract String component();
|
||||
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public AgentSpan afterStart(final AgentSpan span) {
|
||||
assert span != null;
|
||||
if (spanType() != null) {
|
||||
span.setTag(DDTags.SPAN_TYPE, spanType());
|
||||
}
|
||||
span.setTag(Tags.COMPONENT.getKey(), component());
|
||||
if (traceAnalyticsEnabled) {
|
||||
span.setTag(DDTags.ANALYTICS_SAMPLE_RATE, traceAnalyticsSampleRate);
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,6 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
|
|||
return DDSpanTypes.HTTP_SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return Config.get().isTraceAnalyticsEnabled();
|
||||
}
|
||||
|
||||
public AgentSpan onRequest(final AgentSpan span, final REQUEST request) {
|
||||
assert span != null;
|
||||
if (request != null) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package datadog.trace.agent.decorator
|
||||
|
||||
import datadog.trace.agent.test.utils.ConfigUtils
|
||||
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.instrumentation.api.AgentScope
|
||||
import datadog.trace.instrumentation.api.AgentSpan
|
||||
|
@ -139,51 +139,6 @@ class BaseDecoratorTest extends DDSpecification {
|
|||
1 * scope.span() >> span
|
||||
}
|
||||
|
||||
def "test analytics rate default disabled"() {
|
||||
when:
|
||||
BaseDecorator dec = newDecorator(defaultEnabled, hasConfigNames)
|
||||
|
||||
then:
|
||||
dec.traceAnalyticsEnabled == defaultEnabled
|
||||
dec.traceAnalyticsSampleRate == sampleRate.floatValue()
|
||||
|
||||
where:
|
||||
defaultEnabled | hasConfigNames | sampleRate
|
||||
true | false | 1.0
|
||||
false | false | 1.0
|
||||
false | true | 1.0
|
||||
}
|
||||
|
||||
def "test analytics rate enabled:#enabled, integration:#integName, sampleRate:#sampleRate"() {
|
||||
setup:
|
||||
ConfigUtils.updateConfig {
|
||||
System.properties.setProperty("dd.${integName}.analytics.enabled", "true")
|
||||
System.properties.setProperty("dd.${integName}.analytics.sample-rate", "$sampleRate")
|
||||
}
|
||||
|
||||
when:
|
||||
BaseDecorator dec = newDecorator(enabled)
|
||||
|
||||
then:
|
||||
dec.traceAnalyticsEnabled == expectedEnabled
|
||||
dec.traceAnalyticsSampleRate == (Float) expectedRate
|
||||
|
||||
cleanup:
|
||||
System.clearProperty("dd.${integName}.analytics.enabled")
|
||||
System.clearProperty("dd.${integName}.analytics.sample-rate")
|
||||
|
||||
where:
|
||||
enabled | integName | sampleRate | expectedEnabled | expectedRate
|
||||
false | "" | "" | false | 1.0
|
||||
true | "" | "" | true | 1.0
|
||||
false | "test1" | 0.5 | true | 0.5
|
||||
false | "test2" | 0.75 | true | 0.75
|
||||
true | "test1" | 0.2 | true | 0.2
|
||||
true | "test2" | 0.4 | true | 0.4
|
||||
true | "test1" | "" | true | 1.0
|
||||
true | "test2" | "" | true | 1.0
|
||||
}
|
||||
|
||||
def "test spanNameForMethod"() {
|
||||
when:
|
||||
def result = decorator.spanNameForMethod(method)
|
||||
|
@ -201,68 +156,22 @@ class BaseDecoratorTest extends DDSpecification {
|
|||
}
|
||||
|
||||
def newDecorator() {
|
||||
return newDecorator(false)
|
||||
}
|
||||
return new BaseDecorator() {
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
return []
|
||||
}
|
||||
|
||||
def newDecorator(boolean analyticsEnabledDefault, boolean emptyInstrumentationNames = false) {
|
||||
return emptyInstrumentationNames ?
|
||||
new BaseDecorator() {
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
return []
|
||||
}
|
||||
@Override
|
||||
protected String spanType() {
|
||||
return "test-type"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String spanType() {
|
||||
return "test-type"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String component() {
|
||||
return "test-component"
|
||||
}
|
||||
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return true
|
||||
}
|
||||
} :
|
||||
analyticsEnabledDefault ?
|
||||
new BaseDecorator() {
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
return ["test1", "test2"]
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String spanType() {
|
||||
return "test-type"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String component() {
|
||||
return "test-component"
|
||||
}
|
||||
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return true
|
||||
}
|
||||
} :
|
||||
new BaseDecorator() {
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
return ["test1", "test2"]
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String spanType() {
|
||||
return "test-type"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String component() {
|
||||
return "test-component"
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected String component() {
|
||||
return "test-component"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SomeInnerClass implements Runnable {
|
||||
|
|
|
@ -22,7 +22,6 @@ class ClientDecoratorTest extends BaseDecoratorTest {
|
|||
1 * span.setTag(Tags.COMPONENT.key, "test-component")
|
||||
1 * span.setTag(Tags.SPAN_KIND.key, "client")
|
||||
1 * span.setTag(DDTags.SPAN_TYPE, decorator.spanType())
|
||||
1 * span.setTag(DDTags.ANALYTICS_SAMPLE_RATE, 1.0)
|
||||
_ * span.setTag(_, _) // Want to allow other calls from child implementations.
|
||||
0 * _
|
||||
|
||||
|
@ -64,10 +63,6 @@ class ClientDecoratorTest extends BaseDecoratorTest {
|
|||
protected String component() {
|
||||
return "test-component"
|
||||
}
|
||||
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest {
|
|||
1 * span.setTag(Tags.SPAN_KIND.key, "client")
|
||||
1 * span.setTag(Tags.DB_TYPE.key, "test-db")
|
||||
1 * span.setTag(DDTags.SPAN_TYPE, "test-type")
|
||||
1 * span.setTag(DDTags.ANALYTICS_SAMPLE_RATE, 1.0)
|
||||
0 * _
|
||||
|
||||
where:
|
||||
|
@ -138,10 +137,6 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest {
|
|||
protected String dbInstance(Map map) {
|
||||
return map.instance
|
||||
}
|
||||
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,10 +174,6 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
|
|||
protected Integer status(Map m) {
|
||||
return m.status
|
||||
}
|
||||
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,6 @@ class ServerDecoratorTest extends BaseDecoratorTest {
|
|||
1 * span.setTag(Tags.COMPONENT.key, "test-component")
|
||||
1 * span.setTag(Tags.SPAN_KIND.key, "server")
|
||||
1 * span.setTag(DDTags.SPAN_TYPE, decorator.spanType())
|
||||
if (decorator.traceAnalyticsEnabled) {
|
||||
1 * span.setTag(DDTags.ANALYTICS_SAMPLE_RATE, 1.0)
|
||||
}
|
||||
0 * _
|
||||
}
|
||||
|
||||
|
@ -50,10 +47,6 @@ class ServerDecoratorTest extends BaseDecoratorTest {
|
|||
protected String component() {
|
||||
return "test-component"
|
||||
}
|
||||
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,11 +26,6 @@ public class RatpackServerDecorator extends HttpServerDecorator<Request, Request
|
|||
return "ratpack";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String method(final Request request) {
|
||||
return request.getMethod().getName();
|
||||
|
|
|
@ -38,11 +38,6 @@ public class SpringWebHttpServerDecorator
|
|||
return "spring-web-controller";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean traceAnalyticsDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String method(final HttpServletRequest httpServletRequest) {
|
||||
return httpServletRequest.getMethod();
|
||||
|
|
|
@ -215,7 +215,6 @@ class FieldBackedProviderFieldInjectionDisabledTest extends AgentTestRunner {
|
|||
}
|
||||
|
||||
expect:
|
||||
Config.get().isPrioritySamplingEnabled() == false
|
||||
hasField == false
|
||||
hasMarkerInterface == false
|
||||
hasAccessorInterface == false
|
||||
|
|
|
@ -51,13 +51,11 @@ public class Config {
|
|||
public static final String TRACE_AGENT_PORT = "trace.agent.port";
|
||||
public static final String AGENT_PORT_LEGACY = "agent.port";
|
||||
public static final String AGENT_UNIX_DOMAIN_SOCKET = "trace.agent.unix.domain.socket";
|
||||
public static final String PRIORITY_SAMPLING = "priority.sampling";
|
||||
public static final String TRACE_RESOLVER_ENABLED = "trace.resolver.enabled";
|
||||
public static final String SERVICE_MAPPING = "service.mapping";
|
||||
public static final String GLOBAL_TAGS = "trace.global.tags";
|
||||
public static final String SPAN_TAGS = "trace.span.tags";
|
||||
public static final String JMX_TAGS = "trace.jmx.tags";
|
||||
public static final String TRACE_ANALYTICS_ENABLED = "trace.analytics.enabled";
|
||||
public static final String TRACE_ANNOTATIONS = "trace.annotations";
|
||||
public static final String TRACE_EXECUTORS_ALL = "trace.executors.all";
|
||||
public static final String TRACE_EXECUTORS = "trace.executors";
|
||||
|
@ -104,7 +102,6 @@ public class Config {
|
|||
|
||||
private static final boolean DEFAULT_RUNTIME_CONTEXT_FIELD_INJECTION = true;
|
||||
|
||||
private static final boolean DEFAULT_PRIORITY_SAMPLING_ENABLED = true;
|
||||
private static final boolean DEFAULT_TRACE_RESOLVER_ENABLED = true;
|
||||
private static final Set<Integer> DEFAULT_HTTP_SERVER_ERROR_STATUSES =
|
||||
parseIntegerRangeSet("500-599", "default");
|
||||
|
@ -131,8 +128,6 @@ public class Config {
|
|||
private static final boolean DEFAULT_TRACE_EXECUTORS_ALL = false;
|
||||
private static final String DEFAULT_TRACE_EXECUTORS = "";
|
||||
private static final String DEFAULT_TRACE_METHODS = null;
|
||||
public static final boolean DEFAULT_TRACE_ANALYTICS_ENABLED = false;
|
||||
public static final float DEFAULT_ANALYTICS_SAMPLE_RATE = 1.0f;
|
||||
|
||||
public enum PropagationStyle {
|
||||
DATADOG,
|
||||
|
@ -156,7 +151,6 @@ public class Config {
|
|||
@Getter private final String agentHost;
|
||||
@Getter private final int agentPort;
|
||||
@Getter private final String agentUnixDomainSocket;
|
||||
@Getter private final boolean prioritySamplingEnabled;
|
||||
@Getter private final boolean traceResolverEnabled;
|
||||
@Getter private final Map<String, String> serviceMapping;
|
||||
private final Map<String, String> globalTags;
|
||||
|
@ -191,8 +185,6 @@ public class Config {
|
|||
@Getter private final boolean traceExecutorsAll;
|
||||
@Getter private final List<String> traceExecutors;
|
||||
|
||||
@Getter private final boolean traceAnalyticsEnabled;
|
||||
|
||||
// Values from an optionally provided properties file
|
||||
private static Properties propertiesFromConfigFile;
|
||||
|
||||
|
@ -216,8 +208,6 @@ public class Config {
|
|||
getIntegerSettingFromEnvironment(AGENT_PORT_LEGACY, DEFAULT_TRACE_AGENT_PORT));
|
||||
agentUnixDomainSocket =
|
||||
getSettingFromEnvironment(AGENT_UNIX_DOMAIN_SOCKET, DEFAULT_AGENT_UNIX_DOMAIN_SOCKET);
|
||||
prioritySamplingEnabled =
|
||||
getBooleanSettingFromEnvironment(PRIORITY_SAMPLING, DEFAULT_PRIORITY_SAMPLING_ENABLED);
|
||||
traceResolverEnabled =
|
||||
getBooleanSettingFromEnvironment(TRACE_RESOLVER_ENABLED, DEFAULT_TRACE_RESOLVER_ENABLED);
|
||||
serviceMapping = getMapSettingFromEnvironment(SERVICE_MAPPING, null);
|
||||
|
@ -299,9 +289,6 @@ public class Config {
|
|||
|
||||
traceExecutors = getListSettingFromEnvironment(TRACE_EXECUTORS, DEFAULT_TRACE_EXECUTORS);
|
||||
|
||||
traceAnalyticsEnabled =
|
||||
getBooleanSettingFromEnvironment(TRACE_ANALYTICS_ENABLED, DEFAULT_TRACE_ANALYTICS_ENABLED);
|
||||
|
||||
log.debug("New instance: {}", this);
|
||||
}
|
||||
|
||||
|
@ -323,8 +310,6 @@ public class Config {
|
|||
getPropertyIntegerValue(properties, AGENT_PORT_LEGACY, parent.agentPort));
|
||||
agentUnixDomainSocket =
|
||||
properties.getProperty(AGENT_UNIX_DOMAIN_SOCKET, parent.agentUnixDomainSocket);
|
||||
prioritySamplingEnabled =
|
||||
getPropertyBooleanValue(properties, PRIORITY_SAMPLING, parent.prioritySamplingEnabled);
|
||||
traceResolverEnabled =
|
||||
getPropertyBooleanValue(properties, TRACE_RESOLVER_ENABLED, parent.traceResolverEnabled);
|
||||
serviceMapping = getPropertyMapValue(properties, SERVICE_MAPPING, parent.serviceMapping);
|
||||
|
@ -408,9 +393,6 @@ public class Config {
|
|||
getPropertyBooleanValue(properties, TRACE_EXECUTORS_ALL, parent.traceExecutorsAll);
|
||||
traceExecutors = getPropertyListValue(properties, TRACE_EXECUTORS, parent.traceExecutors);
|
||||
|
||||
traceAnalyticsEnabled =
|
||||
getPropertyBooleanValue(properties, TRACE_ANALYTICS_ENABLED, parent.traceAnalyticsEnabled);
|
||||
|
||||
log.debug("New instance: {}", this);
|
||||
}
|
||||
|
||||
|
@ -453,20 +435,6 @@ public class Config {
|
|||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sample rate for the specified instrumentation or {@link
|
||||
* #DEFAULT_ANALYTICS_SAMPLE_RATE} if none specified.
|
||||
*/
|
||||
public float getInstrumentationAnalyticsSampleRate(final String... aliases) {
|
||||
for (final String alias : aliases) {
|
||||
final Float rate = getFloatSettingFromEnvironment(alias + ".analytics.sample-rate", null);
|
||||
if (null != rate) {
|
||||
return rate;
|
||||
}
|
||||
}
|
||||
return DEFAULT_ANALYTICS_SAMPLE_RATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a map of tags required by the datadog backend to link runtime metrics (i.e. jmx) and
|
||||
* traces.
|
||||
|
@ -511,35 +479,6 @@ public class Config {
|
|||
return anyEnabled;
|
||||
}
|
||||
|
||||
public boolean isTraceAnalyticsIntegrationEnabled(
|
||||
final SortedSet<String> integrationNames, final boolean defaultEnabled) {
|
||||
return traceAnalyticsIntegrationEnabled(integrationNames, defaultEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should only be used internally. Use the instance getter instead {@link
|
||||
* #isTraceAnalyticsIntegrationEnabled(SortedSet, boolean)}.
|
||||
* @param integrationNames
|
||||
* @param defaultEnabled
|
||||
* @return
|
||||
*/
|
||||
public static boolean traceAnalyticsIntegrationEnabled(
|
||||
final SortedSet<String> integrationNames, final boolean defaultEnabled) {
|
||||
// If default is enabled, we want to enable individually,
|
||||
// if default is disabled, we want to disable individually.
|
||||
boolean anyEnabled = defaultEnabled;
|
||||
for (final String name : integrationNames) {
|
||||
final boolean configEnabled =
|
||||
getBooleanSettingFromEnvironment(name + ".analytics.enabled", defaultEnabled);
|
||||
if (defaultEnabled) {
|
||||
anyEnabled &= configEnabled;
|
||||
} else {
|
||||
anyEnabled |= configEnabled;
|
||||
}
|
||||
}
|
||||
return anyEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that takes the name, adds a "dd." prefix then checks for System Properties of
|
||||
* that name. If none found, the name is converted to an Environment Variable and used to check
|
||||
|
|
|
@ -16,12 +16,4 @@ public class DDTags {
|
|||
public static final String ERROR_MSG = "error.msg"; // string representing the error message
|
||||
public static final String ERROR_TYPE = "error.type"; // string representing the type of the error
|
||||
public static final String ERROR_STACK = "error.stack"; // human readable version of the stack
|
||||
|
||||
public static final String ANALYTICS_SAMPLE_RATE = "_dd1.sr.eausr";
|
||||
@Deprecated public static final String EVENT_SAMPLE_RATE = ANALYTICS_SAMPLE_RATE;
|
||||
|
||||
/** Manually force tracer to be keep the trace */
|
||||
public static final String MANUAL_KEEP = "manual.keep";
|
||||
/** Manually force tracer to be drop the trace */
|
||||
public static final String MANUAL_DROP = "manual.drop";
|
||||
}
|
||||
|
|
|
@ -22,18 +22,6 @@ public interface MutableSpan {
|
|||
|
||||
MutableSpan setResourceName(final String resourceName);
|
||||
|
||||
Integer getSamplingPriority();
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link io.opentracing.Span#setTag(String, boolean)} instead using either tag
|
||||
* names {@link datadog.trace.api.DDTags#MANUAL_KEEP} or {@link
|
||||
* datadog.trace.api.DDTags#MANUAL_DROP}.
|
||||
* @param newPriority
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
MutableSpan setSamplingPriority(final int newPriority);
|
||||
|
||||
String getSpanType();
|
||||
|
||||
MutableSpan setSpanType(final String type);
|
||||
|
|
|
@ -6,7 +6,7 @@ public interface TraceInterceptor {
|
|||
|
||||
/**
|
||||
* After a trace is "complete" but before it is written, it is provided to the interceptors to
|
||||
* modify. The result following all interceptors is sampled then sent to the trace writer.
|
||||
* modify. The result following all interceptors is then sent to the trace writer.
|
||||
*
|
||||
* @param trace - The collection of spans that represent a trace. Can be modified in place. Order
|
||||
* of spans should not be relied upon.
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package datadog.trace.api.sampling;
|
||||
|
||||
public class PrioritySampling {
|
||||
/**
|
||||
* Implementation detail of the client. will not be sent to the agent or propagated.
|
||||
*
|
||||
* <p>Internal value used when the priority sampling flag has not been set on the span context.
|
||||
*/
|
||||
public static final int UNSET = Integer.MIN_VALUE;
|
||||
/** The sampler has decided to drop the trace. */
|
||||
public static final int SAMPLER_DROP = 0;
|
||||
/** The sampler has decided to keep the trace. */
|
||||
public static final int SAMPLER_KEEP = 1;
|
||||
/** The user has decided to drop the trace. */
|
||||
public static final int USER_DROP = -1;
|
||||
/** The user has decided to keep the trace. */
|
||||
public static final int USER_KEEP = 2;
|
||||
|
||||
private PrioritySampling() {}
|
||||
}
|
|
@ -21,7 +21,6 @@ import static datadog.trace.api.Config.HTTP_SERVER_ERROR_STATUSES
|
|||
import static datadog.trace.api.Config.JMX_TAGS
|
||||
import static datadog.trace.api.Config.PARTIAL_FLUSH_MIN_SPANS
|
||||
import static datadog.trace.api.Config.PREFIX
|
||||
import static datadog.trace.api.Config.PRIORITY_SAMPLING
|
||||
import static datadog.trace.api.Config.PROPAGATION_STYLE_EXTRACT
|
||||
import static datadog.trace.api.Config.PROPAGATION_STYLE_INJECT
|
||||
import static datadog.trace.api.Config.RUNTIME_CONTEXT_FIELD_INJECTION
|
||||
|
@ -66,7 +65,6 @@ class ConfigTest extends DDSpecification {
|
|||
config.agentHost == "localhost"
|
||||
config.agentPort == 8126
|
||||
config.agentUnixDomainSocket == null
|
||||
config.prioritySamplingEnabled == true
|
||||
config.traceResolverEnabled == true
|
||||
config.serviceMapping == [:]
|
||||
config.mergedSpanTags == [:]
|
||||
|
@ -105,7 +103,6 @@ class ConfigTest extends DDSpecification {
|
|||
prop.setProperty(TRACE_AGENT_PORT, "123")
|
||||
prop.setProperty(AGENT_UNIX_DOMAIN_SOCKET, "somepath")
|
||||
prop.setProperty(AGENT_PORT_LEGACY, "456")
|
||||
prop.setProperty(PRIORITY_SAMPLING, "false")
|
||||
prop.setProperty(TRACE_RESOLVER_ENABLED, "false")
|
||||
prop.setProperty(SERVICE_MAPPING, "a:1")
|
||||
prop.setProperty(GLOBAL_TAGS, "b:2")
|
||||
|
@ -136,7 +133,6 @@ class ConfigTest extends DDSpecification {
|
|||
config.agentHost == "somehost"
|
||||
config.agentPort == 123
|
||||
config.agentUnixDomainSocket == "somepath"
|
||||
config.prioritySamplingEnabled == false
|
||||
config.traceResolverEnabled == false
|
||||
config.serviceMapping == [a: "1"]
|
||||
config.mergedSpanTags == [b: "2", c: "3"]
|
||||
|
@ -166,7 +162,6 @@ class ConfigTest extends DDSpecification {
|
|||
System.setProperty(PREFIX + TRACE_AGENT_PORT, "123")
|
||||
System.setProperty(PREFIX + AGENT_UNIX_DOMAIN_SOCKET, "somepath")
|
||||
System.setProperty(PREFIX + AGENT_PORT_LEGACY, "456")
|
||||
System.setProperty(PREFIX + PRIORITY_SAMPLING, "false")
|
||||
System.setProperty(PREFIX + TRACE_RESOLVER_ENABLED, "false")
|
||||
System.setProperty(PREFIX + SERVICE_MAPPING, "a:1")
|
||||
System.setProperty(PREFIX + GLOBAL_TAGS, "b:2")
|
||||
|
@ -197,7 +192,6 @@ class ConfigTest extends DDSpecification {
|
|||
config.agentHost == "somehost"
|
||||
config.agentPort == 123
|
||||
config.agentUnixDomainSocket == "somepath"
|
||||
config.prioritySamplingEnabled == false
|
||||
config.traceResolverEnabled == false
|
||||
config.serviceMapping == [a: "1"]
|
||||
config.mergedSpanTags == [b: "2", c: "3"]
|
||||
|
@ -268,7 +262,6 @@ class ConfigTest extends DDSpecification {
|
|||
System.setProperty(PREFIX + AGENT_HOST, " ")
|
||||
System.setProperty(PREFIX + TRACE_AGENT_PORT, " ")
|
||||
System.setProperty(PREFIX + AGENT_PORT_LEGACY, "invalid")
|
||||
System.setProperty(PREFIX + PRIORITY_SAMPLING, "3")
|
||||
System.setProperty(PREFIX + TRACE_RESOLVER_ENABLED, " ")
|
||||
System.setProperty(PREFIX + SERVICE_MAPPING, " ")
|
||||
System.setProperty(PREFIX + HEADER_TAGS, "1")
|
||||
|
@ -289,7 +282,6 @@ class ConfigTest extends DDSpecification {
|
|||
config.writerType == " "
|
||||
config.agentHost == " "
|
||||
config.agentPort == 8126
|
||||
config.prioritySamplingEnabled == false
|
||||
config.traceResolverEnabled == true
|
||||
config.serviceMapping == [:]
|
||||
config.mergedSpanTags == [:]
|
||||
|
@ -354,7 +346,6 @@ class ConfigTest extends DDSpecification {
|
|||
properties.setProperty(AGENT_HOST, "somehost")
|
||||
properties.setProperty(TRACE_AGENT_PORT, "123")
|
||||
properties.setProperty(AGENT_UNIX_DOMAIN_SOCKET, "somepath")
|
||||
properties.setProperty(PRIORITY_SAMPLING, "false")
|
||||
properties.setProperty(TRACE_RESOLVER_ENABLED, "false")
|
||||
properties.setProperty(SERVICE_MAPPING, "a:1")
|
||||
properties.setProperty(GLOBAL_TAGS, "b:2")
|
||||
|
@ -379,7 +370,6 @@ class ConfigTest extends DDSpecification {
|
|||
config.agentHost == "somehost"
|
||||
config.agentPort == 123
|
||||
config.agentUnixDomainSocket == "somepath"
|
||||
config.prioritySamplingEnabled == false
|
||||
config.traceResolverEnabled == false
|
||||
config.serviceMapping == [a: "1"]
|
||||
config.mergedSpanTags == [b: "2", c: "3"]
|
||||
|
@ -463,40 +453,6 @@ class ConfigTest extends DDSpecification {
|
|||
integrationNames = new TreeSet<>(names)
|
||||
}
|
||||
|
||||
def "verify integration trace analytics config"() {
|
||||
setup:
|
||||
environmentVariables.set("DD_ORDER_ANALYTICS_ENABLED", "false")
|
||||
environmentVariables.set("DD_TEST_ENV_ANALYTICS_ENABLED", "true")
|
||||
environmentVariables.set("DD_DISABLED_ENV_ANALYTICS_ENABLED", "false")
|
||||
|
||||
System.setProperty("dd.order.analytics.enabled", "true")
|
||||
System.setProperty("dd.test-prop.analytics.enabled", "true")
|
||||
System.setProperty("dd.disabled-prop.analytics.enabled", "false")
|
||||
|
||||
expect:
|
||||
Config.get().isTraceAnalyticsIntegrationEnabled(integrationNames, defaultEnabled) == expected
|
||||
|
||||
where:
|
||||
names | defaultEnabled | expected
|
||||
[] | true | true
|
||||
[] | false | false
|
||||
["invalid"] | true | true
|
||||
["invalid"] | false | false
|
||||
["test-prop"] | false | true
|
||||
["test-env"] | false | true
|
||||
["disabled-prop"] | true | false
|
||||
["disabled-env"] | true | false
|
||||
["other", "test-prop"] | false | true
|
||||
["other", "test-env"] | false | true
|
||||
["order"] | false | true
|
||||
["test-prop", "disabled-prop"] | false | true
|
||||
["disabled-env", "test-env"] | false | true
|
||||
["test-prop", "disabled-prop"] | true | false
|
||||
["disabled-env", "test-env"] | true | false
|
||||
|
||||
integrationNames = new TreeSet<>(names)
|
||||
}
|
||||
|
||||
def "test getFloatSettingFromEnvironment(#name)"() {
|
||||
setup:
|
||||
environmentVariables.set("DD_ENV_ZERO_TEST", "0.0")
|
||||
|
|
|
@ -8,11 +8,10 @@ apply from: "${rootDir}/gradle/java.gradle"
|
|||
apply from: "${rootDir}/gradle/publish.gradle"
|
||||
|
||||
minimumBranchCoverage = 0.5
|
||||
minimumInstructionCoverage = 0.6
|
||||
minimumInstructionCoverage = 0.5
|
||||
excludedClassesCoverage += [
|
||||
'datadog.trace.common.writer.ListWriter',
|
||||
'datadog.trace.common.writer.LoggingWriter',
|
||||
'datadog.trace.common.sampling.PrioritySampling',
|
||||
// This code is copied from okHttp samples and we have integration tests to verify that it works.
|
||||
'datadog.trace.common.writer.unixdomainsockets.TunnelingUnixSocket',
|
||||
'datadog.trace.common.writer.unixdomainsockets.UnixDomainSocketFactory'
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.fasterxml.jackson.annotation.JsonGetter;
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.api.interceptor.MutableSpan;
|
||||
import datadog.trace.api.sampling.PrioritySampling;
|
||||
import datadog.trace.common.util.Clock;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.tag.Tag;
|
||||
|
@ -276,17 +275,6 @@ public class DDSpan implements Span, MutableSpan {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sampling priority of the root span of this span's trace
|
||||
*
|
||||
* <p>Has no effect if the span priority has been propagated (injected or extracted).
|
||||
*/
|
||||
@Override
|
||||
public final DDSpan setSamplingPriority(final int newPriority) {
|
||||
context().setSamplingPriority(newPriority);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DDSpan setSpanType(final String type) {
|
||||
context().setSpanType(type);
|
||||
|
@ -367,17 +355,6 @@ public class DDSpan implements Span, MutableSpan {
|
|||
return context.getOperationName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Integer getSamplingPriority() {
|
||||
final int samplingPriority = context.getSamplingPriority();
|
||||
if (samplingPriority == PrioritySampling.UNSET) {
|
||||
return null;
|
||||
} else {
|
||||
return samplingPriority;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public String getSpanType() {
|
||||
|
|
|
@ -3,7 +3,6 @@ package datadog.opentracing;
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import datadog.opentracing.decorators.AbstractDecorator;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.api.sampling.PrioritySampling;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -23,8 +22,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
*/
|
||||
@Slf4j
|
||||
public class DDSpanContext implements io.opentracing.SpanContext {
|
||||
public static final String PRIORITY_SAMPLING_KEY = "_sampling_priority_v1";
|
||||
public static final String SAMPLE_RATE_KEY = "_sample_rate";
|
||||
public static final String ORIGIN_KEY = "_dd.origin";
|
||||
|
||||
private static final Map<String, Number> EMPTY_METRICS = Collections.emptyMap();
|
||||
|
@ -57,13 +54,6 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
private volatile String spanType;
|
||||
/** True indicates that the span reports an error */
|
||||
private volatile boolean errorFlag;
|
||||
/**
|
||||
* When true, the samplingPriority cannot be changed. This prevents the sampling flag from
|
||||
* changing after the context has propagated.
|
||||
*
|
||||
* <p>For thread safety, this boolean is only modified or accessed under instance lock.
|
||||
*/
|
||||
private boolean samplingPriorityLocked = false;
|
||||
/** The origin of the trace. (eg. Synthetics) */
|
||||
private final String origin;
|
||||
/** Metrics on the span */
|
||||
|
@ -80,7 +70,6 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
final String serviceName,
|
||||
final String operationName,
|
||||
final String resourceName,
|
||||
final int samplingPriority,
|
||||
final String origin,
|
||||
final Map<String, String> baggageItems,
|
||||
final boolean errorFlag,
|
||||
|
@ -118,10 +107,6 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
this.spanType = spanType;
|
||||
this.origin = origin;
|
||||
|
||||
if (samplingPriority != PrioritySampling.UNSET) {
|
||||
setSamplingPriority(samplingPriority);
|
||||
}
|
||||
|
||||
if (origin != null) {
|
||||
this.tags.put(ORIGIN_KEY, origin);
|
||||
}
|
||||
|
@ -191,73 +176,6 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
this.spanType = spanType;
|
||||
}
|
||||
|
||||
public void setSamplingPriority(final int newPriority) {
|
||||
if (trace != null) {
|
||||
final DDSpan rootSpan = trace.getRootSpan();
|
||||
if (null != rootSpan && rootSpan.context() != this) {
|
||||
rootSpan.context().setSamplingPriority(newPriority);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (newPriority == PrioritySampling.UNSET) {
|
||||
log.debug("{}: Refusing to set samplingPriority to UNSET", this);
|
||||
return;
|
||||
}
|
||||
// sync with lockSamplingPriority
|
||||
synchronized (this) {
|
||||
if (samplingPriorityLocked) {
|
||||
log.debug(
|
||||
"samplingPriority locked at {}. Refusing to set to {}",
|
||||
getMetrics().get(PRIORITY_SAMPLING_KEY),
|
||||
newPriority);
|
||||
} else {
|
||||
setMetric(PRIORITY_SAMPLING_KEY, newPriority);
|
||||
log.debug("Set sampling priority to {}", getMetrics().get(PRIORITY_SAMPLING_KEY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @return the sampling priority of this span's trace, or null if no priority has been set */
|
||||
public int getSamplingPriority() {
|
||||
if (trace != null) {
|
||||
final DDSpan rootSpan = trace.getRootSpan();
|
||||
if (null != rootSpan && rootSpan.context() != this) {
|
||||
return rootSpan.context().getSamplingPriority();
|
||||
}
|
||||
}
|
||||
final Number val = getMetrics().get(PRIORITY_SAMPLING_KEY);
|
||||
return null == val ? PrioritySampling.UNSET : val.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent future changes to the context's sampling priority.
|
||||
*
|
||||
* <p>Used when a span is extracted or injected for propagation.
|
||||
*
|
||||
* <p>Has no effect if the sampling priority is unset.
|
||||
*
|
||||
* @return true if the sampling priority was locked.
|
||||
*/
|
||||
public boolean lockSamplingPriority() {
|
||||
if (trace != null) {
|
||||
final DDSpan rootSpan = trace.getRootSpan();
|
||||
if (null != rootSpan && rootSpan.context() != this) {
|
||||
return rootSpan.context().lockSamplingPriority();
|
||||
}
|
||||
}
|
||||
// sync with setSamplingPriority
|
||||
synchronized (this) {
|
||||
if (getMetrics().get(PRIORITY_SAMPLING_KEY) == null) {
|
||||
log.debug("{} : refusing to lock unset samplingPriority", this);
|
||||
} else if (samplingPriorityLocked == false) {
|
||||
samplingPriorityLocked = true;
|
||||
log.debug(
|
||||
"{} : locked samplingPriority to {}", this, getMetrics().get(PRIORITY_SAMPLING_KEY));
|
||||
}
|
||||
return samplingPriorityLocked;
|
||||
}
|
||||
}
|
||||
|
||||
public String getOrigin() {
|
||||
final DDSpan rootSpan = trace.getRootSpan();
|
||||
if (null != rootSpan) {
|
||||
|
|
|
@ -10,11 +10,6 @@ import datadog.opentracing.scopemanager.ScopeContext;
|
|||
import datadog.trace.api.Config;
|
||||
import datadog.trace.api.interceptor.MutableSpan;
|
||||
import datadog.trace.api.interceptor.TraceInterceptor;
|
||||
import datadog.trace.api.sampling.PrioritySampling;
|
||||
import datadog.trace.common.sampling.RateByServiceSampler;
|
||||
import datadog.trace.common.sampling.Sampler;
|
||||
import datadog.trace.common.writer.DDAgentWriter;
|
||||
import datadog.trace.common.writer.DDApi;
|
||||
import datadog.trace.common.writer.Writer;
|
||||
import datadog.trace.context.ScopeListener;
|
||||
import io.opentracing.References;
|
||||
|
@ -58,8 +53,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
final String serviceName;
|
||||
/** Writer is an charge of reporting traces and spans to the desired endpoint */
|
||||
final Writer writer;
|
||||
/** Sampler defines the sampling policy in order to reduce the number of traces for instance */
|
||||
final Sampler sampler;
|
||||
/** Scope manager is in charge of managing the scopes from which spans are created */
|
||||
final ContextualScopeManager scopeManager = new ContextualScopeManager();
|
||||
|
||||
|
@ -113,15 +106,14 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
}
|
||||
|
||||
// This constructor is already used in the wild, so we have to keep it inside this API for now.
|
||||
public DDTracer(final String serviceName, final Writer writer, final Sampler sampler) {
|
||||
this(serviceName, writer, sampler, Config.get().getLocalRootSpanTags());
|
||||
public DDTracer(final String serviceName, final Writer writer) {
|
||||
this(serviceName, writer, Config.get().getLocalRootSpanTags());
|
||||
}
|
||||
|
||||
private DDTracer(final String serviceName, final Config config) {
|
||||
this(
|
||||
serviceName,
|
||||
Writer.Builder.forConfig(config),
|
||||
Sampler.Builder.forConfig(config),
|
||||
config.getLocalRootSpanTags(),
|
||||
config.getMergedSpanTags(),
|
||||
config.getServiceMapping(),
|
||||
|
@ -131,15 +123,10 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
}
|
||||
|
||||
/** Visible for testing */
|
||||
DDTracer(
|
||||
final String serviceName,
|
||||
final Writer writer,
|
||||
final Sampler sampler,
|
||||
final Map<String, String> runtimeTags) {
|
||||
DDTracer(final String serviceName, final Writer writer, final Map<String, String> runtimeTags) {
|
||||
this(
|
||||
serviceName,
|
||||
writer,
|
||||
sampler,
|
||||
runtimeTags,
|
||||
Collections.<String, String>emptyMap(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
|
@ -155,7 +142,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
this(
|
||||
config.getServiceName(),
|
||||
writer,
|
||||
Sampler.Builder.forConfig(config),
|
||||
config.getLocalRootSpanTags(),
|
||||
config.getMergedSpanTags(),
|
||||
config.getServiceMapping(),
|
||||
|
@ -163,14 +149,11 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
config.getPartialFlushMinSpans());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #DDTracer(String, Writer, Sampler, Map, Map, Map, Map, int)} instead.
|
||||
*/
|
||||
/** @deprecated Use {@link #DDTracer(String, Writer, Map, Map, Map, Map, int)} instead. */
|
||||
@Deprecated
|
||||
public DDTracer(
|
||||
final String serviceName,
|
||||
final Writer writer,
|
||||
final Sampler sampler,
|
||||
final String runtimeId,
|
||||
final Map<String, String> localRootSpanTags,
|
||||
final Map<String, String> defaultSpanTags,
|
||||
|
@ -179,7 +162,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
this(
|
||||
serviceName,
|
||||
writer,
|
||||
sampler,
|
||||
customRuntimeTags(runtimeId, localRootSpanTags),
|
||||
defaultSpanTags,
|
||||
serviceNameMappings,
|
||||
|
@ -187,14 +169,11 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
Config.get().getPartialFlushMinSpans());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #DDTracer(String, Writer, Sampler, Map, Map, Map, Map, int)} instead.
|
||||
*/
|
||||
/** @deprecated Use {@link #DDTracer(String, Writer, Map, Map, Map, Map, int)} instead. */
|
||||
@Deprecated
|
||||
public DDTracer(
|
||||
final String serviceName,
|
||||
final Writer writer,
|
||||
final Sampler sampler,
|
||||
final Map<String, String> localRootSpanTags,
|
||||
final Map<String, String> defaultSpanTags,
|
||||
final Map<String, String> serviceNameMappings,
|
||||
|
@ -202,7 +181,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
this(
|
||||
serviceName,
|
||||
writer,
|
||||
sampler,
|
||||
localRootSpanTags,
|
||||
defaultSpanTags,
|
||||
serviceNameMappings,
|
||||
|
@ -213,7 +191,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
public DDTracer(
|
||||
final String serviceName,
|
||||
final Writer writer,
|
||||
final Sampler sampler,
|
||||
final Map<String, String> localRootSpanTags,
|
||||
final Map<String, String> defaultSpanTags,
|
||||
final Map<String, String> serviceNameMappings,
|
||||
|
@ -227,7 +204,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
this.serviceName = serviceName;
|
||||
this.writer = writer;
|
||||
this.writer.start();
|
||||
this.sampler = sampler;
|
||||
this.localRootSpanTags = localRootSpanTags;
|
||||
this.defaultSpanTags = defaultSpanTags;
|
||||
this.serviceNameMappings = serviceNameMappings;
|
||||
|
@ -244,13 +220,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
injector = HttpCodec.createInjector(Config.get());
|
||||
extractor = HttpCodec.createExtractor(Config.get(), taggedHeaders);
|
||||
|
||||
if (this.writer instanceof DDAgentWriter) {
|
||||
final DDApi api = ((DDAgentWriter) this.writer).getApi();
|
||||
if (sampler instanceof DDApi.ResponseListener) {
|
||||
api.addResponseListener((DDApi.ResponseListener) this.sampler);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("New instance: {}", this);
|
||||
|
||||
final List<AbstractDecorator> decorators = DDDecoratorsFactory.createBuiltinDecorators();
|
||||
|
@ -363,12 +332,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We use the sampler to know if the trace has to be reported/written. The sampler is called on
|
||||
* the first span (root span) of the trace. If the trace is marked as a sample, we report it.
|
||||
*
|
||||
* @param trace a list of the spans related to the same trace
|
||||
*/
|
||||
/** @param trace a list of the spans related to the same trace */
|
||||
void write(final Collection<DDSpan> trace) {
|
||||
if (trace.isEmpty()) {
|
||||
return;
|
||||
|
@ -391,7 +355,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
incrementTraceCount();
|
||||
// TODO: current trace implementation doesn't guarantee that first span is the root span
|
||||
// We may want to reconsider way this check is done.
|
||||
if (!writtenTrace.isEmpty() && sampler.sample(writtenTrace.get(0))) {
|
||||
if (!writtenTrace.isEmpty()) {
|
||||
writer.write(writtenTrace);
|
||||
}
|
||||
}
|
||||
|
@ -443,8 +407,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
+ serviceName
|
||||
+ ", writer="
|
||||
+ writer
|
||||
+ ", sampler="
|
||||
+ sampler
|
||||
+ ", defaultSpanTags="
|
||||
+ defaultSpanTags
|
||||
+ '}';
|
||||
|
@ -487,11 +449,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
}
|
||||
|
||||
private DDSpan startSpan() {
|
||||
final DDSpan span = new DDSpan(timestampMicro, buildSpanContext());
|
||||
if (sampler instanceof RateByServiceSampler) {
|
||||
((RateByServiceSampler) sampler).initializeSamplingPriority(span);
|
||||
}
|
||||
return span;
|
||||
return new DDSpan(timestampMicro, buildSpanContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -632,7 +590,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
final BigInteger parentSpanId;
|
||||
final Map<String, String> baggage;
|
||||
final PendingTrace parentTrace;
|
||||
final int samplingPriority;
|
||||
final String origin;
|
||||
|
||||
final DDSpanContext context;
|
||||
|
@ -654,7 +611,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
parentSpanId = ddsc.getSpanId();
|
||||
baggage = ddsc.getBaggageItems();
|
||||
parentTrace = ddsc.getTrace();
|
||||
samplingPriority = PrioritySampling.UNSET;
|
||||
origin = null;
|
||||
if (serviceName == null) {
|
||||
serviceName = ddsc.getServiceName();
|
||||
|
@ -666,13 +622,11 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
final ExtractedContext extractedContext = (ExtractedContext) parentContext;
|
||||
traceId = extractedContext.getTraceId();
|
||||
parentSpanId = extractedContext.getSpanId();
|
||||
samplingPriority = extractedContext.getSamplingPriority();
|
||||
baggage = extractedContext.getBaggage();
|
||||
} else {
|
||||
// Start a new trace
|
||||
traceId = generateNewId();
|
||||
parentSpanId = BigInteger.ZERO;
|
||||
samplingPriority = PrioritySampling.UNSET;
|
||||
baggage = null;
|
||||
}
|
||||
|
||||
|
@ -704,7 +658,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
|
|||
serviceName,
|
||||
operationName,
|
||||
resourceName,
|
||||
samplingPriority,
|
||||
origin,
|
||||
baggage,
|
||||
errorFlag,
|
||||
|
|
|
@ -48,8 +48,7 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
|
|||
// We must maintain a separate count because ConcurrentLinkedDeque.size() is a linear operation.
|
||||
private final AtomicInteger completedSpanCount = new AtomicInteger(0);
|
||||
/**
|
||||
* During a trace there are cases where the root span must be accessed (e.g. priority sampling and
|
||||
* trace-search tags).
|
||||
* During a trace there are cases where the root span must be accessed (e.g. trace-search tags).
|
||||
*
|
||||
* <p>Use a weak ref because we still need to handle buggy cases where the root span is not
|
||||
* correctly closed (see SpanCleaner).
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package datadog.opentracing.decorators;
|
||||
|
||||
import datadog.opentracing.DDSpanContext;
|
||||
import datadog.trace.api.DDTags;
|
||||
|
||||
public class AnalyticsSampleRateDecorator extends AbstractDecorator {
|
||||
public AnalyticsSampleRateDecorator() {
|
||||
super();
|
||||
setMatchingTag(DDTags.ANALYTICS_SAMPLE_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSetTag(final DDSpanContext context, final String tag, final Object value) {
|
||||
if (value instanceof Number) {
|
||||
context.setMetric(DDTags.ANALYTICS_SAMPLE_RATE, (Number) value);
|
||||
} else if (value instanceof String) {
|
||||
try {
|
||||
context.setMetric(DDTags.ANALYTICS_SAMPLE_RATE, Double.parseDouble((String) value));
|
||||
} catch (final NumberFormatException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -12,12 +12,9 @@ public class DDDecoratorsFactory {
|
|||
final List<AbstractDecorator> decorators =
|
||||
new ArrayList<>(
|
||||
Arrays.asList(
|
||||
new AnalyticsSampleRateDecorator(),
|
||||
new DBStatementAsResourceName(),
|
||||
new DBTypeDecorator(),
|
||||
new ErrorFlag(),
|
||||
new ForceManualDropDecorator(),
|
||||
new ForceManualKeepDecorator(),
|
||||
new OperationDecorator(),
|
||||
new PeerServiceDecorator(),
|
||||
new ResourceNameDecorator(),
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package datadog.opentracing.decorators;
|
||||
|
||||
import datadog.opentracing.DDSpanContext;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.api.sampling.PrioritySampling;
|
||||
|
||||
/**
|
||||
* Tag decorator to replace tag 'manual.drop: true' with the appropriate priority sampling value.
|
||||
*/
|
||||
public class ForceManualDropDecorator extends AbstractDecorator {
|
||||
|
||||
public ForceManualDropDecorator() {
|
||||
super();
|
||||
setMatchingTag(DDTags.MANUAL_DROP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSetTag(final DDSpanContext context, final String tag, final Object value) {
|
||||
if (value instanceof Boolean && (boolean) value) {
|
||||
context.setSamplingPriority(PrioritySampling.USER_DROP);
|
||||
} else if (value instanceof String && Boolean.parseBoolean((String) value)) {
|
||||
context.setSamplingPriority(PrioritySampling.USER_DROP);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package datadog.opentracing.decorators;
|
||||
|
||||
import datadog.opentracing.DDSpanContext;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.api.sampling.PrioritySampling;
|
||||
|
||||
/**
|
||||
* Tag decorator to replace tag 'manual.keep: true' with the appropriate priority sampling value.
|
||||
*/
|
||||
public class ForceManualKeepDecorator extends AbstractDecorator {
|
||||
|
||||
public ForceManualKeepDecorator() {
|
||||
super();
|
||||
setMatchingTag(DDTags.MANUAL_KEEP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSetTag(final DDSpanContext context, final String tag, final Object value) {
|
||||
if (value instanceof Boolean && (boolean) value) {
|
||||
context.setSamplingPriority(PrioritySampling.USER_KEEP);
|
||||
} else if (value instanceof String && Boolean.parseBoolean((String) value)) {
|
||||
context.setSamplingPriority(PrioritySampling.USER_KEEP);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package datadog.opentracing.propagation;
|
|||
import static datadog.opentracing.propagation.HttpCodec.validateUInt64BitsID;
|
||||
|
||||
import datadog.opentracing.DDSpanContext;
|
||||
import datadog.trace.api.sampling.PrioritySampling;
|
||||
import io.opentracing.SpanContext;
|
||||
import io.opentracing.propagation.TextMapExtract;
|
||||
import io.opentracing.propagation.TextMapInject;
|
||||
|
@ -25,9 +24,6 @@ class B3HttpCodec {
|
|||
|
||||
private static final String TRACE_ID_KEY = "X-B3-TraceId";
|
||||
private static final String SPAN_ID_KEY = "X-B3-SpanId";
|
||||
private static final String SAMPLING_PRIORITY_KEY = "X-B3-Sampled";
|
||||
private static final String SAMPLING_PRIORITY_ACCEPT = String.valueOf(1);
|
||||
private static final String SAMPLING_PRIORITY_DROP = String.valueOf(0);
|
||||
private static final int HEX_RADIX = 16;
|
||||
|
||||
private B3HttpCodec() {
|
||||
|
@ -41,21 +37,12 @@ class B3HttpCodec {
|
|||
try {
|
||||
carrier.put(TRACE_ID_KEY, context.getTraceId().toString(HEX_RADIX).toLowerCase());
|
||||
carrier.put(SPAN_ID_KEY, context.getSpanId().toString(HEX_RADIX).toLowerCase());
|
||||
|
||||
if (context.lockSamplingPriority()) {
|
||||
carrier.put(
|
||||
SAMPLING_PRIORITY_KEY, convertSamplingPriority(context.getSamplingPriority()));
|
||||
}
|
||||
log.debug("{} - B3 parent context injected", context.getTraceId());
|
||||
} catch (final NumberFormatException e) {
|
||||
log.debug(
|
||||
"Cannot parse context id(s): {} {}", context.getTraceId(), context.getSpanId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private String convertSamplingPriority(final int samplingPriority) {
|
||||
return samplingPriority > 0 ? SAMPLING_PRIORITY_ACCEPT : SAMPLING_PRIORITY_DROP;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Extractor implements HttpCodec.Extractor {
|
||||
|
@ -75,7 +62,6 @@ class B3HttpCodec {
|
|||
Map<String, String> tags = Collections.emptyMap();
|
||||
BigInteger traceId = BigInteger.ZERO;
|
||||
BigInteger spanId = BigInteger.ZERO;
|
||||
int samplingPriority = PrioritySampling.UNSET;
|
||||
|
||||
for (final Map.Entry<String, String> entry : carrier) {
|
||||
final String key = entry.getKey().toLowerCase();
|
||||
|
@ -100,8 +86,6 @@ class B3HttpCodec {
|
|||
traceId = validateUInt64BitsID(trimmedValue, HEX_RADIX);
|
||||
} else if (SPAN_ID_KEY.equalsIgnoreCase(key)) {
|
||||
spanId = validateUInt64BitsID(value, HEX_RADIX);
|
||||
} else if (SAMPLING_PRIORITY_KEY.equalsIgnoreCase(key)) {
|
||||
samplingPriority = convertSamplingPriority(value);
|
||||
}
|
||||
|
||||
if (taggedHeaders.containsKey(key)) {
|
||||
|
@ -115,13 +99,7 @@ class B3HttpCodec {
|
|||
if (!BigInteger.ZERO.equals(traceId)) {
|
||||
final ExtractedContext context =
|
||||
new ExtractedContext(
|
||||
traceId,
|
||||
spanId,
|
||||
samplingPriority,
|
||||
null,
|
||||
Collections.<String, String>emptyMap(),
|
||||
tags);
|
||||
context.lockSamplingPriority();
|
||||
traceId, spanId, null, Collections.<String, String>emptyMap(), tags);
|
||||
|
||||
log.debug("{} - Parent context extracted", context.getTraceId());
|
||||
return context;
|
||||
|
@ -135,11 +113,5 @@ class B3HttpCodec {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int convertSamplingPriority(final String samplingPriority) {
|
||||
return Integer.parseInt(samplingPriority) == 1
|
||||
? PrioritySampling.SAMPLER_KEEP
|
||||
: PrioritySampling.SAMPLER_DROP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package datadog.opentracing.propagation;
|
|||
import static datadog.opentracing.propagation.HttpCodec.validateUInt64BitsID;
|
||||
|
||||
import datadog.opentracing.DDSpanContext;
|
||||
import datadog.trace.api.sampling.PrioritySampling;
|
||||
import io.opentracing.SpanContext;
|
||||
import io.opentracing.propagation.TextMapExtract;
|
||||
import io.opentracing.propagation.TextMapInject;
|
||||
|
@ -20,7 +19,6 @@ class DatadogHttpCodec {
|
|||
private static final String OT_BAGGAGE_PREFIX = "ot-baggage-";
|
||||
private static final String TRACE_ID_KEY = "x-datadog-trace-id";
|
||||
private static final String SPAN_ID_KEY = "x-datadog-parent-id";
|
||||
private static final String SAMPLING_PRIORITY_KEY = "x-datadog-sampling-priority";
|
||||
private static final String ORIGIN_KEY = "x-datadog-origin";
|
||||
|
||||
private DatadogHttpCodec() {
|
||||
|
@ -33,9 +31,6 @@ class DatadogHttpCodec {
|
|||
public void inject(final DDSpanContext context, final TextMapInject carrier) {
|
||||
carrier.put(TRACE_ID_KEY, context.getTraceId().toString());
|
||||
carrier.put(SPAN_ID_KEY, context.getSpanId().toString());
|
||||
if (context.lockSamplingPriority()) {
|
||||
carrier.put(SAMPLING_PRIORITY_KEY, String.valueOf(context.getSamplingPriority()));
|
||||
}
|
||||
final String origin = context.getOrigin();
|
||||
if (origin != null) {
|
||||
carrier.put(ORIGIN_KEY, origin);
|
||||
|
@ -65,7 +60,6 @@ class DatadogHttpCodec {
|
|||
Map<String, String> tags = Collections.emptyMap();
|
||||
BigInteger traceId = BigInteger.ZERO;
|
||||
BigInteger spanId = BigInteger.ZERO;
|
||||
int samplingPriority = PrioritySampling.UNSET;
|
||||
String origin = null;
|
||||
|
||||
for (final Map.Entry<String, String> entry : carrier) {
|
||||
|
@ -80,8 +74,6 @@ class DatadogHttpCodec {
|
|||
traceId = validateUInt64BitsID(value, 10);
|
||||
} else if (SPAN_ID_KEY.equalsIgnoreCase(key)) {
|
||||
spanId = validateUInt64BitsID(value, 10);
|
||||
} else if (SAMPLING_PRIORITY_KEY.equalsIgnoreCase(key)) {
|
||||
samplingPriority = Integer.parseInt(value);
|
||||
} else if (ORIGIN_KEY.equalsIgnoreCase(key)) {
|
||||
origin = value;
|
||||
} else if (key.startsWith(OT_BAGGAGE_PREFIX)) {
|
||||
|
@ -101,8 +93,7 @@ class DatadogHttpCodec {
|
|||
|
||||
if (!BigInteger.ZERO.equals(traceId)) {
|
||||
final ExtractedContext context =
|
||||
new ExtractedContext(traceId, spanId, samplingPriority, origin, baggage, tags);
|
||||
context.lockSamplingPriority();
|
||||
new ExtractedContext(traceId, spanId, origin, baggage, tags);
|
||||
|
||||
log.debug("{} - Parent context extracted", context.getTraceId());
|
||||
return context;
|
||||
|
|
|
@ -2,7 +2,6 @@ package datadog.opentracing.propagation;
|
|||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Propagated data resulting from calling tracer.extract with header data from an incoming request.
|
||||
|
@ -10,21 +9,17 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
public class ExtractedContext extends TagContext {
|
||||
private final BigInteger traceId;
|
||||
private final BigInteger spanId;
|
||||
private final int samplingPriority;
|
||||
private final Map<String, String> baggage;
|
||||
private final AtomicBoolean samplingPriorityLocked = new AtomicBoolean(false);
|
||||
|
||||
public ExtractedContext(
|
||||
final BigInteger traceId,
|
||||
final BigInteger spanId,
|
||||
final int samplingPriority,
|
||||
final String origin,
|
||||
final Map<String, String> baggage,
|
||||
final Map<String, String> tags) {
|
||||
super(origin, tags);
|
||||
this.traceId = traceId;
|
||||
this.spanId = spanId;
|
||||
this.samplingPriority = samplingPriority;
|
||||
this.baggage = baggage;
|
||||
}
|
||||
|
||||
|
@ -33,10 +28,6 @@ public class ExtractedContext extends TagContext {
|
|||
return baggage.entrySet();
|
||||
}
|
||||
|
||||
public void lockSamplingPriority() {
|
||||
samplingPriorityLocked.set(true);
|
||||
}
|
||||
|
||||
public BigInteger getTraceId() {
|
||||
return traceId;
|
||||
}
|
||||
|
@ -45,15 +36,7 @@ public class ExtractedContext extends TagContext {
|
|||
return spanId;
|
||||
}
|
||||
|
||||
public int getSamplingPriority() {
|
||||
return samplingPriority;
|
||||
}
|
||||
|
||||
public Map<String, String> getBaggage() {
|
||||
return baggage;
|
||||
}
|
||||
|
||||
public boolean getSamplingPriorityLocked() {
|
||||
return samplingPriorityLocked.get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package datadog.opentracing.propagation;
|
|||
import static datadog.opentracing.propagation.HttpCodec.validateUInt64BitsID;
|
||||
|
||||
import datadog.opentracing.DDSpanContext;
|
||||
import datadog.trace.api.sampling.PrioritySampling;
|
||||
import io.opentracing.SpanContext;
|
||||
import io.opentracing.propagation.TextMapExtract;
|
||||
import io.opentracing.propagation.TextMapInject;
|
||||
|
@ -63,7 +62,6 @@ public class HaystackHttpCodec {
|
|||
Map<String, String> tags = Collections.emptyMap();
|
||||
BigInteger traceId = BigInteger.ZERO;
|
||||
BigInteger spanId = BigInteger.ZERO;
|
||||
final int samplingPriority = PrioritySampling.SAMPLER_KEEP;
|
||||
final String origin = null; // Always null
|
||||
|
||||
for (final Map.Entry<String, String> entry : carrier) {
|
||||
|
@ -95,8 +93,7 @@ public class HaystackHttpCodec {
|
|||
|
||||
if (!BigInteger.ZERO.equals(traceId)) {
|
||||
final ExtractedContext context =
|
||||
new ExtractedContext(traceId, spanId, samplingPriority, origin, baggage, tags);
|
||||
context.lockSamplingPriority();
|
||||
new ExtractedContext(traceId, spanId, origin, baggage, tags);
|
||||
|
||||
log.debug("{} - Parent context extracted", context.getTraceId());
|
||||
return context;
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package datadog.trace.common.sampling;
|
||||
|
||||
import datadog.opentracing.DDSpan;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class AbstractSampler implements Sampler {
|
||||
|
||||
/** Sample tags */
|
||||
protected Map<String, Pattern> skipTagsPatterns = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean sample(final DDSpan span) {
|
||||
|
||||
// Filter by tag values
|
||||
for (final Entry<String, Pattern> entry : skipTagsPatterns.entrySet()) {
|
||||
final Object value = span.getTags().get(entry.getKey());
|
||||
if (value != null) {
|
||||
final String strValue = String.valueOf(value);
|
||||
final Pattern skipPattern = entry.getValue();
|
||||
if (skipPattern.matcher(strValue).matches()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return doSample(span);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pattern based skipping of tag values
|
||||
*
|
||||
* @param tag
|
||||
* @param skipPattern
|
||||
*/
|
||||
public void addSkipTagPattern(final String tag, final Pattern skipPattern) {
|
||||
skipTagsPatterns.put(tag, skipPattern);
|
||||
}
|
||||
|
||||
protected abstract boolean doSample(DDSpan span);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package datadog.trace.common.sampling;
|
||||
|
||||
import datadog.opentracing.DDSpan;
|
||||
|
||||
/** Sampler that always says yes... */
|
||||
public class AllSampler extends AbstractSampler {
|
||||
|
||||
@Override
|
||||
public boolean doSample(final DDSpan span) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AllSampler { sample=true }";
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package datadog.trace.common.sampling;
|
||||
|
||||
/** @deprecated Replaced by {@link datadog.trace.api.sampling.PrioritySampling} . */
|
||||
@Deprecated
|
||||
public class PrioritySampling {
|
||||
/**
|
||||
* Implementation detail of the client. will not be sent to the agent or propagated.
|
||||
*
|
||||
* <p>Internal value used when the priority sampling flag has not been set on the span context.
|
||||
*/
|
||||
public static final int UNSET = Integer.MIN_VALUE;
|
||||
/** The sampler has decided to drop the trace. */
|
||||
public static final int SAMPLER_DROP = 0;
|
||||
/** The sampler has decided to keep the trace. */
|
||||
public static final int SAMPLER_KEEP = 1;
|
||||
/** The user has decided to drop the trace. */
|
||||
public static final int USER_DROP = -1;
|
||||
/** The user has decided to keep the trace. */
|
||||
public static final int USER_KEEP = 2;
|
||||
|
||||
private PrioritySampling() {}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
package datadog.trace.common.sampling;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.NumericNode;
|
||||
import datadog.opentracing.DDSpan;
|
||||
import datadog.trace.api.sampling.PrioritySampling;
|
||||
import datadog.trace.common.writer.DDApi.ResponseListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* A rate sampler which maintains different sample rates per service+env name.
|
||||
*
|
||||
* <p>The configuration of (serviceName,env)->rate is configured by the core agent.
|
||||
*/
|
||||
@Slf4j
|
||||
public class RateByServiceSampler implements Sampler, ResponseListener {
|
||||
/** Key for setting the default/baseline rate */
|
||||
private static final String DEFAULT_KEY = "service:,env:";
|
||||
|
||||
private static final double DEFAULT_RATE = 1.0;
|
||||
|
||||
private volatile Map<String, RateSampler> serviceRates =
|
||||
unmodifiableMap(singletonMap(DEFAULT_KEY, new RateSampler(DEFAULT_RATE)));
|
||||
|
||||
@Override
|
||||
public boolean sample(final DDSpan span) {
|
||||
// Priority sampling sends all traces to the core agent, including traces marked dropped.
|
||||
// This allows the core agent to collect stats on all traces.
|
||||
return true;
|
||||
}
|
||||
|
||||
/** If span is a root span, set the span context samplingPriority to keep or drop */
|
||||
public void initializeSamplingPriority(final DDSpan span) {
|
||||
if (span.isRootSpan()) {
|
||||
// Run the priority sampler on the new span
|
||||
setSamplingPriorityOnSpanContext(span);
|
||||
} else if (span.getSamplingPriority() == null) {
|
||||
// Edge case: If the parent context did not set the priority, run the priority sampler.
|
||||
// Happens when extracted http context did not send the priority header.
|
||||
setSamplingPriorityOnSpanContext(span);
|
||||
}
|
||||
}
|
||||
|
||||
private void setSamplingPriorityOnSpanContext(final DDSpan span) {
|
||||
final String serviceName = span.getServiceName();
|
||||
final String env = getSpanEnv(span);
|
||||
final String key = "service:" + serviceName + ",env:" + env;
|
||||
|
||||
final Map<String, RateSampler> rates = serviceRates;
|
||||
RateSampler sampler = serviceRates.get(key);
|
||||
if (sampler == null) {
|
||||
sampler = rates.get(DEFAULT_KEY);
|
||||
}
|
||||
|
||||
if (sampler.sample(span)) {
|
||||
span.setSamplingPriority(PrioritySampling.SAMPLER_KEEP);
|
||||
} else {
|
||||
span.setSamplingPriority(PrioritySampling.SAMPLER_DROP);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getSpanEnv(final DDSpan span) {
|
||||
return null == span.getTags().get("env") ? "" : String.valueOf(span.getTags().get("env"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(final String endpoint, final JsonNode responseJson) {
|
||||
final JsonNode newServiceRates = responseJson.get("rate_by_service");
|
||||
if (null != newServiceRates) {
|
||||
log.debug("Update service sampler rates: {} -> {}", endpoint, responseJson);
|
||||
final Map<String, RateSampler> updatedServiceRates = new HashMap<>();
|
||||
final Iterator<String> itr = newServiceRates.fieldNames();
|
||||
while (itr.hasNext()) {
|
||||
final String key = itr.next();
|
||||
final JsonNode value = newServiceRates.get(key);
|
||||
try {
|
||||
if (value instanceof NumericNode) {
|
||||
updatedServiceRates.put(key, new RateSampler(value.doubleValue()));
|
||||
} else {
|
||||
log.debug("Unable to parse new service rate {} -> {}", key, value);
|
||||
}
|
||||
} catch (final NumberFormatException nfe) {
|
||||
log.debug("Unable to parse new service rate {} -> {}", key, value);
|
||||
}
|
||||
}
|
||||
if (!updatedServiceRates.containsKey(DEFAULT_KEY)) {
|
||||
updatedServiceRates.put(DEFAULT_KEY, new RateSampler(DEFAULT_RATE));
|
||||
}
|
||||
serviceRates = unmodifiableMap(updatedServiceRates);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Build an instance of the sampler. The Sample rate is fixed for each instance.
|
||||
*
|
||||
* @param sampleRate a number [0,1] representing the rate ratio.
|
||||
*/
|
||||
private 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 = ThreadLocalRandom.current().nextFloat() <= sampleRate;
|
||||
log.debug("{} - Span is sampled: {}", span, sample);
|
||||
return sample;
|
||||
}
|
||||
|
||||
public double getSampleRate() {
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RateSampler { sampleRate=" + sampleRate + " }";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package datadog.trace.common.sampling;
|
||||
|
||||
import datadog.opentracing.DDSpan;
|
||||
import datadog.trace.api.Config;
|
||||
import java.util.Properties;
|
||||
|
||||
/** Main interface to sample a collection of traces. */
|
||||
public interface Sampler {
|
||||
|
||||
/**
|
||||
* Sample a collection of traces based on the parent span
|
||||
*
|
||||
* @param span the parent span with its context
|
||||
* @return true when the trace/spans has to be reported/written
|
||||
*/
|
||||
boolean sample(DDSpan span);
|
||||
|
||||
final class Builder {
|
||||
public static Sampler forConfig(final Config config) {
|
||||
final Sampler sampler;
|
||||
if (config != null) {
|
||||
if (config.isPrioritySamplingEnabled()) {
|
||||
sampler = new RateByServiceSampler();
|
||||
} else {
|
||||
sampler = new AllSampler();
|
||||
}
|
||||
} else {
|
||||
sampler = new AllSampler();
|
||||
}
|
||||
return sampler;
|
||||
}
|
||||
|
||||
public static Sampler forConfig(final Properties config) {
|
||||
return forConfig(Config.get(config));
|
||||
}
|
||||
|
||||
private Builder() {}
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
*
|
||||
* <p>Written traces are passed off to a disruptor so as to avoid blocking the application's thread.
|
||||
* If a flood of traces arrives that exceeds the disruptor ring size, the traces exceeding the
|
||||
* threshold will be counted and sampled.
|
||||
* threshold will be counted.
|
||||
*/
|
||||
@Slf4j
|
||||
public class DDAgentWriter implements Writer {
|
||||
|
|
|
@ -70,9 +70,8 @@ class OT31ApiTest extends DDSpecification {
|
|||
|
||||
then:
|
||||
textMap == [
|
||||
"x-datadog-trace-id" : context.toTraceId(),
|
||||
"x-datadog-parent-id" : context.toSpanId(),
|
||||
"x-datadog-sampling-priority": "$context.samplingPriority",
|
||||
"x-datadog-trace-id" : context.toTraceId(),
|
||||
"x-datadog-parent-id": context.toSpanId(),
|
||||
]
|
||||
|
||||
when:
|
||||
|
@ -81,7 +80,6 @@ class OT31ApiTest extends DDSpecification {
|
|||
then:
|
||||
extract.traceId == context.traceId
|
||||
extract.spanId == context.spanId
|
||||
extract.samplingPriority == context.samplingPriority
|
||||
}
|
||||
|
||||
static class TextMapAdapter implements TextMap {
|
||||
|
|
|
@ -4,7 +4,6 @@ import datadog.opentracing.propagation.ExtractedContext
|
|||
import datadog.opentracing.propagation.TagContext
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.Scope
|
||||
|
@ -421,7 +420,6 @@ class DDSpanBuilderTest extends DDSpecification {
|
|||
expect:
|
||||
span.traceId == extractedContext.traceId
|
||||
span.parentId == extractedContext.spanId
|
||||
span.samplingPriority == extractedContext.samplingPriority
|
||||
span.context().origin == extractedContext.origin
|
||||
span.context().baggageItems == extractedContext.baggage
|
||||
span.context().@tags == extractedContext.tags + [(Config.RUNTIME_ID_TAG) : config.getRuntimeId(),
|
||||
|
@ -430,8 +428,8 @@ class DDSpanBuilderTest extends DDSpecification {
|
|||
|
||||
where:
|
||||
extractedContext | _
|
||||
new ExtractedContext(1G, 2G, 0, null, [:], [:]) | _
|
||||
new ExtractedContext(3G, 4G, 1, "some-origin", ["asdf": "qwer"], [(ORIGIN_KEY): "some-origin", "zxcv": "1234"]) | _
|
||||
new ExtractedContext(1G, 2G, null, [:], [:]) | _
|
||||
new ExtractedContext(3G, 4G, "some-origin", ["asdf": "qwer"], [(ORIGIN_KEY): "some-origin", "zxcv": "1234"]) | _
|
||||
}
|
||||
|
||||
def "TagContext should populate default span details"() {
|
||||
|
@ -442,7 +440,6 @@ class DDSpanBuilderTest extends DDSpecification {
|
|||
expect:
|
||||
span.traceId != 0G
|
||||
span.parentId == 0G
|
||||
span.samplingPriority == PrioritySampling.SAMPLER_KEEP // Since we're using the RateByServiceSampler
|
||||
span.context().origin == tagContext.origin
|
||||
span.context().baggageItems == [:]
|
||||
span.context().@tags == tagContext.tags + [(Config.RUNTIME_ID_TAG) : config.getRuntimeId(),
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package datadog.opentracing
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.google.common.collect.Maps
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import org.msgpack.core.MessagePack
|
||||
|
@ -13,72 +10,6 @@ import org.msgpack.value.ValueType
|
|||
|
||||
class DDSpanSerializationTest extends DDSpecification {
|
||||
|
||||
def "serialize spans with sampling #samplingPriority"() throws Exception {
|
||||
setup:
|
||||
final Map<String, String> baggage = new HashMap<>()
|
||||
baggage.put("a-baggage", "value")
|
||||
final Map<String, Object> tags = new HashMap<>()
|
||||
baggage.put("k1", "v1")
|
||||
|
||||
Map<String, Object> expected = Maps.newHashMap()
|
||||
expected.put("meta", baggage)
|
||||
expected.put("service", "service")
|
||||
expected.put("error", 0)
|
||||
expected.put("type", "type")
|
||||
expected.put("name", "operation")
|
||||
expected.put("duration", 33000)
|
||||
expected.put("resource", "operation")
|
||||
final Map<String, Number> metrics = new HashMap<>()
|
||||
if (samplingPriority != PrioritySampling.UNSET) {
|
||||
metrics.put("_sampling_priority_v1", Integer.valueOf(samplingPriority))
|
||||
metrics.put("_sample_rate", Double.valueOf(1.0))
|
||||
}
|
||||
expected.put("metrics", metrics)
|
||||
expected.put("start", 100000)
|
||||
expected.put("span_id", 2l)
|
||||
expected.put("parent_id", 0l)
|
||||
expected.put("trace_id", 1l)
|
||||
|
||||
def writer = new ListWriter()
|
||||
def tracer = new DDTracer(writer)
|
||||
final DDSpanContext context =
|
||||
new DDSpanContext(
|
||||
1G,
|
||||
2G,
|
||||
0G,
|
||||
"service",
|
||||
"operation",
|
||||
null,
|
||||
samplingPriority,
|
||||
null,
|
||||
new HashMap<>(baggage),
|
||||
false,
|
||||
"type",
|
||||
tags,
|
||||
new PendingTrace(tracer, 1G, [:]),
|
||||
tracer)
|
||||
|
||||
baggage.put(DDTags.THREAD_NAME, Thread.currentThread().getName())
|
||||
baggage.put(DDTags.THREAD_ID, String.valueOf(Thread.currentThread().getId()))
|
||||
|
||||
DDSpan span = new DDSpan(100L, context)
|
||||
if (samplingPriority != PrioritySampling.UNSET) {
|
||||
span.context().setMetric("_sample_rate", Double.valueOf(1.0))
|
||||
}
|
||||
span.finish(133L)
|
||||
ObjectMapper serializer = new ObjectMapper()
|
||||
|
||||
def actualTree = serializer.readTree(serializer.writeValueAsString(span))
|
||||
def expectedTree = serializer.readTree(serializer.writeValueAsString(expected))
|
||||
expect:
|
||||
actualTree == expectedTree
|
||||
|
||||
where:
|
||||
samplingPriority | _
|
||||
PrioritySampling.SAMPLER_KEEP | _
|
||||
PrioritySampling.UNSET | _
|
||||
}
|
||||
|
||||
def "serialize trace/span with id #value as int"() {
|
||||
setup:
|
||||
def objectMapper = new ObjectMapper(new MessagePackFactory())
|
||||
|
@ -91,7 +22,6 @@ class DDSpanSerializationTest extends DDSpecification {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
PrioritySampling.UNSET,
|
||||
null,
|
||||
Collections.emptyMap(),
|
||||
false,
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package datadog.opentracing
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
|
||||
import datadog.opentracing.propagation.ExtractedContext
|
||||
import datadog.opentracing.propagation.TagContext
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.sampling.RateByServiceSampler
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.SpanContext
|
||||
import spock.lang.Shared
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
@ -18,16 +14,7 @@ import static datadog.trace.api.Config.DEFAULT_SERVICE_NAME
|
|||
class DDSpanTest extends DDSpecification {
|
||||
|
||||
def writer = new ListWriter()
|
||||
def sampler = new RateByServiceSampler()
|
||||
def tracer = new DDTracer(DEFAULT_SERVICE_NAME, writer, sampler, [:])
|
||||
|
||||
@Shared
|
||||
def defaultSamplingPriority = PrioritySampling.SAMPLER_KEEP
|
||||
|
||||
def setup() {
|
||||
sampler.onResponse("test", new ObjectMapper()
|
||||
.readTree('{"rate_by_service":{"service:,env:":1.0,"service:spock,env:":0.0}}'))
|
||||
}
|
||||
def tracer = new DDTracer(DEFAULT_SERVICE_NAME, writer, [:])
|
||||
|
||||
def "getters and setters"() {
|
||||
setup:
|
||||
|
@ -39,7 +26,6 @@ class DDSpanTest extends DDSpecification {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
PrioritySampling.UNSET,
|
||||
null,
|
||||
Collections.<String, String> emptyMap(),
|
||||
false,
|
||||
|
@ -69,22 +55,6 @@ class DDSpanTest extends DDSpecification {
|
|||
span.setSpanType("type")
|
||||
then:
|
||||
span.getType() == "type"
|
||||
|
||||
when:
|
||||
span.setSamplingPriority(PrioritySampling.UNSET)
|
||||
then:
|
||||
span.getSamplingPriority() == null
|
||||
|
||||
when:
|
||||
span.setSamplingPriority(PrioritySampling.SAMPLER_KEEP)
|
||||
then:
|
||||
span.getSamplingPriority() == PrioritySampling.SAMPLER_KEEP
|
||||
|
||||
when:
|
||||
context.lockSamplingPriority()
|
||||
span.setSamplingPriority(PrioritySampling.USER_KEEP)
|
||||
then:
|
||||
span.getSamplingPriority() == PrioritySampling.SAMPLER_KEEP
|
||||
}
|
||||
|
||||
def "resource name equals operation name if null"() {
|
||||
|
@ -178,28 +148,6 @@ class DDSpanTest extends DDSpecification {
|
|||
span.durationNano == 1
|
||||
}
|
||||
|
||||
def "priority sampling metric set only on root span"() {
|
||||
setup:
|
||||
def parent = tracer.buildSpan("testParent").start()
|
||||
def child1 = tracer.buildSpan("testChild1").asChildOf(parent).start()
|
||||
|
||||
child1.setSamplingPriority(PrioritySampling.SAMPLER_KEEP)
|
||||
child1.context().lockSamplingPriority()
|
||||
parent.setSamplingPriority(PrioritySampling.SAMPLER_DROP)
|
||||
child1.finish()
|
||||
def child2 = tracer.buildSpan("testChild2").asChildOf(parent).start()
|
||||
child2.finish()
|
||||
parent.finish()
|
||||
|
||||
expect:
|
||||
parent.context().samplingPriority == PrioritySampling.SAMPLER_KEEP
|
||||
parent.getMetrics().get(DDSpanContext.PRIORITY_SAMPLING_KEY) == PrioritySampling.SAMPLER_KEEP
|
||||
child1.getSamplingPriority() == parent.getSamplingPriority()
|
||||
child1.getMetrics().get(DDSpanContext.PRIORITY_SAMPLING_KEY) == null
|
||||
child2.getSamplingPriority() == parent.getSamplingPriority()
|
||||
child2.getMetrics().get(DDSpanContext.PRIORITY_SAMPLING_KEY) == null
|
||||
}
|
||||
|
||||
def "origin set only on root span"() {
|
||||
setup:
|
||||
def parent = tracer.buildSpan("testParent").asChildOf(extractedContext).start().context()
|
||||
|
@ -212,9 +160,9 @@ class DDSpanTest extends DDSpecification {
|
|||
child.@origin == null // Access field directly instead of getter.
|
||||
|
||||
where:
|
||||
extractedContext | _
|
||||
new TagContext("some-origin", [:]) | _
|
||||
new ExtractedContext(1G, 2G, 0, "some-origin", [:], [:]) | _
|
||||
extractedContext | _
|
||||
new TagContext("some-origin", [:]) | _
|
||||
new ExtractedContext(1G, 2G, "some-origin", [:], [:]) | _
|
||||
}
|
||||
|
||||
def "isRootSpan() in and not in the context of distributed tracing"() {
|
||||
|
@ -231,9 +179,9 @@ class DDSpanTest extends DDSpecification {
|
|||
root.finish()
|
||||
|
||||
where:
|
||||
extractedContext | isTraceRootSpan
|
||||
null | true
|
||||
new ExtractedContext(123G, 456G, 1, "789", [:], [:]) | false
|
||||
extractedContext | isTraceRootSpan
|
||||
null | true
|
||||
new ExtractedContext(123G, 456G, "789", [:], [:]) | false
|
||||
}
|
||||
|
||||
def "getApplicationRootSpan() in and not in the context of distributed tracing"() {
|
||||
|
@ -253,74 +201,8 @@ class DDSpanTest extends DDSpecification {
|
|||
root.finish()
|
||||
|
||||
where:
|
||||
extractedContext | isTraceRootSpan
|
||||
null | true
|
||||
new ExtractedContext(123G, 456G, 1, "789", [:], [:]) | false
|
||||
}
|
||||
|
||||
def "sampling priority set on init"() {
|
||||
setup:
|
||||
def span = tracer.buildSpan("test").start()
|
||||
|
||||
expect:
|
||||
span.getSamplingPriority() == PrioritySampling.SAMPLER_KEEP
|
||||
|
||||
when:
|
||||
span.setTag(DDTags.SERVICE_NAME, "spock")
|
||||
|
||||
then:
|
||||
// FIXME: priority currently only applies if service name set before span started.
|
||||
span.getSamplingPriority() == PrioritySampling.SAMPLER_KEEP
|
||||
// span.getSamplingPriority() == PrioritySampling.SAMPLER_DROP
|
||||
|
||||
when:
|
||||
span = tracer.buildSpan("test").withTag(DDTags.SERVICE_NAME, "spock").start()
|
||||
|
||||
then:
|
||||
span.getSamplingPriority() == PrioritySampling.SAMPLER_DROP
|
||||
}
|
||||
|
||||
def "setting forced tracing via tag"() {
|
||||
setup:
|
||||
def span = tracer.buildSpan("root").start()
|
||||
if (tagName) {
|
||||
span.setTag(tagName, tagValue)
|
||||
}
|
||||
|
||||
expect:
|
||||
span.getSamplingPriority() == expectedPriority
|
||||
|
||||
cleanup:
|
||||
span.finish()
|
||||
|
||||
where:
|
||||
tagName | tagValue | expectedPriority
|
||||
'manual.drop' | true | PrioritySampling.USER_DROP
|
||||
'manual.keep' | true | PrioritySampling.USER_KEEP
|
||||
}
|
||||
|
||||
def "not setting forced tracing via tag or setting it wrong value not causing exception"() {
|
||||
|
||||
setup:
|
||||
def span = tracer.buildSpan("root").start()
|
||||
if (tagName) {
|
||||
span.setTag(tagName, tagValue)
|
||||
}
|
||||
|
||||
expect:
|
||||
span.getSamplingPriority() == defaultSamplingPriority
|
||||
|
||||
cleanup:
|
||||
span.finish()
|
||||
|
||||
where:
|
||||
tagName | tagValue
|
||||
// When no tag is set default to
|
||||
null | null
|
||||
// Setting to not known value
|
||||
'manual.drop' | false
|
||||
'manual.keep' | false
|
||||
'manual.drop' | 1
|
||||
'manual.keep' | 1
|
||||
extractedContext | isTraceRootSpan
|
||||
null | true
|
||||
new ExtractedContext(123G, 456G, "789", [:], [:]) | false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package datadog.opentracing
|
||||
|
||||
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
|
||||
class SpanFactory {
|
||||
|
@ -18,7 +17,6 @@ class SpanFactory {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
PrioritySampling.UNSET,
|
||||
null,
|
||||
Collections.emptyMap(),
|
||||
false,
|
||||
|
@ -38,7 +36,6 @@ class SpanFactory {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
PrioritySampling.UNSET,
|
||||
null,
|
||||
Collections.emptyMap(),
|
||||
false,
|
||||
|
@ -57,7 +54,6 @@ class SpanFactory {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
PrioritySampling.UNSET,
|
||||
null,
|
||||
Collections.emptyMap(),
|
||||
false,
|
||||
|
@ -78,7 +74,6 @@ class SpanFactory {
|
|||
serviceName,
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
PrioritySampling.UNSET,
|
||||
null,
|
||||
Collections.emptyMap(),
|
||||
false,
|
||||
|
|
|
@ -7,15 +7,12 @@ import datadog.trace.agent.test.utils.ConfigUtils
|
|||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.sampling.AllSampler
|
||||
import datadog.trace.common.writer.LoggingWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.tag.StringTag
|
||||
import io.opentracing.tag.Tags
|
||||
|
||||
import static datadog.trace.api.Config.DEFAULT_SERVICE_NAME
|
||||
import static datadog.trace.api.DDTags.ANALYTICS_SAMPLE_RATE
|
||||
import static java.util.Collections.emptyMap
|
||||
|
||||
class SpanDecoratorTest extends DDSpecification {
|
||||
|
@ -58,7 +55,6 @@ class SpanDecoratorTest extends DDSpecification {
|
|||
tracer = new DDTracer(
|
||||
"wrong-service",
|
||||
new LoggingWriter(),
|
||||
new AllSampler(),
|
||||
"some-runtime-id",
|
||||
emptyMap(),
|
||||
emptyMap(),
|
||||
|
@ -94,7 +90,6 @@ class SpanDecoratorTest extends DDSpecification {
|
|||
tracer = new DDTracer(
|
||||
serviceName,
|
||||
new LoggingWriter(),
|
||||
new AllSampler(),
|
||||
"some-runtime-id",
|
||||
emptyMap(),
|
||||
emptyMap(),
|
||||
|
@ -141,7 +136,6 @@ class SpanDecoratorTest extends DDSpecification {
|
|||
tracer = new DDTracer(
|
||||
serviceName,
|
||||
new LoggingWriter(),
|
||||
new AllSampler(),
|
||||
"some-runtime-id",
|
||||
emptyMap(),
|
||||
emptyMap(),
|
||||
|
@ -225,58 +219,6 @@ class SpanDecoratorTest extends DDSpecification {
|
|||
type = "foo"
|
||||
}
|
||||
|
||||
def "span metrics starts empty but added with rate limiting value of #rate"() {
|
||||
expect:
|
||||
span.metrics == [:]
|
||||
|
||||
when:
|
||||
span.setTag(ANALYTICS_SAMPLE_RATE, rate)
|
||||
|
||||
then:
|
||||
span.metrics == result
|
||||
|
||||
where:
|
||||
rate | result
|
||||
00 | [(ANALYTICS_SAMPLE_RATE): 0]
|
||||
1 | [(ANALYTICS_SAMPLE_RATE): 1]
|
||||
0f | [(ANALYTICS_SAMPLE_RATE): 0]
|
||||
1f | [(ANALYTICS_SAMPLE_RATE): 1]
|
||||
0.1 | [(ANALYTICS_SAMPLE_RATE): 0.1]
|
||||
1.1 | [(ANALYTICS_SAMPLE_RATE): 1.1]
|
||||
-1 | [(ANALYTICS_SAMPLE_RATE): -1]
|
||||
10 | [(ANALYTICS_SAMPLE_RATE): 10]
|
||||
"00" | [(ANALYTICS_SAMPLE_RATE): 0]
|
||||
"1" | [(ANALYTICS_SAMPLE_RATE): 1]
|
||||
"1.0" | [(ANALYTICS_SAMPLE_RATE): 1]
|
||||
"0" | [(ANALYTICS_SAMPLE_RATE): 0]
|
||||
"0.1" | [(ANALYTICS_SAMPLE_RATE): 0.1]
|
||||
"1.1" | [(ANALYTICS_SAMPLE_RATE): 1.1]
|
||||
"-1" | [(ANALYTICS_SAMPLE_RATE): -1]
|
||||
"str" | [:]
|
||||
}
|
||||
|
||||
def "set priority sampling via tag"() {
|
||||
when:
|
||||
span.setTag(tag, value)
|
||||
|
||||
then:
|
||||
span.samplingPriority == expected
|
||||
|
||||
where:
|
||||
tag | value | expected
|
||||
DDTags.MANUAL_KEEP | true | PrioritySampling.USER_KEEP
|
||||
DDTags.MANUAL_KEEP | false | null
|
||||
DDTags.MANUAL_KEEP | "true" | PrioritySampling.USER_KEEP
|
||||
DDTags.MANUAL_KEEP | "false" | null
|
||||
DDTags.MANUAL_KEEP | "asdf" | null
|
||||
|
||||
DDTags.MANUAL_DROP | true | PrioritySampling.USER_DROP
|
||||
DDTags.MANUAL_DROP | false | null
|
||||
DDTags.MANUAL_DROP | "true" | PrioritySampling.USER_DROP
|
||||
DDTags.MANUAL_DROP | "false" | null
|
||||
DDTags.MANUAL_DROP | "asdf" | null
|
||||
}
|
||||
|
||||
def "DBStatementAsResource should not interact on Mongo queries"() {
|
||||
when:
|
||||
span.setResourceName("not-change-me")
|
||||
|
|
|
@ -3,7 +3,6 @@ package datadog.opentracing.decorators
|
|||
import datadog.opentracing.DDSpanContext
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.PendingTrace
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.tag.Tags
|
||||
|
@ -113,7 +112,6 @@ class URLAsResourceNameTest extends DDSpecification {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
PrioritySampling.UNSET,
|
||||
null,
|
||||
Collections.<String, String> emptyMap(),
|
||||
false,
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package datadog.opentracing.propagation
|
||||
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.SpanContext
|
||||
import io.opentracing.propagation.TextMapExtractAdapter
|
||||
|
||||
import static datadog.opentracing.DDTracer.TRACE_ID_MAX
|
||||
import static datadog.opentracing.propagation.B3HttpCodec.SAMPLING_PRIORITY_KEY
|
||||
import static datadog.opentracing.propagation.B3HttpCodec.SPAN_ID_KEY
|
||||
import static datadog.opentracing.propagation.B3HttpCodec.TRACE_ID_KEY
|
||||
|
||||
|
@ -22,10 +20,6 @@ class B3HttpExtractorTest extends DDSpecification {
|
|||
SOME_HEADER : "my-interesting-info",
|
||||
]
|
||||
|
||||
if (samplingPriority != null) {
|
||||
headers.put(SAMPLING_PRIORITY_KEY, "$samplingPriority".toString())
|
||||
}
|
||||
|
||||
when:
|
||||
final ExtractedContext context = extractor.extract(new TextMapExtractAdapter(headers))
|
||||
|
||||
|
@ -34,16 +28,13 @@ class B3HttpExtractorTest extends DDSpecification {
|
|||
context.spanId == spanId
|
||||
context.baggage == [:]
|
||||
context.tags == ["some-tag": "my-interesting-info"]
|
||||
context.samplingPriority == expectedSamplingPriority
|
||||
context.origin == null
|
||||
|
||||
where:
|
||||
traceId | spanId | samplingPriority | expectedSamplingPriority
|
||||
1G | 2G | null | PrioritySampling.UNSET
|
||||
2G | 3G | 1 | PrioritySampling.SAMPLER_KEEP
|
||||
3G | 4G | 0 | PrioritySampling.SAMPLER_DROP
|
||||
TRACE_ID_MAX | TRACE_ID_MAX - 1 | 0 | PrioritySampling.SAMPLER_DROP
|
||||
TRACE_ID_MAX - 1 | TRACE_ID_MAX | 1 | PrioritySampling.SAMPLER_KEEP
|
||||
traceId | spanId
|
||||
1G | 2G
|
||||
TRACE_ID_MAX | TRACE_ID_MAX - 1
|
||||
TRACE_ID_MAX - 1 | TRACE_ID_MAX
|
||||
}
|
||||
|
||||
def "extract 128 bit id truncates id to 64 bit"() {
|
||||
|
|
|
@ -3,13 +3,11 @@ package datadog.opentracing.propagation
|
|||
import datadog.opentracing.DDSpanContext
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.PendingTrace
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.propagation.TextMapInjectAdapter
|
||||
|
||||
import static datadog.opentracing.DDTracer.TRACE_ID_MAX
|
||||
import static datadog.opentracing.propagation.B3HttpCodec.SAMPLING_PRIORITY_KEY
|
||||
import static datadog.opentracing.propagation.B3HttpCodec.SPAN_ID_KEY
|
||||
import static datadog.opentracing.propagation.B3HttpCodec.TRACE_ID_KEY
|
||||
|
||||
|
@ -29,7 +27,6 @@ class B3HttpInjectorTest extends DDSpecification {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
samplingPriority,
|
||||
"fakeOrigin",
|
||||
new HashMap<String, String>() {
|
||||
{
|
||||
|
@ -51,19 +48,12 @@ class B3HttpInjectorTest extends DDSpecification {
|
|||
then:
|
||||
1 * carrier.put(TRACE_ID_KEY, traceId.toString(16).toLowerCase())
|
||||
1 * carrier.put(SPAN_ID_KEY, spanId.toString(16).toLowerCase())
|
||||
if (expectedSamplingPriority != null) {
|
||||
1 * carrier.put(SAMPLING_PRIORITY_KEY, "$expectedSamplingPriority")
|
||||
}
|
||||
0 * _
|
||||
|
||||
where:
|
||||
traceId | spanId | samplingPriority | expectedSamplingPriority
|
||||
1G | 2G | PrioritySampling.UNSET | null
|
||||
2G | 3G | PrioritySampling.SAMPLER_KEEP | 1
|
||||
4G | 5G | PrioritySampling.SAMPLER_DROP | 0
|
||||
5G | 6G | PrioritySampling.USER_KEEP | 1
|
||||
6G | 7G | PrioritySampling.USER_DROP | 0
|
||||
TRACE_ID_MAX | TRACE_ID_MAX - 1 | PrioritySampling.UNSET | null
|
||||
TRACE_ID_MAX - 1 | TRACE_ID_MAX | PrioritySampling.SAMPLER_KEEP | 1
|
||||
traceId | spanId
|
||||
1G | 2G
|
||||
TRACE_ID_MAX | TRACE_ID_MAX - 1
|
||||
TRACE_ID_MAX - 1 | TRACE_ID_MAX
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package datadog.opentracing.propagation
|
||||
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.SpanContext
|
||||
import io.opentracing.propagation.TextMapExtractAdapter
|
||||
|
@ -8,7 +7,6 @@ import io.opentracing.propagation.TextMapExtractAdapter
|
|||
import static datadog.opentracing.DDTracer.TRACE_ID_MAX
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.ORIGIN_KEY
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.OT_BAGGAGE_PREFIX
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.SAMPLING_PRIORITY_KEY
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.SPAN_ID_KEY
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.TRACE_ID_KEY
|
||||
|
||||
|
@ -26,10 +24,6 @@ class DatadogHttpExtractorTest extends DDSpecification {
|
|||
SOME_HEADER : "my-interesting-info",
|
||||
]
|
||||
|
||||
if (samplingPriority != PrioritySampling.UNSET) {
|
||||
headers.put(SAMPLING_PRIORITY_KEY, "$samplingPriority".toString())
|
||||
}
|
||||
|
||||
if (origin) {
|
||||
headers.put(ORIGIN_KEY, origin)
|
||||
}
|
||||
|
@ -42,15 +36,14 @@ class DatadogHttpExtractorTest extends DDSpecification {
|
|||
context.spanId == new BigInteger(spanId)
|
||||
context.baggage == ["k1": "v1", "k2": "v2"]
|
||||
context.tags == ["some-tag": "my-interesting-info"]
|
||||
context.samplingPriority == samplingPriority
|
||||
context.origin == origin
|
||||
|
||||
where:
|
||||
traceId | spanId | samplingPriority | origin
|
||||
"1" | "2" | PrioritySampling.UNSET | null
|
||||
"2" | "3" | PrioritySampling.SAMPLER_KEEP | "saipan"
|
||||
TRACE_ID_MAX.toString() | (TRACE_ID_MAX - 1).toString() | PrioritySampling.UNSET | "saipan"
|
||||
(TRACE_ID_MAX - 1).toString() | TRACE_ID_MAX.toString() | PrioritySampling.SAMPLER_KEEP | "saipan"
|
||||
traceId | spanId | origin
|
||||
"1" | "2" | null
|
||||
"2" | "3" | "saipan"
|
||||
TRACE_ID_MAX.toString() | (TRACE_ID_MAX - 1).toString() | "saipan"
|
||||
(TRACE_ID_MAX - 1).toString() | TRACE_ID_MAX.toString() | "saipan"
|
||||
}
|
||||
|
||||
def "extract header tags with no propagation"() {
|
||||
|
|
|
@ -3,7 +3,6 @@ package datadog.opentracing.propagation
|
|||
import datadog.opentracing.DDSpanContext
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.PendingTrace
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.propagation.TextMapInjectAdapter
|
||||
|
@ -11,7 +10,6 @@ import io.opentracing.propagation.TextMapInjectAdapter
|
|||
import static datadog.opentracing.DDTracer.TRACE_ID_MAX
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.ORIGIN_KEY
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.OT_BAGGAGE_PREFIX
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.SAMPLING_PRIORITY_KEY
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.SPAN_ID_KEY
|
||||
import static datadog.opentracing.propagation.DatadogHttpCodec.TRACE_ID_KEY
|
||||
|
||||
|
@ -31,7 +29,6 @@ class DatadogHttpInjectorTest extends DDSpecification {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
samplingPriority,
|
||||
origin,
|
||||
new HashMap<String, String>() {
|
||||
{
|
||||
|
@ -55,19 +52,16 @@ class DatadogHttpInjectorTest extends DDSpecification {
|
|||
1 * carrier.put(SPAN_ID_KEY, spanId.toString())
|
||||
1 * carrier.put(OT_BAGGAGE_PREFIX + "k1", "v1")
|
||||
1 * carrier.put(OT_BAGGAGE_PREFIX + "k2", "v2")
|
||||
if (samplingPriority != PrioritySampling.UNSET) {
|
||||
1 * carrier.put(SAMPLING_PRIORITY_KEY, "$samplingPriority")
|
||||
}
|
||||
if (origin) {
|
||||
1 * carrier.put(ORIGIN_KEY, origin)
|
||||
}
|
||||
0 * _
|
||||
|
||||
where:
|
||||
traceId | spanId | samplingPriority | origin
|
||||
1G | 2G | PrioritySampling.UNSET | null
|
||||
1G | 2G | PrioritySampling.SAMPLER_KEEP | "saipan"
|
||||
TRACE_ID_MAX | TRACE_ID_MAX - 1 | PrioritySampling.UNSET | "saipan"
|
||||
TRACE_ID_MAX - 1 | TRACE_ID_MAX | PrioritySampling.SAMPLER_KEEP | null
|
||||
traceId | spanId | origin
|
||||
1G | 2G | null
|
||||
1G | 2G | "saipan"
|
||||
TRACE_ID_MAX | TRACE_ID_MAX - 1 | "saipan"
|
||||
TRACE_ID_MAX - 1 | TRACE_ID_MAX | null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package datadog.opentracing.propagation
|
||||
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.SpanContext
|
||||
import io.opentracing.propagation.TextMapExtractAdapter
|
||||
|
@ -32,15 +31,13 @@ class HaystackHttpExtractorTest extends DDSpecification {
|
|||
context.spanId == new BigInteger(spanId)
|
||||
context.baggage == ["k1": "v1", "k2": "v2"]
|
||||
context.tags == ["some-tag": "my-interesting-info"]
|
||||
context.samplingPriority == samplingPriority
|
||||
context.origin == origin
|
||||
|
||||
where:
|
||||
traceId | spanId | samplingPriority | origin
|
||||
"1" | "2" | PrioritySampling.SAMPLER_KEEP | null
|
||||
"2" | "3" | PrioritySampling.SAMPLER_KEEP | null
|
||||
TRACE_ID_MAX.toString() | (TRACE_ID_MAX - 1).toString() | PrioritySampling.SAMPLER_KEEP | null
|
||||
(TRACE_ID_MAX - 1).toString() | TRACE_ID_MAX.toString() | PrioritySampling.SAMPLER_KEEP | null
|
||||
traceId | spanId | origin
|
||||
"1" | "2" | null
|
||||
TRACE_ID_MAX.toString() | (TRACE_ID_MAX - 1).toString() | null
|
||||
(TRACE_ID_MAX - 1).toString() | TRACE_ID_MAX.toString() | null
|
||||
}
|
||||
|
||||
def "extract header tags with no propagation"() {
|
||||
|
|
|
@ -3,15 +3,12 @@ package datadog.opentracing.propagation
|
|||
import datadog.opentracing.DDSpanContext
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.PendingTrace
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.propagation.TextMapInjectAdapter
|
||||
|
||||
import static datadog.opentracing.DDTracer.TRACE_ID_MAX
|
||||
import static datadog.opentracing.propagation.HaystackHttpCodec.OT_BAGGAGE_PREFIX
|
||||
import static datadog.opentracing.propagation.HaystackHttpCodec.SPAN_ID_KEY
|
||||
import static datadog.opentracing.propagation.HaystackHttpCodec.TRACE_ID_KEY
|
||||
import static datadog.opentracing.propagation.HaystackHttpCodec.*
|
||||
|
||||
class HaystackHttpInjectorTest extends DDSpecification {
|
||||
|
||||
|
@ -29,7 +26,6 @@ class HaystackHttpInjectorTest extends DDSpecification {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
samplingPriority,
|
||||
origin,
|
||||
new HashMap<String, String>() {
|
||||
{
|
||||
|
@ -56,10 +52,9 @@ class HaystackHttpInjectorTest extends DDSpecification {
|
|||
|
||||
|
||||
where:
|
||||
traceId | spanId | samplingPriority | origin
|
||||
1G | 2G | PrioritySampling.SAMPLER_KEEP | null
|
||||
1G | 2G | PrioritySampling.SAMPLER_KEEP | null
|
||||
TRACE_ID_MAX | TRACE_ID_MAX - 1 | PrioritySampling.SAMPLER_KEEP | null
|
||||
TRACE_ID_MAX - 1 | TRACE_ID_MAX | PrioritySampling.SAMPLER_KEEP | null
|
||||
traceId | spanId | origin
|
||||
1G | 2G | null
|
||||
TRACE_ID_MAX | TRACE_ID_MAX - 1 | null
|
||||
TRACE_ID_MAX - 1 | TRACE_ID_MAX | null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import datadog.opentracing.DDSpanContext
|
|||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.PendingTrace
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import io.opentracing.propagation.TextMapInjectAdapter
|
||||
|
@ -34,7 +33,6 @@ class HttpInjectorTest extends DDSpecification {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
samplingPriority,
|
||||
origin,
|
||||
new HashMap<String, String>() {
|
||||
{
|
||||
|
@ -59,9 +57,6 @@ class HttpInjectorTest extends DDSpecification {
|
|||
1 * carrier.put(DatadogHttpCodec.SPAN_ID_KEY, spanId.toString())
|
||||
1 * carrier.put(DatadogHttpCodec.OT_BAGGAGE_PREFIX + "k1", "v1")
|
||||
1 * carrier.put(DatadogHttpCodec.OT_BAGGAGE_PREFIX + "k2", "v2")
|
||||
if (samplingPriority != PrioritySampling.UNSET) {
|
||||
1 * carrier.put(DatadogHttpCodec.SAMPLING_PRIORITY_KEY, "$samplingPriority")
|
||||
}
|
||||
if (origin) {
|
||||
1 * carrier.put(DatadogHttpCodec.ORIGIN_KEY, origin)
|
||||
}
|
||||
|
@ -69,20 +64,17 @@ class HttpInjectorTest extends DDSpecification {
|
|||
if (styles.contains(B3)) {
|
||||
1 * carrier.put(B3HttpCodec.TRACE_ID_KEY, traceId.toString())
|
||||
1 * carrier.put(B3HttpCodec.SPAN_ID_KEY, spanId.toString())
|
||||
if (samplingPriority != PrioritySampling.UNSET) {
|
||||
1 * carrier.put(B3HttpCodec.SAMPLING_PRIORITY_KEY, "1")
|
||||
}
|
||||
}
|
||||
0 * _
|
||||
|
||||
where:
|
||||
styles | samplingPriority | origin
|
||||
[DATADOG, B3] | PrioritySampling.UNSET | null
|
||||
[DATADOG, B3] | PrioritySampling.SAMPLER_KEEP | "saipan"
|
||||
[DATADOG] | PrioritySampling.UNSET | null
|
||||
[DATADOG] | PrioritySampling.SAMPLER_KEEP | "saipan"
|
||||
[B3] | PrioritySampling.UNSET | null
|
||||
[B3] | PrioritySampling.SAMPLER_KEEP | "saipan"
|
||||
[B3, DATADOG] | PrioritySampling.SAMPLER_KEEP | "saipan"
|
||||
styles | origin
|
||||
[DATADOG, B3] | null
|
||||
[DATADOG, B3] | "saipan"
|
||||
[DATADOG] | null
|
||||
[DATADOG] | "saipan"
|
||||
[B3] | null
|
||||
[B3] | "saipan"
|
||||
[B3, DATADOG] | "saipan"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package datadog.trace
|
|||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.propagation.HttpCodec
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.common.sampling.AllSampler
|
||||
import datadog.trace.common.sampling.RateByServiceSampler
|
||||
import datadog.trace.common.writer.DDAgentWriter
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.common.writer.LoggingWriter
|
||||
|
@ -18,7 +16,6 @@ import static datadog.trace.api.Config.HEADER_TAGS
|
|||
import static datadog.trace.api.Config.HEALTH_METRICS_ENABLED
|
||||
import static datadog.trace.api.Config.HEALTH_METRICS_STATSD_PORT
|
||||
import static datadog.trace.api.Config.PREFIX
|
||||
import static datadog.trace.api.Config.PRIORITY_SAMPLING
|
||||
import static datadog.trace.api.Config.SERVICE_MAPPING
|
||||
import static datadog.trace.api.Config.SPAN_TAGS
|
||||
import static datadog.trace.api.Config.WRITER_TYPE
|
||||
|
@ -46,11 +43,10 @@ class DDTracerTest extends DDSpecification {
|
|||
|
||||
then:
|
||||
tracer.serviceName == "unnamed-java-app"
|
||||
tracer.sampler instanceof RateByServiceSampler
|
||||
tracer.writer.toString() == "DDAgentWriter { api=DDApi { tracesUrl=http://localhost:8126/v0.3/traces } }"
|
||||
tracer.writer.monitor instanceof DDAgentWriter.NoopMonitor
|
||||
|
||||
tracer.spanContextDecorators.size() == 15
|
||||
tracer.spanContextDecorators.size() == 12
|
||||
|
||||
tracer.injector instanceof HttpCodec.CompoundInjector
|
||||
tracer.extractor instanceof HttpCodec.CompoundExtractor
|
||||
|
@ -70,15 +66,6 @@ class DDTracerTest extends DDSpecification {
|
|||
}
|
||||
|
||||
|
||||
def "verify overriding sampler"() {
|
||||
setup:
|
||||
System.setProperty(PREFIX + PRIORITY_SAMPLING, "false")
|
||||
when:
|
||||
def tracer = new DDTracer(new Config())
|
||||
then:
|
||||
tracer.sampler instanceof AllSampler
|
||||
}
|
||||
|
||||
def "verify overriding writer"() {
|
||||
setup:
|
||||
System.setProperty(PREFIX + WRITER_TYPE, "LoggingWriter")
|
||||
|
@ -131,40 +118,23 @@ class DDTracerTest extends DDSpecification {
|
|||
"writer" | "trace.agent.port" | "9999" | "DDAgentWriter { api=DDApi { tracesUrl=http://localhost:9999/v0.3/traces } }"
|
||||
}
|
||||
|
||||
def "verify sampler/writer constructor"() {
|
||||
def "verify writer constructor"() {
|
||||
setup:
|
||||
def writer = new ListWriter()
|
||||
def sampler = new RateByServiceSampler()
|
||||
|
||||
when:
|
||||
def tracer = new DDTracer(DEFAULT_SERVICE_NAME, writer, sampler)
|
||||
def tracer = new DDTracer(DEFAULT_SERVICE_NAME, writer)
|
||||
|
||||
then:
|
||||
tracer.serviceName == DEFAULT_SERVICE_NAME
|
||||
tracer.sampler == sampler
|
||||
tracer.writer == writer
|
||||
tracer.localRootSpanTags[Config.RUNTIME_ID_TAG].size() > 0 // not null or empty
|
||||
tracer.localRootSpanTags[Config.LANGUAGE_TAG_KEY] == Config.LANGUAGE_TAG_VALUE
|
||||
}
|
||||
|
||||
def "Shares TraceCount with DDApi with #key = #value"() {
|
||||
setup:
|
||||
System.setProperty(PREFIX + key, value)
|
||||
final DDTracer tracer = new DDTracer(new Config())
|
||||
|
||||
expect:
|
||||
tracer.writer instanceof DDAgentWriter
|
||||
tracer.writer.traceCount.is(((DDAgentWriter) tracer.writer).traceCount)
|
||||
|
||||
where:
|
||||
key | value
|
||||
PRIORITY_SAMPLING | "true"
|
||||
PRIORITY_SAMPLING | "false"
|
||||
}
|
||||
|
||||
def "root tags are applied only to root spans"() {
|
||||
setup:
|
||||
def tracer = new DDTracer('my_service', new ListWriter(), new AllSampler(), '', ['only_root': 'value'], [:], [:], [:])
|
||||
def tracer = new DDTracer('my_service', new ListWriter(), '', ['only_root': 'value'], [:], [:], [:])
|
||||
def root = tracer.buildSpan('my_root').start()
|
||||
def child = tracer.buildSpan('my_child').asChildOf(root).start()
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package datadog.trace.api.sampling
|
||||
|
||||
import datadog.opentracing.DDSpan
|
||||
import datadog.trace.common.sampling.AllSampler
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
import spock.lang.Subject
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class AllSamplerTest extends DDSpecification {
|
||||
|
||||
@Subject
|
||||
DDSpan span = Mock()
|
||||
|
||||
private final AllSampler sampler = new AllSampler()
|
||||
|
||||
def "test AllSampler"() {
|
||||
expect:
|
||||
for (int i = 0; i < 500; i++) {
|
||||
assert sampler.doSample(span)
|
||||
}
|
||||
}
|
||||
|
||||
def "test skip tag sampler"() {
|
||||
setup:
|
||||
final Map<String, Object> tags = new HashMap<>()
|
||||
2 * span.getTags() >> tags
|
||||
sampler.addSkipTagPattern("http.url", Pattern.compile(".*/hello"))
|
||||
|
||||
when:
|
||||
tags.put("http.url", "http://a/hello")
|
||||
|
||||
then:
|
||||
!sampler.sample(span)
|
||||
|
||||
when:
|
||||
tags.put("http.url", "http://a/hello2")
|
||||
|
||||
then:
|
||||
sampler.sample(span)
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package datadog.trace.api.sampling
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import datadog.opentracing.DDSpan
|
||||
import datadog.opentracing.SpanFactory
|
||||
import datadog.trace.common.sampling.RateByServiceSampler
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
|
||||
import static datadog.trace.common.sampling.RateByServiceSampler.DEFAULT_KEY
|
||||
|
||||
class RateByServiceSamplerTest extends DDSpecification {
|
||||
|
||||
def "invalid rate -> 1"() {
|
||||
setup:
|
||||
RateByServiceSampler serviceSampler = new RateByServiceSampler()
|
||||
ObjectMapper serializer = new ObjectMapper()
|
||||
String response = '{"rate_by_service": {"service:,env:":' + rate + '}}'
|
||||
serviceSampler.onResponse("traces", serializer.readTree(response))
|
||||
expect:
|
||||
serviceSampler.serviceRates[DEFAULT_KEY].sampleRate == expectedRate
|
||||
|
||||
where:
|
||||
rate | expectedRate
|
||||
null | 1
|
||||
1 | 1
|
||||
0 | 0.0
|
||||
-5 | 1
|
||||
5 | 1
|
||||
0.5 | 0.5
|
||||
}
|
||||
|
||||
def "rate by service name"() {
|
||||
setup:
|
||||
RateByServiceSampler serviceSampler = new RateByServiceSampler()
|
||||
ObjectMapper serializer = new ObjectMapper()
|
||||
|
||||
when:
|
||||
String response = '{"rate_by_service": {"service:spock,env:test":0.0}}'
|
||||
serviceSampler.onResponse("traces", serializer.readTree(response))
|
||||
DDSpan span1 = SpanFactory.newSpanOf("foo", "bar")
|
||||
serviceSampler.initializeSamplingPriority(span1)
|
||||
then:
|
||||
span1.getSamplingPriority() == PrioritySampling.SAMPLER_KEEP
|
||||
serviceSampler.sample(span1)
|
||||
|
||||
when:
|
||||
response = '{"rate_by_service": {"service:spock,env:test":1.0}}'
|
||||
serviceSampler.onResponse("traces", serializer.readTree(response))
|
||||
DDSpan span2 = SpanFactory.newSpanOf("spock", "test")
|
||||
serviceSampler.initializeSamplingPriority(span2)
|
||||
then:
|
||||
span2.getSamplingPriority() == PrioritySampling.SAMPLER_KEEP
|
||||
serviceSampler.sample(span2)
|
||||
}
|
||||
|
||||
def "sampling priority set on context"() {
|
||||
setup:
|
||||
RateByServiceSampler serviceSampler = new RateByServiceSampler()
|
||||
ObjectMapper serializer = new ObjectMapper()
|
||||
String response = '{"rate_by_service": {"service:,env:":1.0}}'
|
||||
serviceSampler.onResponse("traces", serializer.readTree(response))
|
||||
|
||||
DDSpan span = SpanFactory.newSpanOf("foo", "bar")
|
||||
serviceSampler.initializeSamplingPriority(span)
|
||||
expect:
|
||||
// sets correctly on root span
|
||||
span.getSamplingPriority() == PrioritySampling.SAMPLER_KEEP
|
||||
// RateByServiceSamler must not set the sample rate
|
||||
span.getMetrics().get("_sample_rate") == null
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import datadog.opentracing.DDSpan
|
|||
import datadog.opentracing.DDSpanContext
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.PendingTrace
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.DDAgentWriter
|
||||
import datadog.trace.common.writer.DDApi
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
|
@ -167,7 +166,6 @@ class DDAgentWriterTest extends DDSpecification {
|
|||
"",
|
||||
"",
|
||||
"",
|
||||
PrioritySampling.UNSET,
|
||||
"",
|
||||
Collections.emptyMap(),
|
||||
false,
|
||||
|
@ -205,7 +203,6 @@ class DDAgentWriterTest extends DDSpecification {
|
|||
"",
|
||||
"",
|
||||
"",
|
||||
PrioritySampling.UNSET,
|
||||
"",
|
||||
Collections.emptyMap(),
|
||||
false,
|
||||
|
|
|
@ -3,7 +3,6 @@ import datadog.opentracing.DDSpan
|
|||
import datadog.opentracing.DDSpanContext
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.opentracing.PendingTrace
|
||||
import datadog.trace.api.sampling.PrioritySampling
|
||||
import datadog.trace.common.writer.DDApi
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import datadog.trace.util.test.DDSpecification
|
||||
|
@ -30,7 +29,6 @@ class DDApiIntegrationTest {
|
|||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
PrioritySampling.UNSET,
|
||||
null,
|
||||
Collections.emptyMap(),
|
||||
false,
|
||||
|
|
Loading…
Reference in New Issue