Skip to content

Commit

Permalink
Support url.query
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Mar 8, 2024
1 parent ccf02bf commit 53c9a6c
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -642,19 +642,39 @@ 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);
String path = attributes.get(SemanticAttributes.URL_PATH);
if (path == null) {
return null;
}
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 "?"
}

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

@Nullable
Expand Down

0 comments on commit 53c9a6c

Please sign in to comment.