Don't trace httpurlconnection as a top-level trace
MODIFY
dd-java-agent/instrumentation/http-url-connection/src/main/java/datadog/trace/instrumentation/http_url_connection/HttpUrlConnectionInstrumentation.java
dd-java-agent/instrumentation/http-url-connection/src/main/java/datadog/trace/instrumentation/http_url_connection/HttpUrlConnectionInstrumentation.java
@@ -107,12 +107,17 @@ public class HttpUrlConnectionInstrumentation extends Instrumenter.Default {
return null;
}
+ final Tracer tracer = GlobalTracer.get();
+ if (tracer.activeSpan() == null) {
+ // httpurlconnection doesn't play nicely with top-level spans
+ return null;
+ }
+
final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(HttpURLConnection.class);
if (callDepth > 0) {
return null;
}
- final Tracer tracer = GlobalTracer.get();
final Scope scope =
tracer
.buildSpan("http.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
@@ -332,6 +332,20 @@ class HttpUrlConnectionTest extends AgentTestRunner {
}
}
+ def "top level httpurlconnection tracing disabled"() {
+ setup:
+ HttpURLConnection connection = server.address.toURL().openConnection()
+ connection.addRequestProperty("is-dd-server", "false")
+ def stream = connection.inputStream
+ def lines = stream.readLines()
+ stream.close()
+ assert connection.getResponseCode() == STATUS
+ assert lines == [RESPONSE]
+
+ expect:
+ assertTraces(TEST_WRITER, 0) {}
+ }
+
def "rest template"() {
setup:
runUnderTrace("someTrace") {

Don't trace httpurlconnection as a top-level trace