Add configuration param to 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
@@ -50,6 +50,7 @@ public class Config {
public static final String TRACE_ANNOTATIONS = "trace.annotations";
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 HEADER_TAGS = "trace.header.tags";
public static final String HTTP_SERVER_ERROR_STATUSES = "http.server.error.statuses";
public static final String HTTP_CLIENT_ERROR_STATUSES = "http.client.error.statuses";
@@ -103,6 +104,8 @@ public class Config {
private static final String SPLIT_BY_SPACE_OR_COMMA_REGEX = "[,\\s]+";
+ private static final boolean DEFAULT_TRACE_REPORT_HOSTNAME = false;
+
public enum PropagationStyle {
DATADOG,
B3
@@ -142,6 +145,8 @@ public class Config {
@Getter private final Integer jmxFetchStatsdPort;
@Getter private final boolean logsInjectionEnabled;
@Getter private final boolean appCustomLogManager;
+ // If `true` the hostname will be detected and added to the root span's metadata
+ @Getter private final boolean reportHostName;
// Read order: System Properties -> Env Variables, [-> default value]
// Visible for testing
@@ -217,6 +222,9 @@ public class Config {
appCustomLogManager =
getBooleanSettingFromEnvironment(APP_CUSTOM_LOG_MANAGER, DEFAULT_APP_CUSTOM_LOG_MANAGER);
+ reportHostName =
+ getBooleanSettingFromEnvironment(TRACE_REPORT_HOSTNAME, DEFAULT_TRACE_REPORT_HOSTNAME);
+
log.debug("New instance: {}", this);
}
@@ -298,6 +306,9 @@ public class Config {
appCustomLogManager =
getBooleanSettingFromEnvironment(APP_CUSTOM_LOG_MANAGER, DEFAULT_APP_CUSTOM_LOG_MANAGER);
+ reportHostName =
+ getPropertyBooleanValue(properties, TRACE_REPORT_HOSTNAME, parent.reportHostName);
+
log.debug("New instance: {}", this);
}

MODIFY
dd-trace-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy
dd-trace-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy
@@ -35,6 +35,7 @@ import static datadog.trace.api.Config.SERVICE_MAPPING
import static datadog.trace.api.Config.SERVICE_NAME
import static datadog.trace.api.Config.SPAN_TAGS
import static datadog.trace.api.Config.TRACE_AGENT_PORT
+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
@@ -54,6 +55,7 @@ class ConfigTest extends Specification {
private static final DD_JMXFETCH_METRICS_CONFIGS_ENV = "DD_JMXFETCH_METRICS_CONFIGS"
private static final DD_TRACE_AGENT_PORT_ENV = "DD_TRACE_AGENT_PORT"
private static final DD_AGENT_PORT_LEGACY_ENV = "DD_AGENT_PORT"
+ private static final DD_TRACE_REPORT_HOSTNAME = "DD_TRACE_REPORT_HOSTNAME"
def "verify defaults"() {
when:
@@ -75,6 +77,7 @@ class ConfigTest extends Specification {
config.httpClientErrorStatuses == (400..499).toSet()
config.httpClientSplitByDomain == false
config.partialFlushMinSpans == 1000
+ config.reportHostName == false
config.runtimeContextFieldInjection == true
config.propagationStylesToExtract.toList() == [Config.PropagationStyle.DATADOG]
config.propagationStylesToInject.toList() == [Config.PropagationStyle.DATADOG]
@@ -114,6 +117,7 @@ class ConfigTest extends Specification {
prop.setProperty(HTTP_CLIENT_ERROR_STATUSES, "111")
prop.setProperty(HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
prop.setProperty(PARTIAL_FLUSH_MIN_SPANS, "15")
+ prop.setProperty(TRACE_REPORT_HOSTNAME, "true")
prop.setProperty(RUNTIME_CONTEXT_FIELD_INJECTION, "false")
prop.setProperty(PROPAGATION_STYLE_EXTRACT, "Datadog, B3")
prop.setProperty(PROPAGATION_STYLE_INJECT, "B3, Datadog")
@@ -143,6 +147,7 @@ class ConfigTest extends Specification {
config.httpClientErrorStatuses == (111..111).toSet()
config.httpClientSplitByDomain == true
config.partialFlushMinSpans == 15
+ config.reportHostName == true
config.runtimeContextFieldInjection == false
config.propagationStylesToExtract.toList() == [Config.PropagationStyle.DATADOG, Config.PropagationStyle.B3]
config.propagationStylesToInject.toList() == [Config.PropagationStyle.B3, Config.PropagationStyle.DATADOG]
@@ -173,6 +178,7 @@ class ConfigTest extends Specification {
System.setProperty(PREFIX + HTTP_CLIENT_ERROR_STATUSES, "111")
System.setProperty(PREFIX + HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "true")
System.setProperty(PREFIX + PARTIAL_FLUSH_MIN_SPANS, "25")
+ System.setProperty(PREFIX + TRACE_REPORT_HOSTNAME, "true")
System.setProperty(PREFIX + RUNTIME_CONTEXT_FIELD_INJECTION, "false")
System.setProperty(PREFIX + PROPAGATION_STYLE_EXTRACT, "Datadog, B3")
System.setProperty(PREFIX + PROPAGATION_STYLE_INJECT, "B3, Datadog")
@@ -202,6 +208,7 @@ class ConfigTest extends Specification {
config.httpClientErrorStatuses == (111..111).toSet()
config.httpClientSplitByDomain == true
config.partialFlushMinSpans == 25
+ config.reportHostName == true
config.runtimeContextFieldInjection == false
config.propagationStylesToExtract.toList() == [Config.PropagationStyle.DATADOG, Config.PropagationStyle.B3]
config.propagationStylesToInject.toList() == [Config.PropagationStyle.B3, Config.PropagationStyle.DATADOG]
@@ -220,6 +227,7 @@ class ConfigTest extends Specification {
environmentVariables.set(DD_PROPAGATION_STYLE_EXTRACT, "B3 Datadog")
environmentVariables.set(DD_PROPAGATION_STYLE_INJECT, "Datadog B3")
environmentVariables.set(DD_JMXFETCH_METRICS_CONFIGS_ENV, "some/file")
+ environmentVariables.set(DD_TRACE_REPORT_HOSTNAME, "true")
when:
def config = new Config()
@@ -230,6 +238,7 @@ class ConfigTest extends Specification {
config.propagationStylesToExtract.toList() == [Config.PropagationStyle.B3, Config.PropagationStyle.DATADOG]
config.propagationStylesToInject.toList() == [Config.PropagationStyle.DATADOG, Config.PropagationStyle.B3]
config.jmxFetchMetricsConfigs == ["some/file"]
+ config.reportHostName == true
}
def "sys props override env vars"() {

Add configuration param to report hostname