Avoid instrumenting HttpsURLConnectionImpl#1447
Conversation
| @Override | ||
| public ElementMatcher<? super TypeDescription> getTypeMatcher() { | ||
| return hasSuperType(is(HttpURLConnection.class)); | ||
| return hasSuperType(is(HttpURLConnection.class)).and(not(named("sun.net.www.protocol.https.HttpsURLConnectionImpl"))); |
There was a problem hiding this comment.
| return hasSuperType(is(HttpURLConnection.class)).and(not(named("sun.net.www.protocol.https.HttpsURLConnectionImpl"))); | |
| return hasSuperType(is(HttpURLConnection.class)) | |
| .and(not(named("sun.net.www.protocol.https.HttpsURLConnectionImpl"))) | |
| .and(declaresField(named("connected"))); |
There was a problem hiding this comment.
Why declaresField(named("connected"))? It can be an inherited and not a declared field.
There was a problem hiding this comment.
@felixbarny This cannot work, as the connected field belongs to java.net.URLConnection (abstract). Let me know if you think we can merge it.
There was a problem hiding this comment.
Yes, forget what I said. @Advice.FieldValue("connected") boolean connected is guaranteed to work as the connected field is always accessible as we're searching for sub-types of HttpUrlConnection that are also sub-types of URLConnection
Codecov Report
@@ Coverage Diff @@
## master #1447 +/- ##
=============================================
+ Coverage 28.88% 59.82% +30.93%
- Complexity 14 91 +77
=============================================
Files 6 388 +382
Lines 90 17503 +17413
Branches 10 2403 +2393
=============================================
+ Hits 26 10471 +10445
- Misses 61 6315 +6254
- Partials 3 717 +714
Continue to review full report at Codecov.
|
| @Override | ||
| public ElementMatcher<? super TypeDescription> getTypeMatcher() { | ||
| return hasSuperType(is(HttpURLConnection.class)); | ||
| return hasSuperType(is(HttpURLConnection.class)).and(not(named("sun.net.www.protocol.https.HttpsURLConnectionImpl"))); |
There was a problem hiding this comment.
Yes, forget what I said. @Advice.FieldValue("connected") boolean connected is guaranteed to work as the connected field is always accessible as we're searching for sub-types of HttpUrlConnection that are also sub-types of URLConnection
What does this PR do?
Fixes a problem with the instrumentation of
HttpUrlConnection:sun.net.www.protocol.https.HttpsURLConnectionImpluses a delegate UrlConnection. It's ownresponseCodefield is not updated, instead itsgetResponseCode()delegates. Since our instrumentation relies on the field's value in order to end the HTTP span, it fails to end it.Checklist
I have added tests that would fail without this fixUrlConnectionwithout callingjava.net.HttpURLConnection#disconnectwould fail without this fix