Add test for UrlConnection error on file protocol
MODIFY
dd-java-agent/instrumentation/http-url-connection/src/main/java/datadog/trace/instrumentation/http_url_connection/UrlInstrumentation.java
dd-java-agent/instrumentation/http-url-connection/src/main/java/datadog/trace/instrumentation/http_url_connection/UrlInstrumentation.java
@@ -25,6 +25,8 @@ import net.bytebuddy.matcher.ElementMatcher;
@AutoService(Instrumenter.class)
public class UrlInstrumentation extends Instrumenter.Default {
+ public static final String COMPONENT = "UrlConnection";
+
public UrlInstrumentation() {
super("urlconnection", "httpurlconnection");
}
@@ -67,7 +69,7 @@ public class UrlInstrumentation extends Instrumenter.Default {
.buildSpan(protocol + ".request")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.HTTP_CLIENT)
- .withTag(Tags.COMPONENT.getKey(), "UrlConnection")
+ .withTag(Tags.COMPONENT.getKey(), COMPONENT)
.startActive(true);
final Span span = scope.span();

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
@@ -2,6 +2,7 @@ import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.TestUtils
import datadog.trace.api.DDSpanTypes
import datadog.trace.api.DDTags
+import datadog.trace.instrumentation.http_url_connection.UrlInstrumentation
import io.opentracing.tag.Tags
import io.opentracing.util.GlobalTracer
@@ -65,4 +66,47 @@ class UrlConnectionTest extends AgentTestRunner {
url = new URI("$scheme://localhost:$INVALID_PORT").toURL()
}
+
+ def "trace request with connection failure to a local file with broken url path"() {
+ setup:
+ def url = new URI("file:/some-random-file%abc").toURL()
+
+ when:
+ runUnderTrace("someTrace") {
+ url.openConnection()
+ }
+
+ then:
+ thrown IllegalArgumentException
+
+ expect:
+ assertTraces(1) {
+ trace(0, 2) {
+ span(0) {
+ operationName "someTrace"
+ parent()
+ errored true
+ tags {
+ errorTags IllegalArgumentException, String
+ defaultTags()
+ }
+ }
+ span(1) {
+ operationName "file.request"
+ childOf span(0)
+ errored true
+ tags {
+ "$Tags.COMPONENT.key" UrlInstrumentation.COMPONENT
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
+ // FIXME: These tags really make no sense for non-http connections, why do we set them?
+ "$DDTags.SPAN_TYPE" DDSpanTypes.HTTP_CLIENT
+ "$Tags.HTTP_URL.key" "$url"
+ "$Tags.PEER_PORT.key" 80
+ errorTags IllegalArgumentException, String
+ defaultTags()
+ }
+ }
+ }
+ }
+ }
}

Add test for UrlConnection error on file protocol