Skip to content

Commit 8d90462

Browse files
authored
AsyncHttpClient: extract net attributes from InetSocketAddress (#3882)
1 parent 8200319 commit 8d90462

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesExtractor.java

+7-14
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,26 @@
55

66
package io.opentelemetry.javaagent.instrumentation.asynchttpclient.v2_0;
77

8-
import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor;
8+
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor;
99
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
10+
import java.net.InetSocketAddress;
1011
import org.asynchttpclient.Request;
1112
import org.asynchttpclient.Response;
1213
import org.checkerframework.checker.nullness.qual.Nullable;
1314

1415
final class AsyncHttpClientNetAttributesExtractor
15-
extends NetAttributesExtractor<Request, Response> {
16+
extends InetSocketAddressNetAttributesExtractor<Request, Response> {
1617

1718
@Override
1819
public String transport(Request request) {
1920
return SemanticAttributes.NetTransportValues.IP_TCP;
2021
}
2122

2223
@Override
23-
public String peerName(Request request, @Nullable Response response) {
24-
return request.getUri().getHost();
25-
}
26-
27-
@Override
28-
public Integer peerPort(Request request, @Nullable Response response) {
29-
return request.getUri().getPort();
30-
}
31-
32-
@Override
33-
@Nullable
34-
public String peerIp(Request request, @Nullable Response response) {
24+
public @Nullable InetSocketAddress getAddress(Request request, @Nullable Response response) {
25+
if (response != null && response.getRemoteAddress() instanceof InetSocketAddress) {
26+
return (InetSocketAddress) response.getRemoteAddress();
27+
}
3528
return null;
3629
}
3730
}

0 commit comments

Comments
 (0)