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

Require server.address and server.port in the HTTP client getter #9171

Merged
Show file tree
Hide file tree
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 @@ -31,4 +31,14 @@ public interface HttpClientAttributesGetter<REQUEST, RESPONSE>
*/
@Nullable
String getUrlFull(REQUEST request);

/** {@inheritDoc} */
@Nullable
@Override
String getServerAddress(REQUEST request);

/** {@inheritDoc} */
@Nullable
@Override
Integer getServerPort(REQUEST request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.instrumentation.vertx.client.AbstractVertxHttpAttributesGetter;
import io.vertx.core.http.HttpClientRequest;
import javax.annotation.Nullable;

final class Vertx3HttpAttributesGetter extends AbstractVertxHttpAttributesGetter {

Expand All @@ -21,11 +22,33 @@ public String getUrlFull(HttpClientRequest request) {
// where relative is expected.
if (!isAbsolute(uri)) {
VertxRequestInfo requestInfo = requestInfoField.get(request);
uri = absoluteUri(requestInfo, uri);
if (requestInfo != null) {
uri = absoluteUri(requestInfo, uri);
}
}
return uri;
}

@Nullable
@Override
public String getServerAddress(HttpClientRequest request) {
VertxRequestInfo requestInfo = requestInfoField.get(request);
if (requestInfo == null) {
return null;
}
return requestInfo.getHost();
}

@Nullable
@Override
public Integer getServerPort(HttpClientRequest request) {
VertxRequestInfo requestInfo = requestInfoField.get(request);
if (requestInfo == null) {
return null;
}
return requestInfo.getPort();
}

private static boolean isAbsolute(String uri) {
return uri.startsWith("http://") || uri.startsWith("https://");
}
Expand Down