Remove report hostname
MODIFY
dd-trace-api/src/main/java/datadog/trace/api/Config.java
dd-trace-api/src/main/java/datadog/trace/api/Config.java
package datadog.trace.api;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -55,7 +51,6 @@ public class Config {
public static final String TRACE_EXECUTORS = "trace.executors";
public static final String TRACE_METHODS = "trace.methods";
public static final String TRACE_CLASSES_EXCLUDE = "trace.classes.exclude";
- public static final String TRACE_REPORT_HOSTNAME = "trace.report-hostname";
public static final String HTTP_SERVER_ERROR_STATUSES = "http.server.error.statuses";
public static final String HTTP_CLIENT_ERROR_STATUSES = "http.client.error.statuses";
public static final String HTTP_SERVER_TAG_QUERY_STRING = "http.server.tag.query-string";
@@ -98,15 +93,11 @@ public class Config {
private static final String SPLIT_BY_SPACE_OR_COMMA_REGEX = "[,\\s]+";
- private static final boolean DEFAULT_TRACE_REPORT_HOSTNAME = false;
private static final String DEFAULT_TRACE_ANNOTATIONS = null;
private static final boolean DEFAULT_TRACE_EXECUTORS_ALL = false;
private static final String DEFAULT_TRACE_EXECUTORS = "";
private static final String DEFAULT_TRACE_METHODS = null;
- /** 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";
-
/**
* 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.
@@ -133,8 +124,6 @@ public class Config {
@Getter private final boolean logsInjectionEnabled;
- @Getter private final boolean reportHostName;
-
@Getter private final String traceAnnotations;
@Getter private final String traceMethods;
@@ -201,9 +190,6 @@ public class Config {
logsInjectionEnabled =
getBooleanSettingFromEnvironment(LOGS_INJECTION_ENABLED, DEFAULT_LOGS_INJECTION_ENABLED);
- reportHostName =
- getBooleanSettingFromEnvironment(TRACE_REPORT_HOSTNAME, DEFAULT_TRACE_REPORT_HOSTNAME);
-
traceAnnotations = getSettingFromEnvironment(TRACE_ANNOTATIONS, DEFAULT_TRACE_ANNOTATIONS);
traceMethods = getSettingFromEnvironment(TRACE_METHODS, DEFAULT_TRACE_METHODS);
@@ -269,9 +255,6 @@ public class Config {
logsInjectionEnabled =
getBooleanSettingFromEnvironment(LOGS_INJECTION_ENABLED, DEFAULT_LOGS_INJECTION_ENABLED);
- reportHostName =
- getPropertyBooleanValue(properties, TRACE_REPORT_HOSTNAME, parent.reportHostName);
-
traceAnnotations = properties.getProperty(TRACE_ANNOTATIONS, parent.traceAnnotations);
traceMethods = properties.getProperty(TRACE_METHODS, parent.traceMethods);
@@ -289,13 +272,6 @@ public class Config {
final Map<String, String> result = new HashMap<>(runtimeTags);
result.put(LANGUAGE_TAG_KEY, LANGUAGE_TAG_VALUE);
- if (reportHostName) {
- final String hostName = getHostName();
- if (null != hostName && !hostName.isEmpty()) {
- result.put(INTERNAL_HOST_NAME, hostName);
- }
- }
-
return Collections.unmodifiableMap(result);
}
@@ -719,47 +695,6 @@ public class Config {
return properties;
}
- /** Returns the detected hostname. First tries locally, then using DNS */
- private String getHostName() {
- String possibleHostname = null;
-
- // Try environment variable. This works in almost all environments
- if (System.getProperty("os.name").startsWith("Windows")) {
- possibleHostname = System.getenv("COMPUTERNAME");
- } else {
- possibleHostname = System.getenv("HOSTNAME");
- }
-
- if (possibleHostname != null && !possibleHostname.isEmpty()) {
- log.debug("Determined hostname from environment variable");
- return possibleHostname.trim();
- }
-
- // Try hostname command
- try {
- final Process process = Runtime.getRuntime().exec("hostname");
- final BufferedReader reader =
- new BufferedReader(new InputStreamReader(process.getInputStream()));
- possibleHostname = reader.readLine();
- } catch (final Exception e) {
- // Ignore. Hostname command is not always available
- }
-
- if (possibleHostname != null && !possibleHostname.isEmpty()) {
- log.debug("Determined hostname from hostname command");
- return possibleHostname.trim();
- }
-
- // From DNS
- try {
- return InetAddress.getLocalHost().getHostName();
- } catch (final UnknownHostException e) {
- // If we are not able to detect the hostname we do not throw an exception.
- }
-
- return null;
- }
-
// This has to be placed after all other static fields to give them a chance to initialize
private static final Config INSTANCE = new Config();

MODIFY
dd-trace-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy
dd-trace-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy
@@ -20,7 +20,6 @@ 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_REPORT_HOSTNAME
import static datadog.trace.api.Config.TRACE_RESOLVER_ENABLED
import static datadog.trace.api.Config.WRITER_TYPE
@@ -34,7 +33,6 @@ class ConfigTest extends DDSpecification {
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"
- private static final DD_TRACE_REPORT_HOSTNAME = "DD_TRACE_REPORT_HOSTNAME"
def "verify defaults"() {
when:
@@ -52,7 +50,6 @@ class ConfigTest extends DDSpecification {
config.httpClientSplitByDomain == false
config.dbClientSplitByInstance == false
config.partialFlushMinSpans == 1000
- config.reportHostName == false
config.runtimeContextFieldInjection == true
config.toString().contains("unnamed-java-app")
@@ -79,7 +76,6 @@ class ConfigTest extends DDSpecification {
prop.setProperty(HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
prop.setProperty(DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "true")
prop.setProperty(PARTIAL_FLUSH_MIN_SPANS, "15")
- prop.setProperty(TRACE_REPORT_HOSTNAME, "true")
prop.setProperty(RUNTIME_CONTEXT_FIELD_INJECTION, "false")
when:
@@ -97,7 +93,6 @@ class ConfigTest extends DDSpecification {
config.httpClientSplitByDomain == true
config.dbClientSplitByInstance == true
config.partialFlushMinSpans == 15
- config.reportHostName == true
config.runtimeContextFieldInjection == false
}
@@ -115,7 +110,6 @@ class ConfigTest extends DDSpecification {
System.setProperty(PREFIX + HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
System.setProperty(PREFIX + DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "true")
System.setProperty(PREFIX + PARTIAL_FLUSH_MIN_SPANS, "25")
- System.setProperty(PREFIX + TRACE_REPORT_HOSTNAME, "true")
System.setProperty(PREFIX + RUNTIME_CONTEXT_FIELD_INJECTION, "false")
when:
@@ -133,7 +127,6 @@ class ConfigTest extends DDSpecification {
config.httpClientSplitByDomain == true
config.dbClientSplitByInstance == true
config.partialFlushMinSpans == 25
- config.reportHostName == true
config.runtimeContextFieldInjection == false
}
@@ -142,7 +135,6 @@ class ConfigTest extends DDSpecification {
environmentVariables.set(DD_SERVICE_NAME_ENV, "still something else")
environmentVariables.set(DD_TRACE_ENABLED_ENV, "false")
environmentVariables.set(DD_WRITER_TYPE_ENV, "LoggingWriter")
- environmentVariables.set(DD_TRACE_REPORT_HOSTNAME, "true")
when:
def config = new Config()
@@ -151,7 +143,6 @@ class ConfigTest extends DDSpecification {
config.serviceName == "still something else"
config.traceEnabled == false
config.writerType == "LoggingWriter"
- config.reportHostName == true
}
def "sys props override env vars"() {
@@ -429,18 +420,6 @@ class ConfigTest extends DDSpecification {
!config.localRootSpanTags.containsKey('_dd.hostname')
}
- def "verify configuration to add hostname to root span tags"() {
- setup:
- Properties properties = new Properties()
- properties.setProperty(TRACE_REPORT_HOSTNAME, 'true')
-
- 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")

Remove report hostname (#31)