Update tests for `language` tag in root span
MODIFY
dd-java-agent/instrumentation/kafka-clients-0.11/src/test/groovy/KafkaClientTest.groovy
dd-java-agent/instrumentation/kafka-clients-0.11/src/test/groovy/KafkaClientTest.groovy
import datadog.trace.agent.test.AgentTestRunner
-import datadog.trace.api.Config
import org.apache.kafka.clients.consumer.ConsumerRecord
import org.junit.ClassRule
import org.springframework.kafka.core.DefaultKafkaConsumerFactory
@@ -75,59 +74,49 @@ class KafkaClientTest extends AgentTestRunner {
received.value() == greeting
received.key() == null
- TEST_WRITER.waitForTraces(2)
- TEST_WRITER.size() == 2
-
- def t1 = TEST_WRITER.get(0)
- t1.size() == 1
- def t2 = TEST_WRITER.get(1)
- t2.size() == 1
-
- and: // PRODUCER span 0
- def t1span1 = t1[0]
-
- t1span1.context().operationName == "kafka.produce"
- t1span1.serviceName == "kafka"
- t1span1.resourceName == "Produce Topic $SHARED_TOPIC"
- t1span1.type == "queue"
- !t1span1.context().getErrorFlag()
- t1span1.context().parentId == "0"
-
- def t1tags1 = t1span1.context().tags
- t1tags1["component"] == "java-kafka"
- t1tags1["span.kind"] == "producer"
- t1tags1["span.type"] == "queue"
- t1tags1["thread.name"] != null
- t1tags1["thread.id"] != null
- t1tags1[Config.RUNTIME_ID_TAG] == Config.get().runtimeId
- t1tags1.size() == 6
-
- and: // CONSUMER span 0
- def t2span1 = t2[0]
-
- t2span1.context().operationName == "kafka.consume"
- t2span1.serviceName == "kafka"
- t2span1.resourceName == "Consume Topic $SHARED_TOPIC"
- t2span1.type == "queue"
- !t2span1.context().getErrorFlag()
- t2span1.context().parentId == t1span1.context().spanId
-
- def t2tags1 = t2span1.context().tags
- t2tags1["component"] == "java-kafka"
- t2tags1["span.kind"] == "consumer"
- t1tags1["span.type"] == "queue"
- t2tags1["partition"] >= 0
- t2tags1["offset"] == 0
- t2tags1["thread.name"] != null
- t2tags1["thread.id"] != null
- t2tags1[Config.RUNTIME_ID_TAG] == Config.get().runtimeId
- t2tags1.size() == 8
+ assertTraces(2) {
+ trace(0, 1) {
+ // PRODUCER span 0
+ span(0) {
+ serviceName "kafka"
+ operationName "kafka.produce"
+ resourceName "Produce Topic $SHARED_TOPIC"
+ spanType "queue"
+ errored false
+ parent()
+ tags {
+ "component" "java-kafka"
+ "span.kind" "producer"
+ "span.type" "queue"
+ defaultTags()
+ }
+ }
+ }
+ trace(1, 1) {
+ // CONSUMER span 0
+ span(0) {
+ serviceName "kafka"
+ operationName "kafka.consume"
+ resourceName "Consume Topic $SHARED_TOPIC"
+ spanType "queue"
+ errored false
+ childOf TEST_WRITER[0][0]
+ tags {
+ "component" "java-kafka"
+ "span.kind" "consumer"
+ "span.type" "queue"
+ "partition" { it >= 0 }
+ "offset" 0
+ defaultTags(true)
+ }
+ }
+ }
+ }
def headers = received.headers()
headers.iterator().hasNext()
- new String(headers.headers("x-datadog-trace-id").iterator().next().value()) == "$t1span1.traceId"
- new String(headers.headers("x-datadog-parent-id").iterator().next().value()) == "$t1span1.spanId"
-
+ new String(headers.headers("x-datadog-trace-id").iterator().next().value()) == "${TEST_WRITER[0][0].traceId}"
+ new String(headers.headers("x-datadog-parent-id").iterator().next().value()) == "${TEST_WRITER[0][0].spanId}"
cleanup:
producerFactory.stop()

MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/asserts/TagsAssert.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/asserts/TagsAssert.groovy
@@ -33,13 +33,16 @@ class TagsAssert {
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
if ("0" == spanParentId || distributedRootSpan) {
assert tags[Config.RUNTIME_ID_TAG] == Config.get().runtimeId
+ assert tags[Config.LANGUAGE_TAG_KEY] == Config.LANGUAGE_TAG_VALUE
} else {
assert tags[Config.RUNTIME_ID_TAG] == null
+ assert tags[Config.LANGUAGE_TAG_KEY] == null
}
}

MODIFY
dd-trace-api/src/main/java/datadog/trace/api/Config.java
dd-trace-api/src/main/java/datadog/trace/api/Config.java
@@ -50,8 +50,8 @@ public class Config {
public static final String JMX_FETCH_STATSD_PORT = "jmxfetch.statsd.port";
public static final String RUNTIME_ID_TAG = "runtime-id";
- public static final String LANGUAGES_TAG_KEY = "languages";
- public static final String LANGUAGES_TAG_VALUE = "jvm";
+ 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";
public static final String DD_AGENT_WRITER_TYPE = "DDAgentWriter";
@@ -202,9 +202,9 @@ public class Config {
* @return A map of tag-name -> tag-value
*/
public Map<String, String> getRuntimeTags() {
- final Map<String, String> result = newHashMap(3);
+ final Map<String, String> result = newHashMap(2);
result.put(RUNTIME_ID_TAG, runtimeId);
- result.put(LANGUAGES_TAG_KEY, LANGUAGES_TAG_VALUE);
+ result.put(LANGUAGE_TAG_KEY, LANGUAGE_TAG_VALUE);
return Collections.unmodifiableMap(result);
}

MODIFY
dd-trace-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy
dd-trace-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy
@@ -35,7 +35,7 @@ class ConfigTest extends Specification {
config.traceResolverEnabled == true
config.serviceMapping == [:]
config.mergedSpanTags == [:]
- config.mergedJmxTags == [(RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_NAME): config.serviceName, (LANGUAGES_TAG_KEY): LANGUAGES_TAG_VALUE]
+ config.mergedJmxTags == [(RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_NAME): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
config.headerTags == [:]
config.runtimeContextFieldInjection == true
config.jmxFetchEnabled == false
@@ -81,7 +81,7 @@ class ConfigTest extends Specification {
config.traceResolverEnabled == false
config.serviceMapping == [a: "1"]
config.mergedSpanTags == [b: "2", c: "3"]
- config.mergedJmxTags == [b: "2", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_NAME): config.serviceName, (LANGUAGES_TAG_KEY): LANGUAGES_TAG_VALUE]
+ config.mergedJmxTags == [b: "2", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_NAME): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
config.headerTags == [e: "5"]
config.runtimeContextFieldInjection == false
config.jmxFetchEnabled == true
@@ -202,7 +202,7 @@ class ConfigTest extends Specification {
config.traceResolverEnabled == false
config.serviceMapping == [a: "1"]
config.mergedSpanTags == [b: "2", c: "3"]
- config.mergedJmxTags == [b: "2", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_NAME): config.serviceName, (LANGUAGES_TAG_KEY): LANGUAGES_TAG_VALUE]
+ config.mergedJmxTags == [b: "2", d: "4", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_NAME): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
config.headerTags == [e: "5"]
config.jmxFetchMetricsConfigs == ["/foo.yaml", "/bar.yaml"]
config.jmxFetchCheckPeriod == 100

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
@@ -54,7 +54,7 @@ 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();
- /** Tags required to link apm trades to runtime metrics */
+ /** Tags required to link apm traces to runtime metrics */
final Map<String, String> runtimeTags;
/** A set of tags that are added to every span */
private final Map<String, String> defaultSpanTags;
@@ -627,7 +627,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
tags.putAll(((TagContext) parentContext).getTags());
}
// add runtime tags to the root span
- for (Map.Entry<String, String> runtimeTag : runtimeTags.entrySet()) {
+ for (final Map.Entry<String, String> runtimeTag : runtimeTags.entrySet()) {
tags.put(runtimeTag.getKey(), runtimeTag.getValue());
}

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanBuilderTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanBuilderTest.groovy
@@ -54,7 +54,8 @@ class DDSpanBuilderTest extends Specification {
span.getTags() == [
(DDTags.THREAD_NAME) : Thread.currentThread().getName(),
(DDTags.THREAD_ID) : Thread.currentThread().getId(),
- (Config.RUNTIME_ID_TAG): config.getRuntimeId()
+ (Config.RUNTIME_ID_TAG) : config.getRuntimeId(),
+ (Config.LANGUAGE_TAG_KEY): Config.LANGUAGE_TAG_VALUE,
]
when:
@@ -389,7 +390,8 @@ class DDSpanBuilderTest extends Specification {
span.parentId == extractedContext.spanId
span.samplingPriority == extractedContext.samplingPriority
span.context().baggageItems == extractedContext.baggage
- span.context().@tags == extractedContext.tags + [(Config.RUNTIME_ID_TAG): config.getRuntimeId()]
+ span.context().@tags == extractedContext.tags + [(Config.RUNTIME_ID_TAG) : config.getRuntimeId(),
+ (Config.LANGUAGE_TAG_KEY): Config.LANGUAGE_TAG_VALUE,]
where:
extractedContext | _
@@ -408,7 +410,8 @@ class DDSpanBuilderTest extends Specification {
span.tags == tags + [
(DDTags.THREAD_NAME) : Thread.currentThread().getName(),
(DDTags.THREAD_ID) : Thread.currentThread().getId(),
- (Config.RUNTIME_ID_TAG): config.getRuntimeId()
+ (Config.RUNTIME_ID_TAG) : config.getRuntimeId(),
+ (Config.LANGUAGE_TAG_KEY): Config.LANGUAGE_TAG_VALUE,
]
cleanup:

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/TraceInterceptorTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/TraceInterceptorTest.groovy
@@ -143,7 +143,8 @@ class TraceInterceptorTest extends Specification {
tags["thread.name"] != null
tags["thread.id"] != null
tags["runtime-id"] != null
- tags.size() == 7
+ tags["language"] != null
+ tags.size() == 8
}
def "register interceptor through bridge"() {

Update tests for `language` tag in root span