Remove globally applied tags (#32)

This commit is contained in:
Trask Stalnaker 2019-12-02 19:12:44 -08:00 committed by GitHub
parent 0514c6655d
commit a4089ff1fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 12 additions and 367 deletions

View File

@ -1,6 +1,5 @@
package datadog.trace.agent.decorator;
import datadog.trace.api.Config;
import datadog.trace.instrumentation.api.AgentSpan;
import io.opentracing.tag.Tags;
@ -10,7 +9,6 @@ public abstract class ServerDecorator extends BaseDecorator {
public AgentSpan afterStart(final AgentSpan span) {
assert span != null;
span.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
span.setTag(Config.LANGUAGE_TAG_KEY, Config.LANGUAGE_TAG_VALUE);
return super.afterStart(span);
}
}

View File

@ -1,6 +1,6 @@
package datadog.trace.agent.decorator
import datadog.trace.api.Config
import datadog.trace.api.DDTags
import datadog.trace.instrumentation.api.AgentSpan
import io.opentracing.tag.Tags
@ -15,7 +15,6 @@ class ServerDecoratorTest extends BaseDecoratorTest {
decorator.afterStart(span)
then:
1 * span.setTag(Config.LANGUAGE_TAG_KEY, Config.LANGUAGE_TAG_VALUE)
1 * span.setTag(Tags.COMPONENT.key, "test-component")
1 * span.setTag(Tags.SPAN_KIND.key, "server")
1 * span.setTag(DDTags.SPAN_TYPE, decorator.spanType())

View File

@ -1,8 +1,6 @@
package datadog.trace.agent.test.asserts
import datadog.opentracing.DDSpan
import datadog.trace.api.Config
import datadog.trace.instrumentation.api.Tags
import groovy.transform.stc.ClosureParams
import groovy.transform.stc.SimpleType
@ -35,27 +33,9 @@ class TagsAssert {
def defaultTags(boolean distributedRootSpan = false) {
assertedTags.add("thread.name")
assertedTags.add("thread.id")
assertedTags.add(Config.RUNTIME_ID_TAG)
assertedTags.add(Config.LANGUAGE_TAG_KEY)
assert tags["thread.name"] != null
assert tags["thread.id"] != null
// FIXME: DQH - Too much conditional logic? Maybe create specialized methods for client & server cases
boolean isRoot = (0G == spanParentId)
if (isRoot || distributedRootSpan) {
assert tags[Config.RUNTIME_ID_TAG] == Config.get().runtimeId
} else {
assert tags[Config.RUNTIME_ID_TAG] == null
}
boolean isServer = (tags[Tags.SPAN_KIND] == Tags.SPAN_KIND_SERVER)
if (isRoot || distributedRootSpan || isServer) {
assert tags[Config.LANGUAGE_TAG_KEY] == Config.LANGUAGE_TAG_VALUE
} else {
assert tags[Config.LANGUAGE_TAG_KEY] == null
}
}
def errorTags(Class<Throwable> errorType) {

View File

@ -9,7 +9,6 @@ import java.util.concurrent.Callable
class ConfigUtils {
static final CONFIG_INSTANCE_FIELD = Config.getDeclaredField("INSTANCE")
static final RUNTIME_ID_FIELD = Config.getDeclaredField("runtimeId")
@SneakyThrows
synchronized static <T extends Object> Object withConfigOverride(final String name, final String value, final Callable<T> r) {
@ -52,16 +51,7 @@ class ConfigUtils {
assert Modifier.isVolatile(CONFIG_INSTANCE_FIELD.getModifiers())
assert !Modifier.isFinal(CONFIG_INSTANCE_FIELD.getModifiers())
assert Modifier.isPublic(RUNTIME_ID_FIELD.getModifiers())
assert !Modifier.isStatic(RUNTIME_ID_FIELD.getModifiers())
assert Modifier.isVolatile(RUNTIME_ID_FIELD.getModifiers())
assert !Modifier.isFinal(RUNTIME_ID_FIELD.getModifiers())
def previousConfig = CONFIG_INSTANCE_FIELD.get(null)
def newConfig = new Config()
CONFIG_INSTANCE_FIELD.set(null, newConfig)
if (previousConfig != null) {
RUNTIME_ID_FIELD.set(newConfig, RUNTIME_ID_FIELD.get(previousConfig))
}
}
}

View File

@ -14,7 +14,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
import java.util.UUID;
import java.util.regex.Pattern;
import lombok.Getter;
import lombok.ToString;
@ -43,9 +42,6 @@ public class Config {
public static final String INTEGRATIONS_ENABLED = "integrations.enabled";
public static final String WRITER_TYPE = "writer.type";
public static final String TRACE_RESOLVER_ENABLED = "trace.resolver.enabled";
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_ANNOTATIONS = "trace.annotations";
public static final String TRACE_EXECUTORS_ALL = "trace.executors.all";
public static final String TRACE_EXECUTORS = "trace.executors";
@ -63,12 +59,6 @@ public class Config {
public static final String LOGS_INJECTION_ENABLED = "logs.injection";
public static final String SERVICE_TAG = "service";
@Deprecated public static final String SERVICE = SERVICE_TAG; // To be removed in 0.34.0
public static final String RUNTIME_ID_TAG = "runtime-id";
public static final String LANGUAGE_TAG_KEY = "language";
public static final String LANGUAGE_TAG_VALUE = "jvm";
public static final String DEFAULT_SERVICE_NAME = "unnamed-java-app";
private static final boolean DEFAULT_TRACE_ENABLED = true;
@ -98,20 +88,11 @@ public class Config {
private static final String DEFAULT_TRACE_EXECUTORS = "";
private static final String DEFAULT_TRACE_METHODS = null;
/**
* this is a random UUID that gets generated on JVM start up and is attached to every root span
* and every JMX metric that is sent out.
*/
@Getter private final String runtimeId;
@Getter private final String serviceName;
@Getter private final boolean traceEnabled;
@Getter private final boolean integrationsEnabled;
@Getter private final String writerType;
@Getter private final boolean traceResolverEnabled;
private final Map<String, String> globalTags;
private final Map<String, String> spanTags;
private final Map<String, String> jmxTags;
@Getter private final List<String> excludedClasses;
@Getter private final Set<Integer> httpServerErrorStatuses;
@Getter private final Set<Integer> httpClientErrorStatuses;
@ -139,8 +120,6 @@ public class Config {
Config() {
propertiesFromConfigFile = loadConfigurationFile();
runtimeId = UUID.randomUUID().toString();
serviceName = getSettingFromEnvironment(SERVICE_NAME, DEFAULT_SERVICE_NAME);
traceEnabled = getBooleanSettingFromEnvironment(TRACE_ENABLED, DEFAULT_TRACE_ENABLED);
@ -150,10 +129,6 @@ public class Config {
traceResolverEnabled =
getBooleanSettingFromEnvironment(TRACE_RESOLVER_ENABLED, DEFAULT_TRACE_RESOLVER_ENABLED);
globalTags = getMapSettingFromEnvironment(GLOBAL_TAGS, null);
spanTags = getMapSettingFromEnvironment(SPAN_TAGS, null);
jmxTags = getMapSettingFromEnvironment(JMX_TAGS, null);
excludedClasses = getListSettingFromEnvironment(TRACE_CLASSES_EXCLUDE, null);
httpServerErrorStatuses =
@ -204,7 +179,6 @@ public class Config {
// Read order: Properties -> Parent
private Config(final Properties properties, final Config parent) {
runtimeId = parent.runtimeId;
serviceName = properties.getProperty(SERVICE_NAME, parent.serviceName);
@ -215,9 +189,6 @@ public class Config {
traceResolverEnabled =
getPropertyBooleanValue(properties, TRACE_RESOLVER_ENABLED, parent.traceResolverEnabled);
globalTags = getPropertyMapValue(properties, GLOBAL_TAGS, parent.globalTags);
spanTags = getPropertyMapValue(properties, SPAN_TAGS, parent.spanTags);
jmxTags = getPropertyMapValue(properties, JMX_TAGS, parent.jmxTags);
excludedClasses =
getPropertyListValue(properties, TRACE_CLASSES_EXCLUDE, parent.excludedClasses);
@ -266,53 +237,6 @@ public class Config {
log.debug("New instance: {}", this);
}
/** @return A map of tags to be applied only to the local application root span. */
public Map<String, String> getLocalRootSpanTags() {
final Map<String, String> runtimeTags = getRuntimeTags();
final Map<String, String> result = new HashMap<>(runtimeTags);
result.put(LANGUAGE_TAG_KEY, LANGUAGE_TAG_VALUE);
return Collections.unmodifiableMap(result);
}
public Map<String, String> getMergedSpanTags() {
// DO not include runtimeId into span tags: we only want that added to the root span
final Map<String, String> result = newHashMap(globalTags.size() + spanTags.size());
result.putAll(globalTags);
result.putAll(spanTags);
return Collections.unmodifiableMap(result);
}
public Map<String, String> getMergedJmxTags() {
final Map<String, String> runtimeTags = getRuntimeTags();
final Map<String, String> result =
newHashMap(
globalTags.size() + jmxTags.size() + runtimeTags.size() + 1 /* for serviceName */);
result.putAll(globalTags);
result.putAll(jmxTags);
result.putAll(runtimeTags);
// service name set here instead of getRuntimeTags because apm already manages the service tag
// and may chose to override it.
// Additionally, infra/JMX metrics require `service` rather than APM's `service.name` tag
result.put(SERVICE_TAG, serviceName);
return Collections.unmodifiableMap(result);
}
/**
* Return a map of tags required by the datadog backend to link runtime metrics (i.e. jmx) and
* traces.
*
* <p>These tags must be applied to every runtime metrics and placed on the root span of every
* trace.
*
* @return A map of tag-name -> tag-value
*/
private Map<String, String> getRuntimeTags() {
final Map<String, String> result = newHashMap(2);
result.put(RUNTIME_ID_TAG, runtimeId);
return Collections.unmodifiableMap(result);
}
public boolean isIntegrationEnabled(
final SortedSet<String> integrationNames, final boolean defaultEnabled) {
return integrationEnabled(integrationNames, defaultEnabled);
@ -377,13 +301,6 @@ public class Config {
return defaultValue;
}
/** @deprecated This method should only be used internally. Use the explicit getter instead. */
private static Map<String, String> getMapSettingFromEnvironment(
final String name, final String defaultValue) {
return parseMap(
getSettingFromEnvironment(name, defaultValue), propertyNameToSystemPropertyName(name));
}
/**
* Calls {@link #getSettingFromEnvironment(String, String)} and converts the result to a list by
* splitting on `,`.

View File

@ -7,18 +7,13 @@ import org.junit.contrib.java.lang.system.RestoreSystemProperties
import static datadog.trace.api.Config.CONFIGURATION_FILE
import static datadog.trace.api.Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE
import static datadog.trace.api.Config.GLOBAL_TAGS
import static datadog.trace.api.Config.HTTP_CLIENT_ERROR_STATUSES
import static datadog.trace.api.Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN
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.RUNTIME_CONTEXT_FIELD_INJECTION
import static datadog.trace.api.Config.RUNTIME_ID_TAG
import static datadog.trace.api.Config.SERVICE_NAME
import static datadog.trace.api.Config.SERVICE_TAG
import static datadog.trace.api.Config.SPAN_TAGS
import static datadog.trace.api.Config.TRACE_ENABLED
import static datadog.trace.api.Config.TRACE_RESOLVER_ENABLED
import static datadog.trace.api.Config.WRITER_TYPE
@ -32,7 +27,6 @@ class ConfigTest extends DDSpecification {
private static final DD_SERVICE_NAME_ENV = "DD_SERVICE_NAME"
private static final DD_TRACE_ENABLED_ENV = "DD_TRACE_ENABLED"
private static final DD_WRITER_TYPE_ENV = "DD_WRITER_TYPE"
private static final DD_SPAN_TAGS_ENV = "DD_SPAN_TAGS"
def "verify defaults"() {
when:
@ -43,8 +37,6 @@ class ConfigTest extends DDSpecification {
config.traceEnabled == true
config.writerType == "LoggingWriter"
config.traceResolverEnabled == true
config.mergedSpanTags == [:]
config.mergedJmxTags == [(RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName]
config.httpServerErrorStatuses == (500..599).toSet()
config.httpClientErrorStatuses == (400..499).toSet()
config.httpClientSplitByDomain == false
@ -68,9 +60,6 @@ class ConfigTest extends DDSpecification {
prop.setProperty(TRACE_ENABLED, "false")
prop.setProperty(WRITER_TYPE, "LoggingWriter")
prop.setProperty(TRACE_RESOLVER_ENABLED, "false")
prop.setProperty(GLOBAL_TAGS, "b:2")
prop.setProperty(SPAN_TAGS, "c:3")
prop.setProperty(JMX_TAGS, "d:4")
prop.setProperty(HTTP_SERVER_ERROR_STATUSES, "123-456,457,124-125,122")
prop.setProperty(HTTP_CLIENT_ERROR_STATUSES, "111")
prop.setProperty(HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
@ -86,8 +75,6 @@ class ConfigTest extends DDSpecification {
config.traceEnabled == false
config.writerType == "LoggingWriter"
config.traceResolverEnabled == false
config.mergedSpanTags == [b: "2", c: "3"]
config.mergedJmxTags == [b: "2", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName]
config.httpServerErrorStatuses == (122..457).toSet()
config.httpClientErrorStatuses == (111..111).toSet()
config.httpClientSplitByDomain == true
@ -102,9 +89,6 @@ class ConfigTest extends DDSpecification {
System.setProperty(PREFIX + TRACE_ENABLED, "false")
System.setProperty(PREFIX + WRITER_TYPE, "LoggingWriter")
System.setProperty(PREFIX + TRACE_RESOLVER_ENABLED, "false")
System.setProperty(PREFIX + GLOBAL_TAGS, "b:2")
System.setProperty(PREFIX + SPAN_TAGS, "c:3")
System.setProperty(PREFIX + JMX_TAGS, "d:4")
System.setProperty(PREFIX + HTTP_SERVER_ERROR_STATUSES, "123-456,457,124-125,122")
System.setProperty(PREFIX + HTTP_CLIENT_ERROR_STATUSES, "111")
System.setProperty(PREFIX + HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
@ -120,8 +104,6 @@ class ConfigTest extends DDSpecification {
config.traceEnabled == false
config.writerType == "LoggingWriter"
config.traceResolverEnabled == false
config.mergedSpanTags == [b: "2", c: "3"]
config.mergedJmxTags == [b: "2", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName]
config.httpServerErrorStatuses == (122..457).toSet()
config.httpClientErrorStatuses == (111..111).toSet()
config.httpClientSplitByDomain == true
@ -167,7 +149,6 @@ class ConfigTest extends DDSpecification {
System.setProperty(PREFIX + TRACE_ENABLED, " ")
System.setProperty(PREFIX + WRITER_TYPE, " ")
System.setProperty(PREFIX + TRACE_RESOLVER_ENABLED, " ")
System.setProperty(PREFIX + SPAN_TAGS, "invalid")
System.setProperty(PREFIX + HTTP_SERVER_ERROR_STATUSES, "1111")
System.setProperty(PREFIX + HTTP_CLIENT_ERROR_STATUSES, "1:1")
System.setProperty(PREFIX + HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "invalid")
@ -181,7 +162,6 @@ class ConfigTest extends DDSpecification {
config.traceEnabled == true
config.writerType == " "
config.traceResolverEnabled == true
config.mergedSpanTags == [:]
config.httpServerErrorStatuses == (500..599).toSet()
config.httpClientErrorStatuses == (400..499).toSet()
config.httpClientSplitByDomain == false
@ -195,9 +175,6 @@ class ConfigTest extends DDSpecification {
properties.setProperty(TRACE_ENABLED, "false")
properties.setProperty(WRITER_TYPE, "LoggingWriter")
properties.setProperty(TRACE_RESOLVER_ENABLED, "false")
properties.setProperty(GLOBAL_TAGS, "b:2")
properties.setProperty(SPAN_TAGS, "c:3")
properties.setProperty(JMX_TAGS, "d:4")
properties.setProperty(HTTP_SERVER_ERROR_STATUSES, "123-456,457,124-125,122")
properties.setProperty(HTTP_CLIENT_ERROR_STATUSES, "111")
properties.setProperty(HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
@ -212,8 +189,6 @@ class ConfigTest extends DDSpecification {
config.traceEnabled == false
config.writerType == "LoggingWriter"
config.traceResolverEnabled == false
config.mergedSpanTags == [b: "2", c: "3"]
config.mergedJmxTags == [b: "2", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName]
config.httpServerErrorStatuses == (122..457).toSet()
config.httpClientErrorStatuses == (111..111).toSet()
config.httpClientSplitByDomain == true
@ -318,42 +293,6 @@ class ConfigTest extends DDSpecification {
defaultValue = 10.0
}
def "verify mapping configs on tracer"() {
setup:
System.setProperty(PREFIX + SPAN_TAGS, mapString)
def props = new Properties()
props.setProperty(SPAN_TAGS, mapString)
when:
def config = new Config()
def propConfig = Config.get(props)
then:
config.spanTags == map
propConfig.spanTags == map
where:
mapString | map
"a:1, a:2, a:3" | [a: "3"]
"a:b,c:d,e:" | [a: "b", c: "d"]
// More different string variants:
"a:" | [:]
"a:a;" | [a: "a;"]
"a:1, a:2, a:3" | [a: "3"]
"a:b,c:d,e:" | [a: "b", c: "d"]
"key 1!:va|ue_1," | ["key 1!": "va|ue_1"]
" key1 :value1 ,\t key2: value2" | [key1: "value1", key2: "value2"]
// Invalid strings:
"" | [:]
"1" | [:]
"a" | [:]
"a,1" | [:]
"in:val:id" | [:]
"a:b:c:d" | [:]
"a:b,c,d" | [:]
"!a" | [:]
}
def "verify integer range configs on tracer"() {
setup:
System.setProperty(PREFIX + HTTP_SERVER_ERROR_STATUSES, value)
@ -393,33 +332,6 @@ class ConfigTest extends DDSpecification {
" 400 - 403 , 405 " | [400, 401, 402, 403, 405]
}
def "verify null value mapping configs on tracer"() {
setup:
environmentVariables.set(DD_SPAN_TAGS_ENV, mapString)
when:
def config = new Config()
then:
config.spanTags == map
where:
mapString | map
null | [:]
"" | [:]
}
def "verify hostname not added to root span tags by default"() {
setup:
Properties properties = new Properties()
when:
def config = Config.get(properties)
then:
!config.localRootSpanTags.containsKey('_dd.hostname')
}
def "verify fallback to properties file"() {
setup:
System.setProperty(PREFIX + CONFIGURATION_FILE, "src/test/resources/dd-java-tracer.properties")

View File

@ -23,7 +23,6 @@ import java.lang.ref.WeakReference;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -48,11 +47,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
/** Scope manager is in charge of managing the scopes from which spans are created */
final ContextualScopeManager scopeManager = new ContextualScopeManager();
/** A set of tags that are added only to the application's root span */
private final Map<String, String> localRootSpanTags;
/** A set of tags that are added to every span */
private final Map<String, String> defaultSpanTags;
/** number of spans in a pending trace before they get flushed */
@Getter private final int partialFlushMinSpans;
@ -86,84 +80,28 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
this(config.getServiceName(), config);
}
// 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) {
this(serviceName, writer, Config.get().getLocalRootSpanTags());
}
private DDTracer(final String serviceName, final Config config) {
this(
serviceName,
Writer.Builder.forConfig(config),
config.getLocalRootSpanTags(),
config.getMergedSpanTags(),
config.getPartialFlushMinSpans());
this(serviceName, Writer.Builder.forConfig(config), config.getPartialFlushMinSpans());
log.debug("Using config: {}", config);
}
/** Visible for testing */
DDTracer(final String serviceName, final Writer writer, final Map<String, String> runtimeTags) {
this(serviceName, writer, runtimeTags, Collections.<String, String>emptyMap(), 0);
}
public DDTracer(final Writer writer) {
this(Config.get(), writer);
}
public DDTracer(final Config config, final Writer writer) {
this(
config.getServiceName(),
writer,
config.getLocalRootSpanTags(),
config.getMergedSpanTags(),
config.getPartialFlushMinSpans());
this(config.getServiceName(), writer, config.getPartialFlushMinSpans());
}
/** @deprecated Use {@link #DDTracer(String, Writer, Map, Map, int)} instead. */
@Deprecated
public DDTracer(
final String serviceName,
final Writer writer,
final String runtimeId,
final Map<String, String> localRootSpanTags,
final Map<String, String> defaultSpanTags) {
this(
serviceName,
writer,
customRuntimeTags(runtimeId, localRootSpanTags),
defaultSpanTags,
Config.get().getPartialFlushMinSpans());
public DDTracer(final String serviceName, final Writer writer) {
this(serviceName, writer, Config.get().getPartialFlushMinSpans());
}
/** @deprecated Use {@link #DDTracer(String, Writer, Map, Map,int)} instead. */
@Deprecated
public DDTracer(
final String serviceName,
final Writer writer,
final Map<String, String> localRootSpanTags,
final Map<String, String> defaultSpanTags) {
this(
serviceName,
writer,
localRootSpanTags,
defaultSpanTags,
Config.get().getPartialFlushMinSpans());
}
public DDTracer(
final String serviceName,
final Writer writer,
final Map<String, String> localRootSpanTags,
final Map<String, String> defaultSpanTags,
final int partialFlushMinSpans) {
assert localRootSpanTags != null;
assert defaultSpanTags != null;
public DDTracer(final String serviceName, final Writer writer, final int partialFlushMinSpans) {
this.serviceName = serviceName;
this.writer = writer;
this.writer.start();
this.localRootSpanTags = localRootSpanTags;
this.defaultSpanTags = defaultSpanTags;
this.partialFlushMinSpans = partialFlushMinSpans;
shutdownCallback = new ShutdownHook(this);
@ -326,19 +264,9 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
+ serviceName
+ ", writer="
+ writer
+ ", defaultSpanTags="
+ defaultSpanTags
+ '}';
}
@Deprecated
private static Map<String, String> customRuntimeTags(
final String runtimeId, final Map<String, String> applicationRootSpanTags) {
final Map<String, String> runtimeTags = new HashMap<>(applicationRootSpanTags);
runtimeTags.put(Config.RUNTIME_ID_TAG, runtimeId);
return Collections.unmodifiableMap(runtimeTags);
}
/** Spans are built using this builder */
public class DDSpanBuilder implements SpanBuilder {
private final ScopeManager scopeManager;
@ -347,7 +275,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
private final String operationName;
// Builder attributes
private final Map<String, Object> tags = new HashMap<String, Object>(defaultSpanTags);
private final Map<String, Object> tags = new HashMap<>();
private long timestampMicro;
private SpanContext parent;
private String serviceName;
@ -536,8 +464,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
parentSpanId = BigInteger.ZERO;
}
tags.putAll(localRootSpanTags);
parentTrace = new PendingTrace(DDTracer.this, traceId);
}

View File

@ -53,10 +53,8 @@ class DDSpanBuilderTest extends DDSpecification {
then:
span.getTags() == [
(DDTags.THREAD_NAME) : Thread.currentThread().getName(),
(DDTags.THREAD_ID) : Thread.currentThread().getId(),
(Config.RUNTIME_ID_TAG) : config.getRuntimeId(),
(Config.LANGUAGE_TAG_KEY): Config.LANGUAGE_TAG_VALUE,
(DDTags.THREAD_NAME): Thread.currentThread().getName(),
(DDTags.THREAD_ID) : Thread.currentThread().getId()
]
when:
@ -400,31 +398,4 @@ class DDSpanBuilderTest extends DDSpecification {
new ExtractedContext(1G, 2G) | _
new ExtractedContext(3G, 4G) | _
}
def "global span tags populated on each span"() {
setup:
System.setProperty("dd.trace.span.tags", tagString)
def config = new Config()
tracer = new DDTracer(config, writer)
def span = tracer.buildSpan("op name").withServiceName("foo").start()
expect:
span.tags == tags + [
(DDTags.THREAD_NAME) : Thread.currentThread().getName(),
(DDTags.THREAD_ID) : Thread.currentThread().getId(),
(Config.RUNTIME_ID_TAG) : config.getRuntimeId(),
(Config.LANGUAGE_TAG_KEY): Config.LANGUAGE_TAG_VALUE,
]
cleanup:
System.clearProperty("dd.trace.span.tags")
where:
tagString | tags
"" | [:]
"in:val:id" | [:]
"a:x" | [a: "x"]
"a:a,a:b,a:c" | [a: "c"]
"a:1,b-c:d" | [a: "1", "b-c": "d"]
}
}

View File

@ -12,7 +12,7 @@ import static datadog.trace.api.Config.DEFAULT_SERVICE_NAME
class DDSpanTest extends DDSpecification {
def writer = new ListWriter()
def tracer = new DDTracer(DEFAULT_SERVICE_NAME, writer, [:])
def tracer = new DDTracer(DEFAULT_SERVICE_NAME, writer)
def "getters and setters"() {
setup:

View File

@ -11,7 +11,6 @@ import io.opentracing.tag.StringTag
import io.opentracing.tag.Tags
import static datadog.trace.api.Config.DEFAULT_SERVICE_NAME
import static java.util.Collections.emptyMap
class SpanDecoratorTest extends DDSpecification {
@ -42,10 +41,7 @@ class SpanDecoratorTest extends DDSpecification {
setup:
tracer = new DDTracer(
"wrong-service",
new LoggingWriter(),
"some-runtime-id",
emptyMap(),
emptyMap()
new LoggingWriter()
)
when:
@ -86,10 +82,7 @@ class SpanDecoratorTest extends DDSpecification {
setup:
tracer = new DDTracer(
serviceName,
new LoggingWriter(),
"some-runtime-id",
emptyMap(),
emptyMap()
new LoggingWriter()
)
when:

View File

@ -12,7 +12,6 @@ import org.junit.contrib.java.lang.system.RestoreSystemProperties
import static datadog.trace.api.Config.DEFAULT_SERVICE_NAME
import static datadog.trace.api.Config.PREFIX
import static datadog.trace.api.Config.SPAN_TAGS
import static datadog.trace.api.Config.WRITER_TYPE
class DDTracerTest extends DDSpecification {
@ -56,23 +55,6 @@ class DDTracerTest extends DDSpecification {
tracer.writer instanceof LoggingWriter
}
def "verify mapping configs on tracer"() {
setup:
System.setProperty(PREFIX + SPAN_TAGS, mapString)
when:
def config = new Config()
def tracer = new DDTracer(config)
then:
tracer.defaultSpanTags == map
where:
mapString | map
"a:1, a:2, a:3" | [a: "3"]
"a:b,c:d,e:" | [a: "b", c: "d"]
}
def "verify writer constructor"() {
setup:
def writer = new ListWriter()
@ -83,22 +65,5 @@ class DDTracerTest extends DDSpecification {
then:
tracer.serviceName == DEFAULT_SERVICE_NAME
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 "root tags are applied only to root spans"() {
setup:
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()
expect:
root.context().tags.containsKey('only_root')
!child.context().tags.containsKey('only_root')
cleanup:
child.finish()
root.finish()
}
}

View File

@ -42,12 +42,6 @@ abstract class DDSpecification extends Specification {
.field(named("INSTANCE"))
.transform(Transformer.ForField.withModifiers(PUBLIC, STATIC, VOLATILE))
}
// Making runtimeId modifiable so that it can be preserved when resetting config in tests
.transform { builder, typeDescription, classLoader, module ->
builder
.field(named("runtimeId"))
.transform(Transformer.ForField.withModifiers(PUBLIC, VOLATILE))
}
.installOn(instrumentation)
isConfigInstanceModifiable = true
}