Skip to content

Commit 98d52d6

Browse files
authored
Merge pull request #1069 from microsoft/trask/fix-apache-http-client-instrumentation
Fix apache http client instrumentation
2 parents 569e197 + 568d734 commit 98d52d6

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

agent/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ plugins {
2626
apply from: "$buildScriptsDir/common-java.gradle"
2727
apply from: "$buildScriptsDir/publishing.gradle"
2828

29-
def instrumentationVersion = '0.14.5'
29+
def instrumentationVersion = '0.14.6'
3030

3131
def shadowPrefix = 'com.microsoft.applicationinsights.agent.shadow'
3232

agent/src/main/java/com/microsoft/applicationinsights/agent/internal/model/OutgoingSpanImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ private void endInternal() {
150150
telemetry.getProperties().put("Method", method);
151151
}
152152
if (uri != null) {
153+
String host = (String) detail.get("Host");
154+
if (host != null) {
155+
uri = host + uri;
156+
}
153157
try {
154158
URI uriObject = new URI(uri);
155159
String target;

test/smoke/testApps/HttpClients/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpClientTestServlet.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.apache.commons.httpclient.cookie.CookiePolicy;
1717
import org.apache.commons.httpclient.cookie.CookieSpecBase;
1818
import org.apache.commons.httpclient.methods.GetMethod;
19+
import org.apache.http.HttpResponse;
20+
import org.apache.http.client.ResponseHandler;
1921
import org.apache.http.client.methods.CloseableHttpResponse;
2022
import org.apache.http.client.methods.HttpGet;
2123
import org.apache.http.impl.client.CloseableHttpClient;
@@ -44,6 +46,8 @@ private int doGetInternal(HttpServletRequest req) throws Exception {
4446
return 200;
4547
} else if (pathInfo.equals("/apacheHttpClient4")) {
4648
return apacheHttpClient4();
49+
} else if (pathInfo.equals("/apacheHttpClient4WithResponseHandler")) {
50+
return apacheHttpClient4WithResponseHandler();
4751
} else if (pathInfo.equals("/apacheHttpClient3")) {
4852
return apacheHttpClient3();
4953
} else if (pathInfo.equals("/okHttp3")) {
@@ -65,6 +69,17 @@ private int apacheHttpClient4() throws IOException {
6569
}
6670
}
6771

72+
private int apacheHttpClient4WithResponseHandler() throws IOException {
73+
String url = "https://www.bing.com";
74+
HttpGet get = new HttpGet(url);
75+
return httpClient.execute(get, new ResponseHandler<Integer>() {
76+
@Override
77+
public Integer handleResponse(HttpResponse response) {
78+
return response.getStatusLine().getStatusCode();
79+
}
80+
});
81+
}
82+
6883
private int apacheHttpClient3() throws IOException {
6984
HttpClient httpClient3 = new org.apache.commons.httpclient.HttpClient();
7085
CookiePolicy.registerCookieSpec("PermitAllCookiesSpec", PermitAllCookiesSpec.class);

test/smoke/testApps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketestapp/HttpClientSmokeTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ public void testAsyncDependencyCallWithApacheHttpClient4() throws Exception {
3232
assertTrue(rdd.getId().contains(rd.getId()));
3333
}
3434

35+
@Test
36+
@TargetUri("/apacheHttpClient4WithResponseHandler")
37+
public void testAsyncDependencyCallWithApacheHttpClient4WithResponseHandler() throws Exception {
38+
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
39+
List<Envelope> rddList = mockedIngestion.waitForItems("RemoteDependencyData", 1);
40+
41+
RequestData rd = (RequestData) ((Data) rdList.get(0).getData()).getBaseData();
42+
RemoteDependencyData rdd = (RemoteDependencyData) ((Data) rddList.get(0).getData()).getBaseData();
43+
44+
assertTrue(rd.getSuccess());
45+
assertEquals("GET /", rdd.getName());
46+
assertEquals("www.bing.com:-1 | www.bing.com", rdd.getTarget());
47+
assertTrue(rdd.getId().contains(rd.getId()));
48+
}
49+
3550
@Test
3651
@TargetUri("/apacheHttpClient3")
3752
public void testAsyncDependencyCallWithApacheHttpClient3() throws Exception {

0 commit comments

Comments
 (0)