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

Support url.query #39133

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -642,19 +642,43 @@ private static String getHttpUrlFromServerSpanStableSemconv(Attributes attribute
if (scheme == null) {
return null;
}
String path = attributes.get(SemanticAttributes.URL_PATH);
if (path == null) {
return null;
}
String host = attributes.get(SemanticAttributes.SERVER_ADDRESS);
if (host == null) {
return null;
}
Long port = attributes.get(SemanticAttributes.SERVER_PORT);
if (port != null && port > 0) {
return scheme + "://" + host + ":" + port + path;
String path = attributes.get(SemanticAttributes.URL_PATH);
if (path == null) {
return null;
}
return scheme + "://" + host + path;
String query = attributes.get(SemanticAttributes.URL_QUERY);

int len = scheme.length() + host.length() + path.length();
if (port != null) {
len += 6; // max 5 digits for port plus the port separator ":"
}
if (query != null) {
len += query.length() + 1; // including the query separator "?"
}
Copy link
Contributor

@jeanbisutti jeanbisutti Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract method from line 656 to line 662 with a computeFullPathLength(...) method name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort of like to be able to see the corresponding ifs here and below when appending


StringBuilder sb = new StringBuilder(len);
sb.append(scheme);
sb.append("://");
sb.append(host);
if (port != null && port > 0 && !isDefaultPortForScheme(port, scheme)) {
sb.append(':');
sb.append(port);
}
sb.append(path);
if (query != null) {
sb.append('?');
sb.append(query);
}
return sb.toString();
}

private static boolean isDefaultPortForScheme(Long port, String scheme) {
return (port == 80 && scheme.equals("http")) || (port == 443 && scheme.equals("https"));
}

@Nullable
Expand Down