Use config inheritance in `withConfigOverride`.
This moves us forward to abstract 'Config' and away from depending in
specific config data source (e.g. system properties).
MODIFY
dd-java-agent/instrumentation/akka-http-10.0/src/test/groovy/AkkaHttpClientInstrumentationTest.groovy
dd-java-agent/instrumentation/akka-http-10.0/src/test/groovy/AkkaHttpClientInstrumentationTest.groovy
@@ -60,7 +60,7 @@ class AkkaHttpClientInstrumentationTest extends AgentTestRunner {
HttpRequest request = HttpRequest.create(url.toString())
when:
- HttpResponse response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ HttpResponse response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
Http.get(system)
.singleRequest(request, materializer)
.toCompletableFuture().get()
@@ -113,7 +113,7 @@ class AkkaHttpClientInstrumentationTest extends AgentTestRunner {
HttpRequest request = HttpRequest.create(url.toString())
CompletionStage<HttpResponse> responseFuture =
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
Http.get(system)
.singleRequest(request, materializer)
}
@@ -189,7 +189,7 @@ class AkkaHttpClientInstrumentationTest extends AgentTestRunner {
def url = server.address.resolve("/" + route).toURL()
when:
- HttpResponse response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ HttpResponse response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
Source
.<Pair<HttpRequest, Integer>> single(new Pair(HttpRequest.create(url.toString()), 1))
.via(pool)
@@ -243,7 +243,7 @@ class AkkaHttpClientInstrumentationTest extends AgentTestRunner {
// Use port number that really should be closed
def url = new URL("http://localhost:$UNUSED_PORT/test")
- def response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ def response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
Source
.<Pair<HttpRequest, Integer>> single(new Pair(HttpRequest.create(url.toString()), 1))
.via(pool)

MODIFY
dd-java-agent/instrumentation/apache-httpclient-4/src/latestDepTest/groovy/ApacheHttpClientTest.groovy
dd-java-agent/instrumentation/apache-httpclient-4/src/latestDepTest/groovy/ApacheHttpClientTest.groovy
@@ -58,7 +58,7 @@ class ApacheHttpClientTest extends AgentTestRunner {
def "trace request with propagation"() {
when:
- String response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ String response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("parent") {
if (responseHandler) {
client.execute(new HttpGet(successUrl), responseHandler)
@@ -93,7 +93,7 @@ class ApacheHttpClientTest extends AgentTestRunner {
request.setConfig(requestConfigBuilder.build())
when:
- HttpResponse response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ HttpResponse response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("parent") {
client.execute(request)
}
@@ -123,7 +123,7 @@ class ApacheHttpClientTest extends AgentTestRunner {
request.setConfig(requestConfigBuilder.build())
when:
- HttpResponse response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ HttpResponse response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("parent") {
client.execute(request)
}
@@ -154,7 +154,7 @@ class ApacheHttpClientTest extends AgentTestRunner {
request.setConfig(requestConfigBuilder.build())
when:
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("parent") {
client.execute(request)
}
@@ -182,7 +182,7 @@ class ApacheHttpClientTest extends AgentTestRunner {
request.addHeader(new BasicHeader("is-dd-server", "false"))
when:
- HttpResponse response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ HttpResponse response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("parent") {
client.execute(request)
}

MODIFY
dd-java-agent/instrumentation/apache-httpclient-4/src/test/groovy/ApacheHttpClientTest.groovy
dd-java-agent/instrumentation/apache-httpclient-4/src/test/groovy/ApacheHttpClientTest.groovy
@@ -55,7 +55,7 @@ class ApacheHttpClientTest extends AgentTestRunner {
def "trace request with propagation"() {
when:
- String response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ String response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("parent") {
if (responseHandler) {
client.execute(new HttpGet(successUrl), responseHandler)
@@ -87,7 +87,7 @@ class ApacheHttpClientTest extends AgentTestRunner {
request.addHeader(new BasicHeader("is-dd-server", "false"))
when:
- HttpResponse response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ HttpResponse response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("parent") {
client.execute(request)
}

MODIFY
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy
@@ -33,7 +33,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
def "trace request with propagation (useCaches: #useCaches)"() {
setup:
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("someTrace") {
HttpURLConnection connection = server.address.toURL().openConnection()
connection.useCaches = useCaches
@@ -114,7 +114,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
def "trace request without propagation (useCaches: #useCaches)"() {
setup:
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("someTrace") {
HttpURLConnection connection = server.address.toURL().openConnection()
connection.useCaches = useCaches
@@ -195,7 +195,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
def "test response code"() {
setup:
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("someTrace") {
HttpURLConnection connection = server.address.toURL().openConnection()
connection.setRequestMethod("HEAD")
@@ -242,7 +242,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
def "test broken API usage"() {
setup:
- HttpURLConnection conn = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ HttpURLConnection conn = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("someTrace") {
HttpURLConnection connection = server.address.toURL().openConnection()
connection.setRequestProperty("Connection", "close")
@@ -294,7 +294,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
def "test post request"() {
setup:
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("someTrace") {
HttpURLConnection connection = server.address.toURL().openConnection()
connection.setRequestMethod("POST")
@@ -383,7 +383,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
def "top level httpurlconnection tracing disabled"() {
setup:
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
HttpURLConnection connection = server.address.toURL().openConnection()
connection.addRequestProperty("is-dd-server", "false")
def stream = connection.inputStream
@@ -422,7 +422,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
def "rest template"() {
setup:
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("someTrace") {
RestTemplate restTemplate = new RestTemplate()
String res = restTemplate.postForObject(server.address.toString(), "Hello", String)

MODIFY
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/UrlConnectionTest.groovy
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/UrlConnectionTest.groovy
@@ -17,7 +17,7 @@ class UrlConnectionTest extends AgentTestRunner {
def "trace request with connection failure #scheme"() {
when:
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("someTrace") {
URLConnection connection = url.openConnection()
connection.setConnectTimeout(10000)
@@ -75,7 +75,7 @@ class UrlConnectionTest extends AgentTestRunner {
def url = new URI("file:/some-random-file%abc").toURL()
when:
- withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
runUnderTrace("someTrace") {
url.openConnection()
}

MODIFY
dd-java-agent/instrumentation/okhttp-3/src/test/groovy/OkHttp3Test.groovy
dd-java-agent/instrumentation/okhttp-3/src/test/groovy/OkHttp3Test.groovy
@@ -24,7 +24,7 @@ class OkHttp3Test extends AgentTestRunner {
.url("http://localhost:$server.address.port/ping")
.build()
- def response = withConfigOverride("dd.$Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN", "$renameService") {
+ def response = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {
client.newCall(request).execute()
}

MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/utils/TraceUtils.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/utils/TraceUtils.groovy
@@ -35,6 +35,7 @@ class TraceUtils {
}
}
+ // TODO: ideally all users of this should switch to using Config object (and withConfigOverride) instead.
@SneakyThrows
static <T extends Object> Object withSystemProperty(final String name, final String value, final Callable<T> r) {
if (value == null) {
@@ -51,17 +52,16 @@ class TraceUtils {
@SneakyThrows
static <T extends Object> Object withConfigOverride(final String name, final String value, final Callable<T> r) {
- return withSystemProperty(name, value) {
def existingConfig = Config.get() // We can't reference INSTANCE directly or the reflection below will fail.
- setFinalStatic(Config.getDeclaredField("INSTANCE"), new Config())
- setFinal(Config.getDeclaredField("runtimeId"), Config.get(), existingConfig.runtimeId)
+ Properties properties = new Properties()
+ properties.put(name, value)
+ setFinalStatic(Config.getDeclaredField("INSTANCE"), new Config(properties, existingConfig))
try {
return r.call()
} finally {
setFinalStatic(Config.getDeclaredField("INSTANCE"), existingConfig)
}
}
- }
private static void setFinalStatic(final Field field, final Object newValue) throws Exception {
setFinal(field, null, newValue)

Use config inheritance in `withConfigOverride`.

This moves us forward to abstract 'Config' and away from depending in
specific config data source (e.g. system properties).