Refactor hostname detection in tracer
MODIFY
dd-trace-api/src/main/java/datadog/trace/api/DDTags.java
dd-trace-api/src/main/java/datadog/trace/api/DDTags.java
@@ -7,7 +7,6 @@ public class DDTags {
public static final String THREAD_NAME = "thread.name";
public static final String THREAD_ID = "thread.id";
public static final String DB_STATEMENT = "sql.query";
- public static final String INTERNAL_HOST_NAME = "_dd.hostname";
public static final String USER_NAME = "user.principal";

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
@@ -8,7 +8,6 @@ import datadog.opentracing.propagation.TagContext;
import datadog.opentracing.scopemanager.ContextualScopeManager;
import datadog.opentracing.scopemanager.ScopeContext;
import datadog.trace.api.Config;
-import datadog.trace.api.DDTags;
import datadog.trace.api.interceptor.MutableSpan;
import datadog.trace.api.interceptor.TraceInterceptor;
import datadog.trace.api.sampling.PrioritySampling;
@@ -81,6 +80,9 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
private final HttpCodec.Injector injector;
private final HttpCodec.Extractor extractor;
+ /** A tag intended for internal use only, hence not added to the public api DDTags class. */
+ private static final String INTERNAL_HOST_NAME = "_dd.hostname";
+
/**
* hostname is expensive to calculate so we detect it only when creating the tracer and we cache
* it for future reuse.
@@ -792,7 +794,7 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace
}
alreadyTrackedRootSpans.add(rootSpan);
- rootSpan.setTag(DDTags.INTERNAL_HOST_NAME, hostname);
+ rootSpan.setTag(INTERNAL_HOST_NAME, hostname);
}
}
}

MODIFY
dd-trace-ot/src/test/groovy/datadog/trace/DDTracerTest.groovy
dd-trace-ot/src/test/groovy/datadog/trace/DDTracerTest.groovy
@@ -29,6 +29,8 @@ class DDTracerTest extends Specification {
@Rule
public final EnvironmentVariables environmentVariables = new EnvironmentVariables()
+ private final String INTERNAL_HOST_NAME = "_dd.hostname"
+
def setupSpec() {
// assert that a trace agent isn't running locally as that messes up the test.
try {
@@ -158,8 +160,8 @@ class DDTracerTest extends Specification {
root.finish()
then:
- !root.context().tags.containsKey(DDTags.INTERNAL_HOST_NAME)
- !child.context().tags.containsKey(DDTags.INTERNAL_HOST_NAME)
+ !root.context().tags.containsKey(INTERNAL_HOST_NAME)
+ !child.context().tags.containsKey(INTERNAL_HOST_NAME)
}
def "tracer sets the host name if activated only on root span"() {
@@ -174,7 +176,7 @@ class DDTracerTest extends Specification {
root.finish()
then:
- root.context().tags.get(DDTags.INTERNAL_HOST_NAME) == InetAddress.localHost.hostName
- !child.context().tags.containsKey(DDTags.INTERNAL_HOST_NAME)
+ root.context().tags.get(INTERNAL_HOST_NAME) == InetAddress.localHost.hostName
+ !child.context().tags.containsKey(INTERNAL_HOST_NAME)
}
}

Refactor hostname detection in tracer