diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/model/OutgoingSpanImpl.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/model/OutgoingSpanImpl.java index 08b493dfa7e..dacaf508646 100644 --- a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/model/OutgoingSpanImpl.java +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/model/OutgoingSpanImpl.java @@ -156,22 +156,21 @@ private void endInternal() { } try { URI uriObject = new URI(uri); - String target; - if (requestContext == null) { - target = uriObject.getHost(); - } else { - target = sdkBridge.generateChildDependencyTarget(requestContext, Global.isOutboundW3CEnabled()); + String target = createTarget(uriObject); + if (requestContext != null) { + String incomingTarget = + sdkBridge.generateChildDependencyTarget(requestContext, Global.isOutboundW3CEnabled()); + if (incomingTarget != null && !incomingTarget.isEmpty()) { + target += " | " + incomingTarget; + } } + telemetry.setTarget(target); String path = uriObject.getPath(); if (Strings.isNullOrEmpty(path)) { telemetry.setName(method + " /"); } else { telemetry.setName(method + " " + path); } - if (target != null && !target.isEmpty()) { - // AI correlation expects target to be of this format. - telemetry.setTarget(createTarget(uriObject, target)); - } } catch (URISyntaxException e) { logger.error(e.getMessage()); logger.debug(e.getMessage(), e); @@ -188,12 +187,11 @@ private void endInternal() { } // from CoreAgentNotificationsHandler: - private static String createTarget(URI uriObject, String incomingTarget) { + private static String createTarget(URI uriObject) { String target = uriObject.getHost(); - if (uriObject.getPort() != 80 && uriObject.getPort() != 443) { + if (uriObject.getPort() != 80 && uriObject.getPort() != 443 && uriObject.getPort() != -1) { target += ":" + uriObject.getPort(); } - target += " | " + incomingTarget; return target; } } diff --git a/test/smoke/testApps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketestapp/HttpClientSmokeTest.java b/test/smoke/testApps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketestapp/HttpClientSmokeTest.java index 2ddaea0d72f..93d064c944a 100644 --- a/test/smoke/testApps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketestapp/HttpClientSmokeTest.java +++ b/test/smoke/testApps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketestapp/HttpClientSmokeTest.java @@ -28,7 +28,7 @@ public void testAsyncDependencyCallWithApacheHttpClient4() throws Exception { assertTrue(rd.getSuccess()); assertEquals("GET /", rdd.getName()); - assertEquals("www.bing.com:-1 | www.bing.com", rdd.getTarget()); + assertEquals("www.bing.com", rdd.getTarget()); assertTrue(rdd.getId().contains(rd.getId())); } @@ -43,7 +43,7 @@ public void testAsyncDependencyCallWithApacheHttpClient4WithResponseHandler() th assertTrue(rd.getSuccess()); assertEquals("GET /", rdd.getName()); - assertEquals("www.bing.com:-1 | www.bing.com", rdd.getTarget()); + assertEquals("www.bing.com", rdd.getTarget()); assertTrue(rdd.getId().contains(rd.getId())); } @@ -58,7 +58,7 @@ public void testAsyncDependencyCallWithApacheHttpClient3() throws Exception { assertTrue(rd.getSuccess()); assertEquals("GET /", rdd.getName()); - assertEquals("www.bing.com:-1 | www.bing.com", rdd.getTarget()); + assertEquals("www.bing.com", rdd.getTarget()); assertTrue(rdd.getId().contains(rd.getId())); } @@ -73,7 +73,7 @@ public void testAsyncDependencyCallWithOkHttp3() throws Exception { assertTrue(rd.getSuccess()); assertEquals("GET /", rdd.getName()); - assertEquals("www.bing.com:-1 | www.bing.com", rdd.getTarget()); + assertEquals("www.bing.com", rdd.getTarget()); assertTrue(rdd.getId().contains(rd.getId())); } @@ -88,7 +88,7 @@ public void testAsyncDependencyCallWithOkHttp2() throws Exception { assertTrue(rd.getSuccess()); assertEquals("GET /", rdd.getName()); - assertEquals("www.bing.com:-1 | www.bing.com", rdd.getTarget()); + assertEquals("www.bing.com", rdd.getTarget()); assertTrue(rdd.getId().contains(rd.getId())); } @@ -103,7 +103,7 @@ public void testAsyncDependencyCallWithHttpURLConnection() throws Exception { assertTrue(rd.getSuccess()); assertEquals("GET /", rdd.getName()); - assertEquals("www.bing.com:-1 | www.bing.com", rdd.getTarget()); + assertEquals("www.bing.com", rdd.getTarget()); assertTrue(rdd.getId().contains(rd.getId())); } } diff --git a/test/smoke/testApps/SpringBootTest/src/smokeTest/java/com/springbootstartertest/smoketest/SpringbootSmokeTest.java b/test/smoke/testApps/SpringBootTest/src/smokeTest/java/com/springbootstartertest/smoketest/SpringbootSmokeTest.java index 9de00864161..7c45eece034 100644 --- a/test/smoke/testApps/SpringBootTest/src/smokeTest/java/com/springbootstartertest/smoketest/SpringbootSmokeTest.java +++ b/test/smoke/testApps/SpringBootTest/src/smokeTest/java/com/springbootstartertest/smoketest/SpringbootSmokeTest.java @@ -113,7 +113,7 @@ private static void commonValidation() throws Exception { RemoteDependencyData rdd = (RemoteDependencyData) ((Data) rddEnvelope.getData()).getBaseData(); assertEquals("GET /", rdd.getName()); - assertEquals("www.bing.com:-1 | www.bing.com", rdd.getTarget()); + assertEquals("www.bing.com", rdd.getTarget()); assertTrue(rdd.getId().contains(d.getId())); assertSameOperationId(rdEnvelope, rddEnvelope);