Don't trace httpurlconnection as a top-level trace

This commit is contained in:
Andrew Kent 2018-07-19 16:08:58 -07:00
parent d598515d09
commit 54485c3296
2 changed files with 20 additions and 1 deletions

View File

@ -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")

View File

@ -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") {