Skip to content

Commit

Permalink
Require server.address and server.port in the HTTP client getter (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored and breedx-splk committed Aug 15, 2023
1 parent 1c1193e commit 6c21a09
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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

0 comments on commit 6c21a09

Please sign in to comment.