Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated generateRemoteService to parse HTTP_URL as last resort #750

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
AsakerMohd marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,19 @@ private static String generateRemoteService(SpanData span) {
Long port = span.getAttributes().get(NET_SOCK_PEER_PORT);
remoteService += ":" + port;
}
} else if (isKeyPresent(span, HTTP_URL)) {
String httpUrl = span.getAttributes().get(HTTP_URL);
try {
URL url = new URL(httpUrl);
if (!url.getHost().isEmpty()) {
remoteService = url.getHost();
if (url.getPort() != -1) {
remoteService += ":" + url.getPort();
}
}
} catch (MalformedURLException e) {
logger.log(Level.FINEST, "invalid http.url attribute: ", httpUrl);
}
} else {
logUnknownAttribute(AWS_REMOTE_SERVICE, span);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,31 @@ public void testRemoteAttributesCombinations() {
mockAttribute(NET_SOCK_PEER_ADDR, null);
mockAttribute(NET_SOCK_PEER_PORT, null);

// Validate behavior of Remote Operation from HttpTarget - with 1st api part, then remove it
// Validate behavior of Remote Operation from HttpTarget - with 1st api part. Also validates
// that RemoteService is extracted from HttpUrl.
mockAttribute(HTTP_URL, "http://www.example.com/payment/123");
validateExpectedRemoteAttributes(UNKNOWN_REMOTE_SERVICE, "/payment");
validateExpectedRemoteAttributes("www.example.com", "/payment");
mockAttribute(HTTP_URL, null);

// Validate behavior of Remote Operation from HttpTarget - without 1st api part, then remove it
// Validate behavior of Remote Operation from HttpTarget - with 1st api part. Also validates
// that RemoteService is extracted from HttpUrl.
mockAttribute(HTTP_URL, "http://www.example.com");
validateExpectedRemoteAttributes(UNKNOWN_REMOTE_SERVICE, "/");
validateExpectedRemoteAttributes("www.example.com", "/");
mockAttribute(HTTP_URL, null);

// Validate behavior of Remote Service from HttpUrl
mockAttribute(HTTP_URL, "http://192.168.1.1:8000");
validateExpectedRemoteAttributes("192.168.1.1:8000", "/");
mockAttribute(HTTP_URL, null);
AsakerMohd marked this conversation as resolved.
Show resolved Hide resolved

// Validate behavior of Remote Service from HttpUrl
mockAttribute(HTTP_URL, "");
validateExpectedRemoteAttributes(UNKNOWN_REMOTE_SERVICE, UNKNOWN_REMOTE_OPERATION);
mockAttribute(HTTP_URL, null);

// Validate behavior of Remote Service from HttpUrl
mockAttribute(HTTP_URL, null);
validateExpectedRemoteAttributes(UNKNOWN_REMOTE_SERVICE, UNKNOWN_REMOTE_OPERATION);
mockAttribute(HTTP_URL, null);

// Validate behavior of Remote Operation from HttpTarget - invalid url, then remove it
Expand Down
Loading