From e925d1ba3fe62199d8d55481c4cfe2d177107901 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Wed, 24 Aug 2022 18:44:58 +0200 Subject: [PATCH] Net attributes getters changes: getter implementations --- .../instrumenter/InstrumenterBenchmark.java | 30 +++++++++-- .../client/AkkaHttpNetAttributesGetter.java | 24 +++++++++ .../apachedubbo/v2_7/DubboRequest.java | 9 +++- .../DubboNetClientAttributesGetter.java | 26 +++++---- .../DubboNetServerAttributesGetter.java | 24 +++++++-- ...cheHttpAsyncClientNetAttributesGetter.java | 12 ++++- .../ApacheHttpClientRequest.java | 15 +++++- .../ApacheHttpClientNetAttributesGetter.java | 24 +++++++++ .../ApacheHttpClientNetAttributesGetter.java | 24 +++++++++ .../ApacheHttpClientNetAttributesGetter.java | 12 ++++- .../v4_3/ApacheHttpClientRequest.java | 13 +++++ .../ApacheHttpClientNetAttributesGetter.java | 24 +++++++++ .../ArmeriaNetServerAttributesGetter.java | 24 ++++++++- .../ArmeriaNetClientAttributesGetter.java | 23 +++++++- .../AsyncHttpClientNetAttributesGetter.java | 24 +++++++++ .../AsyncHttpClientNetAttributesGetter.java | 13 ++++- .../v1_11/AwsSdkNetAttributesGetter.java | 24 +++++++++ .../v2_2/AwsSdkNetAttributesGetter.java | 24 +++++++++ .../v3_0/CassandraNetAttributesGetter.java | 14 ++++- .../v4_0/CassandraNetAttributesGetter.java | 14 ++++- .../couchbase/v2_0/CouchbaseRequestInfo.java | 31 ++++------- .../v2_0/CouchbaseNetAttributesGetter.java | 23 ++++++-- .../v2_6/CouchbaseNetworkInstrumentation.java | 17 ++---- ...searchRestNetResponseAttributesGetter.java | 12 +++++ ...icsearch6TransportNetAttributesGetter.java | 14 ++++- ...cTransportNetResponseAttributesGetter.java | 30 ++++++++--- .../GoogleHttpClientNetAttributesGetter.java | 28 ++++++++-- .../grizzly/GrizzlyNetAttributesGetter.java | 43 +++++++++++++-- .../grpc/v1_6/GrpcRequest.java | 41 +++++++++++--- .../grpc/v1_6/TracingClientInterceptor.java | 17 ++---- .../grpc/v1_6/TracingServerInterceptor.java | 3 +- .../GrpcNetClientAttributesGetter.java | 26 ++++++--- .../GrpcNetServerAttributesGetter.java | 27 ++++++++-- .../HttpUrlNetAttributesGetter.java | 24 +++++++++ .../JdkHttpNetAttributesGetter.java | 24 +++++++++ .../v1_1/JaxRsClientNetAttributesGetter.java | 28 ++++++++-- .../internal/JdbcNetAttributesGetter.java | 24 +++++++++ .../jedis/v1_4/JedisNetAttributesGetter.java | 24 +++++++++ .../jedis/v3_0/JedisNetAttributesGetter.java | 23 +++++--- .../jedis/v4_0/JedisNetAttributesGetter.java | 26 ++++++--- .../JettyHttpClientNetAttributesGetter.java | 24 +++++++++ .../v1_0/KtorNetServerAttributesGetter.kt | 28 +++++++++- .../v2_0/KtorNetServerAttributesGetter.kt | 26 ++++++++- .../KubernetesNetAttributesGetter.java | 24 +++++++++ .../LettuceConnectNetAttributesGetter.java | 24 +++++++++ .../LettuceConnectNetAttributesGetter.java | 24 +++++++++ .../v5_1/LettuceNetAttributesGetter.java | 14 ++++- .../internal/channel/HttpDispatcherLink.java | 8 ++- .../http/channel/HttpRequestMessage.java | 4 ++ .../LibertyDispatcherNetAttributesGetter.java | 44 +++++++++++++-- .../liberty/dispatcher/LibertyRequest.java | 16 +++--- .../mongo/v3_1/MongoNetAttributesGetter.java | 50 +++++++++++++---- .../NettyConnectNetAttributesGetter.java | 41 +++++++++----- .../NettyNetClientAttributesGetter.java | 31 ++++++++--- .../NettyNetServerAttributesGetter.java | 25 ++++++++- .../NettyConnectNetAttributesGetter.java | 41 +++++++++----- .../NettyNetClientAttributesGetter.java | 31 ++++++++--- .../client/NettySslNetAttributesGetter.java | 24 ++++++--- .../NettyNetServerAttributesGetter.java | 24 ++++++++- .../v2_2/OkHttp2NetAttributesGetter.java | 24 +++++++++ .../internal/OkHttpNetAttributesGetter.java | 24 +++++++++ .../PlayWsClientNetAttributesGetter.java | 13 ++++- .../RabbitChannelNetAttributesGetter.java | 16 ++++-- .../RabbitReceiveNetAttributesGetter.java | 17 ++++-- .../RatpackHttpNetAttributesGetter.java | 25 +++++++++ .../internal/RatpackNetAttributesGetter.java | 50 ++++++++++++++++- ...ReactorNettyNetClientAttributesGetter.java | 35 +++++++++++- .../redisson/RedissonNetAttributesGetter.java | 18 +++++-- .../v1_0/RestletNetAttributesGetter.java | 54 ++++++++++++++++++- .../internal/RestletNetAttributesGetter.java | 54 ++++++++++++++++++- .../servlet/v2_2/Servlet2Accessor.java | 15 ++++++ .../servlet/v3_0/Servlet3Accessor.java | 15 ++++++ .../servlet/v5_0/Servlet5Accessor.java | 35 ++++++++++-- .../servlet/ServletAccessor.java | 14 ++++- .../servlet/ServletNetAttributesGetter.java | 41 +++++++++++++- .../servlet/javax/JavaxServletAccessor.java | 10 ++++ .../web/SpringWebNetAttributesGetter.java | 29 ++++++++++ .../SpringWebfluxNetAttributesGetter.java | 25 +++++++++ .../v5_3/SpringWebMvcNetAttributesGetter.java | 38 ++++++++++++- .../common/TomcatNetAttributesGetter.java | 44 +++++++++++++-- .../undertow/UndertowNetAttributesGetter.java | 24 +++++++-- .../client/Vertx4NetAttributesGetter.java | 20 ++++++- 82 files changed, 1782 insertions(+), 243 deletions(-) diff --git a/instrumentation-api/src/jmh/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBenchmark.java b/instrumentation-api/src/jmh/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBenchmark.java index 784fa9ad4791..40b091d737c9 100644 --- a/instrumentation-api/src/jmh/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBenchmark.java +++ b/instrumentation-api/src/jmh/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBenchmark.java @@ -99,19 +99,39 @@ public List responseHeader(Void unused, Void unused2, String name) { static class ConstantNetAttributesGetter extends InetSocketAddressNetServerAttributesGetter { - private static final InetSocketAddress ADDRESS = + private static final InetSocketAddress PEER_ADDRESS = InetSocketAddress.createUnresolved("localhost", 8080); + private static final InetSocketAddress HOST_ADDRESS = + InetSocketAddress.createUnresolved("localhost", 80); @Override @Nullable - public InetSocketAddress getAddress(Void unused) { - return ADDRESS; + public String transport(Void unused) { + return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable @Override + public String hostName(Void unused) { + return null; + } + @Nullable - public String transport(Void unused) { - return SemanticAttributes.NetTransportValues.IP_TCP; + @Override + public Integer hostPort(Void unused) { + return null; + } + + @Override + @Nullable + public InetSocketAddress getPeerAddress(Void unused) { + return PEER_ADDRESS; + } + + @Nullable + @Override + public InetSocketAddress getHostAddress(Void unused) { + return HOST_ADDRESS; } } } diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpNetAttributesGetter.java b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpNetAttributesGetter.java index f786b281ea3d..8469530d7c17 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpNetAttributesGetter.java +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpNetAttributesGetter.java @@ -27,4 +27,28 @@ public String peerName(HttpRequest httpRequest, @Nullable HttpResponse httpRespo public Integer peerPort(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { return httpRequest.uri().authority().port(); } + + @Nullable + @Override + public String sockFamily(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerName(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } } diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboRequest.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboRequest.java index 8dd0b0dbe72b..0733b744c867 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboRequest.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboRequest.java @@ -19,7 +19,11 @@ static DubboRequest create(RpcInvocation invocation, RpcContext context) { // In dubbo 3 RpcContext delegates to a ThreadLocal context. We copy the url and remote address // here to ensure we can access them from the thread that ends the span. return new AutoValue_DubboRequest( - invocation, context, context.getUrl(), context.getRemoteAddress()); + invocation, + context, + context.getUrl(), + context.getRemoteAddress(), + context.getLocalAddress()); } abstract RpcInvocation invocation(); @@ -30,4 +34,7 @@ static DubboRequest create(RpcInvocation invocation, RpcContext context) { @Nullable public abstract InetSocketAddress remoteAddress(); + + @Nullable + public abstract InetSocketAddress localAddress(); } diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetClientAttributesGetter.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetClientAttributesGetter.java index 7af5c97d1ce6..8100b0fadc0a 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetClientAttributesGetter.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetClientAttributesGetter.java @@ -9,7 +9,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; import java.net.InetSocketAddress; import javax.annotation.Nullable; -import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Result; /** @@ -21,19 +20,24 @@ public final class DubboNetClientAttributesGetter @Override @Nullable - public InetSocketAddress getAddress(DubboRequest request, @Nullable Result response) { - InetSocketAddress address = request.remoteAddress(); - // dubbo 3 doesn't set remote address for client calls - if (address == null) { - URL url = request.url(); - address = InetSocketAddress.createUnresolved(url.getHost(), url.getPort()); - } - return address; + public String transport(DubboRequest request, @Nullable Result response) { + return null; + } + + @Nullable + @Override + public String peerName(DubboRequest request, @Nullable Result result) { + return request.url().getHost(); + } + + @Override + public Integer peerPort(DubboRequest request, @Nullable Result result) { + return request.url().getPort(); } @Override @Nullable - public String transport(DubboRequest request, @Nullable Result response) { - return null; + public InetSocketAddress getPeerAddress(DubboRequest request, @Nullable Result response) { + return request.remoteAddress(); } } diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesGetter.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesGetter.java index 659587637b70..aa80c525fc69 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesGetter.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesGetter.java @@ -19,13 +19,31 @@ public final class DubboNetServerAttributesGetter @Override @Nullable - public InetSocketAddress getAddress(DubboRequest request) { - return request.remoteAddress(); + public String transport(DubboRequest request) { + return null; } + @Nullable @Override + public String hostName(DubboRequest request) { + return null; + } + @Nullable - public String transport(DubboRequest request) { + @Override + public Integer hostPort(DubboRequest request) { return null; } + + @Override + @Nullable + public InetSocketAddress getPeerAddress(DubboRequest request) { + return request.remoteAddress(); + } + + @Nullable + @Override + public InetSocketAddress getHostAddress(DubboRequest request) { + return request.localAddress(); + } } diff --git a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesGetter.java b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesGetter.java index da311b325e01..8cb247a4f47c 100644 --- a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesGetter.java +++ b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesGetter.java @@ -5,13 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpasyncclient; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.net.InetSocketAddress; import javax.annotation.Nullable; import org.apache.http.HttpResponse; final class ApacheHttpAsyncClientNetAttributesGetter - implements NetClientAttributesGetter { + extends InetSocketAddressNetClientAttributesGetter { @Override public String transport(ApacheHttpClientRequest request, @Nullable HttpResponse response) { @@ -28,4 +29,11 @@ public String peerName(ApacheHttpClientRequest request, @Nullable HttpResponse r public Integer peerPort(ApacheHttpClientRequest request, @Nullable HttpResponse response) { return request.getPeerPort(); } + + @Nullable + @Override + public InetSocketAddress getPeerAddress( + ApacheHttpClientRequest request, @Nullable HttpResponse response) { + return request.peerAddress(); + } } diff --git a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpClientRequest.java b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpClientRequest.java index dd92339354dc..656e3c926815 100644 --- a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpClientRequest.java +++ b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpClientRequest.java @@ -8,6 +8,8 @@ import static java.util.logging.Level.FINE; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -27,8 +29,9 @@ public final class ApacheHttpClientRequest { @Nullable private final URI uri; private final HttpRequest delegate; + @Nullable private final HttpHost target; - public ApacheHttpClientRequest(HttpHost httpHost, HttpRequest httpRequest) { + public ApacheHttpClientRequest(@Nullable HttpHost httpHost, HttpRequest httpRequest) { URI calculatedUri = getUri(httpRequest); if (calculatedUri != null && httpHost != null) { uri = getCalculatedUri(httpHost, calculatedUri); @@ -36,6 +39,7 @@ public ApacheHttpClientRequest(HttpHost httpHost, HttpRequest httpRequest) { uri = calculatedUri; } delegate = httpRequest; + target = httpHost; } public List getHeader(String name) { @@ -143,4 +147,13 @@ private static URI getCalculatedUri(HttpHost httpHost, URI uri) { return null; } } + + @Nullable + public InetSocketAddress peerAddress() { + if (target == null) { + return null; + } + InetAddress inetAddress = target.getAddress(); + return inetAddress == null ? null : new InetSocketAddress(inetAddress, target.getPort()); + } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesGetter.java b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesGetter.java index 04489aa8a1cd..02c09d6c555b 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesGetter.java +++ b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesGetter.java @@ -32,4 +32,28 @@ public Integer peerPort(HttpMethod request, @Nullable HttpMethod response) { HostConfiguration hostConfiguration = request.getHostConfiguration(); return hostConfiguration != null ? hostConfiguration.getPort() : null; } + + @Nullable + @Override + public String sockFamily(HttpMethod request, @Nullable HttpMethod response) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(HttpMethod request, @Nullable HttpMethod response) { + return null; + } + + @Nullable + @Override + public String sockPeerName(HttpMethod request, @Nullable HttpMethod response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(HttpMethod request, @Nullable HttpMethod response) { + return null; + } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesGetter.java b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesGetter.java index f310ae87be0a..efd58e50c6bc 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesGetter.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesGetter.java @@ -28,4 +28,28 @@ public String peerName(ApacheHttpClientRequest request, @Nullable HttpResponse r public Integer peerPort(ApacheHttpClientRequest request, @Nullable HttpResponse response) { return request.getPeerPort(); } + + @Nullable + @Override + public String sockFamily(ApacheHttpClientRequest request, @Nullable HttpResponse response) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(ApacheHttpClientRequest request, @Nullable HttpResponse response) { + return null; + } + + @Nullable + @Override + public String sockPeerName(ApacheHttpClientRequest request, @Nullable HttpResponse response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(ApacheHttpClientRequest request, @Nullable HttpResponse response) { + return null; + } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesGetter.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesGetter.java index 27a4176a3384..aa852325ddb6 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesGetter.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesGetter.java @@ -5,13 +5,14 @@ package io.opentelemetry.instrumentation.apachehttpclient.v4_3; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.net.InetSocketAddress; import javax.annotation.Nullable; import org.apache.http.HttpResponse; final class ApacheHttpClientNetAttributesGetter - implements NetClientAttributesGetter { + extends InetSocketAddressNetClientAttributesGetter { @Override public String transport(ApacheHttpClientRequest request, @Nullable HttpResponse response) { @@ -29,4 +30,11 @@ public String peerName(ApacheHttpClientRequest request, @Nullable HttpResponse r public Integer peerPort(ApacheHttpClientRequest request, @Nullable HttpResponse response) { return request.getPeerPort(); } + + @Nullable + @Override + public InetSocketAddress getPeerAddress( + ApacheHttpClientRequest request, @Nullable HttpResponse response) { + return request.peerAddress(); + } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientRequest.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientRequest.java index 4264c9035329..37881375e174 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientRequest.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientRequest.java @@ -8,6 +8,8 @@ import static java.util.logging.Level.FINE; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -27,6 +29,7 @@ public final class ApacheHttpClientRequest { @Nullable private final URI uri; private final HttpRequest delegate; + @Nullable private final HttpHost target; ApacheHttpClientRequest(@Nullable HttpHost httpHost, HttpRequest httpRequest) { URI calculatedUri = getUri(httpRequest); @@ -36,6 +39,7 @@ public final class ApacheHttpClientRequest { uri = calculatedUri; } delegate = httpRequest; + target = httpHost; } /** Returns the actual {@link HttpRequest} being executed by the client. */ @@ -146,4 +150,13 @@ private static URI getCalculatedUri(HttpHost httpHost, URI uri) { return null; } } + + @Nullable + public InetSocketAddress peerAddress() { + if (target == null) { + return null; + } + InetAddress inetAddress = target.getAddress(); + return inetAddress == null ? null : new InetSocketAddress(inetAddress, target.getPort()); + } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesGetter.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesGetter.java index 46d30cffd813..65e370c06d67 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesGetter.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesGetter.java @@ -50,4 +50,28 @@ public Integer peerPort(HttpRequest request, @Nullable HttpResponse response) { return null; } } + + @Nullable + @Override + public String sockFamily(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerName(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } } diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java index 6b3983a2b869..8e386b2c54d5 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java @@ -20,13 +20,35 @@ public String transport(RequestContext ctx) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable + @Override + public String hostName(RequestContext ctx) { + return null; + } + + @Nullable + @Override + public Integer hostPort(RequestContext ctx) { + return null; + } + @Override @Nullable - public InetSocketAddress getAddress(RequestContext ctx) { + public InetSocketAddress getPeerAddress(RequestContext ctx) { SocketAddress address = ctx.remoteAddress(); if (address instanceof InetSocketAddress) { return (InetSocketAddress) address; } return null; } + + @Nullable + @Override + public InetSocketAddress getHostAddress(RequestContext ctx) { + SocketAddress address = ctx.localAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } + return null; + } } diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesGetter.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesGetter.java index 1e246b5af1c2..fce749b748d8 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesGetter.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesGetter.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.armeria.v1_3.internal; +import com.linecorp.armeria.common.HttpRequest; import com.linecorp.armeria.common.RequestContext; import com.linecorp.armeria.common.logging.RequestLog; import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; @@ -25,13 +26,33 @@ public String transport(RequestContext ctx, @Nullable RequestLog requestLog) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable + @Override + public String peerName(RequestContext ctx, @Nullable RequestLog requestLog) { + return request(ctx).uri().getHost(); + } + + @Override + public Integer peerPort(RequestContext ctx, @Nullable RequestLog requestLog) { + return request(ctx).uri().getPort(); + } + @Override @Nullable - public InetSocketAddress getAddress(RequestContext ctx, @Nullable RequestLog requestLog) { + public InetSocketAddress getPeerAddress(RequestContext ctx, @Nullable RequestLog requestLog) { SocketAddress address = ctx.remoteAddress(); if (address instanceof InetSocketAddress) { return (InetSocketAddress) address; } return null; } + + private static HttpRequest request(RequestContext ctx) { + HttpRequest request = ctx.request(); + if (request == null) { + throw new IllegalStateException( + "Context always has a request in decorators, this exception indicates a programming bug."); + } + return request; + } } diff --git a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesGetter.java b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesGetter.java index c5c44f10d8f9..14704ab41c8b 100644 --- a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesGetter.java +++ b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesGetter.java @@ -28,4 +28,28 @@ public String peerName(Request request, @Nullable Response response) { public Integer peerPort(Request request, @Nullable Response response) { return request.getUri().getPort(); } + + @Nullable + @Override + public String sockFamily(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerName(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(Request request, @Nullable Response response) { + return null; + } } diff --git a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesGetter.java b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesGetter.java index 3f720975e7bb..01b0056dbf22 100644 --- a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesGetter.java +++ b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesGetter.java @@ -19,9 +19,20 @@ public String transport(RequestContext request, @Nullable Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable + @Override + public String peerName(RequestContext requestContext, @Nullable Response response) { + return requestContext.getRequest().getUri().getHost(); + } + + @Override + public Integer peerPort(RequestContext requestContext, @Nullable Response response) { + return requestContext.getRequest().getUri().getPort(); + } + @Override @Nullable - public InetSocketAddress getAddress(RequestContext request, @Nullable Response response) { + public InetSocketAddress getPeerAddress(RequestContext request, @Nullable Response response) { if (response != null && response.getRemoteAddress() instanceof InetSocketAddress) { return (InetSocketAddress) response.getRemoteAddress(); } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkNetAttributesGetter.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkNetAttributesGetter.java index a681e8836fbd..5c5b8d8776fb 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkNetAttributesGetter.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkNetAttributesGetter.java @@ -28,4 +28,28 @@ public String peerName(Request request, @Nullable Response response) { public Integer peerPort(Request request, @Nullable Response response) { return request.getEndpoint().getPort(); } + + @Nullable + @Override + public String sockFamily(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerName(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(Request request, @Nullable Response response) { + return null; + } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkNetAttributesGetter.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkNetAttributesGetter.java index 5d597d01d514..4dff37fe598e 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkNetAttributesGetter.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkNetAttributesGetter.java @@ -34,4 +34,28 @@ public Integer peerPort(ExecutionAttributes request, @Nullable SdkHttpResponse r request.getAttribute(TracingExecutionInterceptor.SDK_HTTP_REQUEST_ATTRIBUTE); return httpRequest.port(); } + + @Nullable + @Override + public String sockFamily(ExecutionAttributes request, @Nullable SdkHttpResponse response) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(ExecutionAttributes request, @Nullable SdkHttpResponse response) { + return null; + } + + @Nullable + @Override + public String sockPeerName(ExecutionAttributes request, @Nullable SdkHttpResponse response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(ExecutionAttributes request, @Nullable SdkHttpResponse response) { + return null; + } } diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetAttributesGetter.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetAttributesGetter.java index c8b625e588c9..e5b64294a5c9 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetAttributesGetter.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetAttributesGetter.java @@ -19,9 +19,21 @@ public String transport(CassandraRequest request, @Nullable ExecutionInfo execut return null; } + @Nullable + @Override + public String peerName(CassandraRequest request, @Nullable ExecutionInfo executionInfo) { + return null; + } + + @Nullable + @Override + public Integer peerPort(CassandraRequest request, @Nullable ExecutionInfo executionInfo) { + return null; + } + @Override @Nullable - public InetSocketAddress getAddress( + public InetSocketAddress getPeerAddress( CassandraRequest request, @Nullable ExecutionInfo executionInfo) { return executionInfo == null ? null : executionInfo.getQueriedHost().getSocketAddress(); } diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetAttributesGetter.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetAttributesGetter.java index cb58a2a6d434..9ae496fc3e2d 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetAttributesGetter.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetAttributesGetter.java @@ -21,9 +21,21 @@ public String transport(CassandraRequest request, @Nullable ExecutionInfo execut return null; } + @Nullable + @Override + public String peerName(CassandraRequest request, @Nullable ExecutionInfo executionInfo) { + return null; + } + + @Nullable + @Override + public Integer peerPort(CassandraRequest request, @Nullable ExecutionInfo executionInfo) { + return null; + } + @Override @Nullable - public InetSocketAddress getAddress( + public InetSocketAddress getPeerAddress( CassandraRequest request, @Nullable ExecutionInfo executionInfo) { if (executionInfo == null) { return null; diff --git a/instrumentation/couchbase/couchbase-2-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseRequestInfo.java b/instrumentation/couchbase/couchbase-2-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseRequestInfo.java index f7e01a33ff5c..992a8512f855 100644 --- a/instrumentation/couchbase/couchbase-2-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseRequestInfo.java +++ b/instrumentation/couchbase/couchbase-2-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseRequestInfo.java @@ -11,6 +11,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.db.SqlStatementInfo; +import java.net.SocketAddress; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import javax.annotation.Nullable; @@ -29,10 +30,9 @@ protected Map computeValue(Class type) { } }; - private String peerName; - private Integer peerPort; private String localAddress; private String operationId; + private SocketAddress peerAddress; public static CouchbaseRequestInfo create( @Nullable String bucket, Class declaringClass, String methodName) { @@ -76,24 +76,6 @@ public static CouchbaseRequestInfo get(Context context) { public abstract boolean isMethodCall(); - @Nullable - public String getPeerName() { - return peerName; - } - - public void setPeerName(String peerName) { - this.peerName = peerName; - } - - @Nullable - public Integer getPeerPort() { - return peerPort; - } - - public void setPeerPort(Integer peerPort) { - this.peerPort = peerPort; - } - @Nullable public String getLocalAddress() { return localAddress; @@ -111,4 +93,13 @@ public String getOperationId() { public void setOperationId(String operationId) { this.operationId = operationId; } + + @Nullable + public SocketAddress getPeerAddress() { + return peerAddress; + } + + public void setPeerAddress(SocketAddress peerAddress) { + this.peerAddress = peerAddress; + } } diff --git a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetAttributesGetter.java b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetAttributesGetter.java index 582b8eeb2083..f5e222a8c003 100644 --- a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetAttributesGetter.java +++ b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetAttributesGetter.java @@ -5,16 +5,18 @@ package io.opentelemetry.javaagent.instrumentation.couchbase.v2_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import javax.annotation.Nullable; public class CouchbaseNetAttributesGetter - implements NetClientAttributesGetter { + extends InetSocketAddressNetClientAttributesGetter { @Nullable @Override public String transport(CouchbaseRequestInfo couchbaseRequest, @Nullable Void unused) { - return couchbaseRequest.getPeerName() != null + return couchbaseRequest.getPeerAddress() != null ? SemanticAttributes.NetTransportValues.IP_TCP : null; } @@ -22,12 +24,23 @@ public String transport(CouchbaseRequestInfo couchbaseRequest, @Nullable Void un @Nullable @Override public String peerName(CouchbaseRequestInfo couchbaseRequest, @Nullable Void unused) { - return couchbaseRequest.getPeerName(); + return null; } @Nullable @Override public Integer peerPort(CouchbaseRequestInfo couchbaseRequest, @Nullable Void unused) { - return couchbaseRequest.getPeerPort(); + return null; + } + + @Nullable + @Override + public InetSocketAddress getPeerAddress( + CouchbaseRequestInfo couchbaseRequest, @Nullable Void unused) { + SocketAddress peerAddress = couchbaseRequest.getPeerAddress(); + if (peerAddress instanceof InetSocketAddress) { + return (InetSocketAddress) peerAddress; + } + return null; } } diff --git a/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseNetworkInstrumentation.java b/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseNetworkInstrumentation.java index 697403a14bb5..4794b9fcaf2a 100644 --- a/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseNetworkInstrumentation.java +++ b/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseNetworkInstrumentation.java @@ -11,6 +11,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import com.couchbase.client.core.message.CouchbaseRequest; +import com.couchbase.client.deps.io.netty.channel.ChannelHandlerContext; import io.opentelemetry.instrumentation.api.util.VirtualField; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -46,26 +47,16 @@ public static class CouchbaseNetworkAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) public static void addNetworkTagsToSpan( - @Advice.FieldValue("remoteHostname") String remoteHostname, - @Advice.FieldValue("remoteSocket") String remoteSocket, @Advice.FieldValue("localSocket") String localSocket, + @Advice.Argument(0) ChannelHandlerContext channelHandlerContext, @Advice.Argument(1) CouchbaseRequest request) { + VirtualField virtualField = VirtualField.find(CouchbaseRequest.class, CouchbaseRequestInfo.class); CouchbaseRequestInfo requestInfo = virtualField.get(request); if (requestInfo != null) { - if (remoteHostname != null) { - requestInfo.setPeerName(remoteHostname); - } - - if (remoteSocket != null) { - int splitIndex = remoteSocket.lastIndexOf(":"); - if (splitIndex != -1) { - requestInfo.setPeerPort(Integer.parseInt(remoteSocket.substring(splitIndex + 1))); - } - } - + requestInfo.setPeerAddress(channelHandlerContext.channel().remoteAddress()); requestInfo.setLocalAddress(localSocket); } } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesGetter.java b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesGetter.java index 7d3db6ec4e62..ad4ff9e40c24 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesGetter.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesGetter.java @@ -46,6 +46,18 @@ public String sockPeerAddr(ElasticsearchRestRequest request, @Nullable Response return null; } + @Nullable + @Override + public String sockPeerName(ElasticsearchRestRequest request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(ElasticsearchRestRequest request, @Nullable Response response) { + return null; + } + @Nullable @Override public String sockFamily( diff --git a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetAttributesGetter.java b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetAttributesGetter.java index 5374fe27fbab..79e7f194f16e 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetAttributesGetter.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetAttributesGetter.java @@ -19,9 +19,21 @@ public String transport(ElasticTransportRequest request, @Nullable ActionRespons return null; } + @Nullable + @Override + public String peerName(ElasticTransportRequest request, @Nullable ActionResponse response) { + return null; + } + + @Nullable + @Override + public Integer peerPort(ElasticTransportRequest request, @Nullable ActionResponse response) { + return null; + } + @Override @Nullable - public InetSocketAddress getAddress( + public InetSocketAddress getPeerAddress( ElasticTransportRequest request, @Nullable ActionResponse response) { if (response != null && response.remoteAddress() != null) { return response.remoteAddress().address(); diff --git a/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetResponseAttributesGetter.java b/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetResponseAttributesGetter.java index 8203698d4a7a..1d556d5b9d65 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetResponseAttributesGetter.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetResponseAttributesGetter.java @@ -21,18 +21,18 @@ public String transport(ElasticTransportRequest request, @Nullable ActionRespons @Override @Nullable public String peerName(ElasticTransportRequest request, @Nullable ActionResponse response) { - if (response != null && response.remoteAddress() != null) { - return response.remoteAddress().getHost(); - } return null; } @Override @Nullable public Integer peerPort(ElasticTransportRequest request, @Nullable ActionResponse response) { - if (response != null && response.remoteAddress() != null) { - return response.remoteAddress().getPort(); - } + return null; + } + + @Nullable + @Override + public String sockFamily(ElasticTransportRequest request, @Nullable ActionResponse response) { return null; } @@ -45,5 +45,21 @@ public String sockPeerAddr(ElasticTransportRequest request, @Nullable ActionResp return null; } - // TODO (trask) implement sockFamily + @Nullable + @Override + public String sockPeerName(ElasticTransportRequest request, @Nullable ActionResponse response) { + if (response != null && response.remoteAddress() != null) { + return response.remoteAddress().getHost(); + } + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(ElasticTransportRequest request, @Nullable ActionResponse response) { + if (response != null && response.remoteAddress() != null) { + return response.remoteAddress().getPort(); + } + return null; + } } diff --git a/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientNetAttributesGetter.java b/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientNetAttributesGetter.java index b9decdb47878..6a5f00d7aba9 100644 --- a/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientNetAttributesGetter.java +++ b/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientNetAttributesGetter.java @@ -27,10 +27,30 @@ public String peerName(HttpRequest request, @Nullable HttpResponse response) { @Override public Integer peerPort(HttpRequest request, @Nullable HttpResponse response) { - int port = request.getUrl().getPort(); - if (port != -1) { - return port; - } + return request.getUrl().getPort(); + } + + @Nullable + @Override + public String sockFamily(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerName(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { return null; } } diff --git a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java index 8fe5900bc087..9a3e81cfaebf 100644 --- a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java +++ b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java @@ -5,18 +5,44 @@ package io.opentelemetry.javaagent.instrumentation.grizzly; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP; + import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import javax.annotation.Nullable; import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.nio.transport.TCPNIOTransport; final class GrizzlyNetAttributesGetter implements NetServerAttributesGetter { - @Nullable @Override public String transport(HttpRequestPacket request) { + return request.getConnection().getTransport() instanceof TCPNIOTransport ? IP_TCP : IP_UDP; + } + + @Nullable + @Override + public String hostName(HttpRequestPacket request) { + return request.getLocalHost(); + } + + @Override + public Integer hostPort(HttpRequestPacket request) { + return request.getServerPort(); + } + + @Nullable + @Override + public String sockFamily(HttpRequestPacket request) { return null; } + @Nullable + @Override + public String sockPeerAddr(HttpRequestPacket request) { + return request.getRemoteAddress(); + } + @Override public Integer sockPeerPort(HttpRequestPacket request) { return request.getRemotePort(); @@ -24,7 +50,18 @@ public Integer sockPeerPort(HttpRequestPacket request) { @Nullable @Override - public String sockPeerAddr(HttpRequestPacket request) { - return request.getRemoteAddress(); + public String sockHostAddr(HttpRequestPacket request) { + return request.getLocalAddress(); + } + + @Nullable + @Override + public String sockHostName(HttpRequestPacket request) { + return null; + } + + @Override + public Integer sockHostPort(HttpRequestPacket request) { + return request.getLocalPort(); } } diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcRequest.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcRequest.java index dd1a49936a73..0e80a1959439 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcRequest.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcRequest.java @@ -8,6 +8,7 @@ import io.grpc.Metadata; import io.grpc.MethodDescriptor; import java.net.SocketAddress; +import java.net.URI; import javax.annotation.Nullable; public final class GrpcRequest { @@ -16,15 +17,19 @@ public final class GrpcRequest { @Nullable private volatile Metadata metadata; - @Nullable private volatile SocketAddress remoteAddress; + @Nullable private volatile String logicalHost; + private volatile int logicalPort = -1; + @Nullable private volatile SocketAddress peerAddress; GrpcRequest( MethodDescriptor method, @Nullable Metadata metadata, - @Nullable SocketAddress remoteAddress) { + @Nullable SocketAddress peerAddress, + @Nullable String authority) { this.method = method; this.metadata = metadata; - this.remoteAddress = remoteAddress; + this.peerAddress = peerAddress; + setLogicalAddress(authority); } public MethodDescriptor getMethod() { @@ -41,11 +46,33 @@ void setMetadata(Metadata metadata) { } @Nullable - public SocketAddress getRemoteAddress() { - return remoteAddress; + public String getLogicalHost() { + return logicalHost; } - void setRemoteAddress(SocketAddress remoteAddress) { - this.remoteAddress = remoteAddress; + public int getLogicalPort() { + return logicalPort; + } + + void setLogicalAddress(@Nullable String authority) { + if (authority == null) { + return; + } + try { + URI uri = new URI(null, authority, null, null, null); + logicalHost = uri.getHost(); + logicalPort = uri.getPort(); + } catch (Throwable e) { + // do nothing + } + } + + @Nullable + public SocketAddress getPeerAddress() { + return peerAddress; + } + + void setPeerAddress(SocketAddress peerAddress) { + this.peerAddress = peerAddress; } } diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java index ead17c9a962d..26885ec8f1e2 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java @@ -11,6 +11,7 @@ import io.grpc.ClientInterceptor; import io.grpc.ForwardingClientCall; import io.grpc.ForwardingClientCallListener; +import io.grpc.Grpc; import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.Status; @@ -20,9 +21,6 @@ import io.opentelemetry.context.Scope; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.net.URI; import java.util.concurrent.atomic.AtomicLongFieldUpdater; final class TracingClientInterceptor implements ClientInterceptor { @@ -43,7 +41,7 @@ final class TracingClientInterceptor implements ClientInterceptor { @Override public ClientCall interceptCall( MethodDescriptor method, CallOptions callOptions, Channel next) { - GrpcRequest request = new GrpcRequest(method, null, null); + GrpcRequest request = new GrpcRequest(method, null, null, null); Context parentContext = Context.current(); if (!instrumenter.shouldStart(parentContext, request)) { return next.newCall(method, callOptions); @@ -60,14 +58,9 @@ public ClientCall interceptCall( throw e; } } - SocketAddress address = null; - try { - URI uri = new URI(null, next.authority(), null, null, null); - address = InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort()); - } catch (Throwable e) { - // do nothing - } - request.setRemoteAddress(address); + + request.setLogicalAddress(next.authority()); + request.setPeerAddress(result.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR)); return new TracingClientCall<>(result, parentContext, context, request); } diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingServerInterceptor.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingServerInterceptor.java index 7aca5ff2779f..bd4175d1f62c 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingServerInterceptor.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingServerInterceptor.java @@ -45,7 +45,8 @@ public ServerCall.Listener interceptCall( new GrpcRequest( call.getMethodDescriptor(), headers, - call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR)); + call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR), + call.getAuthority()); Context parentContext = Context.current(); if (!instrumenter.shouldStart(parentContext, request)) { return next.startCall(call, headers); diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetClientAttributesGetter.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetClientAttributesGetter.java index 37b2bb6589b1..ecc5948bf5eb 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetClientAttributesGetter.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetClientAttributesGetter.java @@ -19,18 +19,30 @@ */ public final class GrpcNetClientAttributesGetter extends InetSocketAddressNetClientAttributesGetter { + + @Override + public String transport(GrpcRequest request, @Nullable Status response) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } + + @Nullable + @Override + public String peerName(GrpcRequest grpcRequest, @Nullable Status status) { + return grpcRequest.getLogicalHost(); + } + + @Override + public Integer peerPort(GrpcRequest grpcRequest, @Nullable Status status) { + return grpcRequest.getLogicalPort(); + } + @Override @Nullable - public InetSocketAddress getAddress(GrpcRequest request, @Nullable Status response) { - SocketAddress address = request.getRemoteAddress(); + public InetSocketAddress getPeerAddress(GrpcRequest request, @Nullable Status response) { + SocketAddress address = request.getPeerAddress(); if (address instanceof InetSocketAddress) { return (InetSocketAddress) address; } return null; } - - @Override - public String transport(GrpcRequest request, @Nullable Status response) { - return SemanticAttributes.NetTransportValues.IP_TCP; - } } diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetServerAttributesGetter.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetServerAttributesGetter.java index f234e221484a..ce8c00c8bbcb 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetServerAttributesGetter.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetServerAttributesGetter.java @@ -18,18 +18,37 @@ */ public final class GrpcNetServerAttributesGetter extends InetSocketAddressNetServerAttributesGetter { + @Override + public String transport(GrpcRequest request) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } + @Nullable - public InetSocketAddress getAddress(GrpcRequest request) { - SocketAddress address = request.getRemoteAddress(); + @Override + public String hostName(GrpcRequest grpcRequest) { + return grpcRequest.getLogicalHost(); + } + + @Override + public Integer hostPort(GrpcRequest grpcRequest) { + return grpcRequest.getLogicalPort(); + } + + @Override + @Nullable + public InetSocketAddress getPeerAddress(GrpcRequest request) { + SocketAddress address = request.getPeerAddress(); if (address instanceof InetSocketAddress) { return (InetSocketAddress) address; } return null; } + @Nullable @Override - public String transport(GrpcRequest request) { - return SemanticAttributes.NetTransportValues.IP_TCP; + public InetSocketAddress getHostAddress(GrpcRequest grpcRequest) { + // TODO: later version introduces TRANSPORT_ATTR_LOCAL_ADDR, might be a good idea to use it + return null; } } diff --git a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesGetter.java b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesGetter.java index f03e2f5cf833..c0c185abfd1a 100644 --- a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesGetter.java +++ b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesGetter.java @@ -27,4 +27,28 @@ public String peerName(HttpURLConnection connection, @Nullable Integer status) { public Integer peerPort(HttpURLConnection connection, @Nullable Integer status) { return connection.getURL().getPort(); } + + @Nullable + @Override + public String sockFamily(HttpURLConnection connection, @Nullable Integer status) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(HttpURLConnection connection, @Nullable Integer status) { + return null; + } + + @Nullable + @Override + public String sockPeerName(HttpURLConnection connection, @Nullable Integer status) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(HttpURLConnection connection, @Nullable Integer status) { + return null; + } } diff --git a/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpNetAttributesGetter.java b/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpNetAttributesGetter.java index 53ac02288f0f..5b84dab3cb1b 100644 --- a/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpNetAttributesGetter.java +++ b/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpNetAttributesGetter.java @@ -51,4 +51,28 @@ public Integer peerPort(HttpRequest httpRequest, @Nullable HttpResponse respo return null; } } + + @Nullable + @Override + public String sockFamily(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerName(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + return null; + } } diff --git a/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientNetAttributesGetter.java b/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientNetAttributesGetter.java index 66a69e60c9a7..d69965b733e9 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientNetAttributesGetter.java +++ b/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientNetAttributesGetter.java @@ -27,10 +27,30 @@ public String peerName(ClientRequest request, @Nullable ClientResponse response) @Override public Integer peerPort(ClientRequest request, @Nullable ClientResponse response) { - int port = request.getURI().getPort(); - if (port != -1) { - return port; - } + return request.getURI().getPort(); + } + + @Nullable + @Override + public String sockFamily(ClientRequest request, @Nullable ClientResponse response) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(ClientRequest request, @Nullable ClientResponse response) { + return null; + } + + @Nullable + @Override + public String sockPeerName(ClientRequest request, @Nullable ClientResponse response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(ClientRequest request, @Nullable ClientResponse response) { return null; } } diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetAttributesGetter.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetAttributesGetter.java index 4cf08505204f..847f99317382 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetAttributesGetter.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetAttributesGetter.java @@ -31,4 +31,28 @@ public String peerName(DbRequest request, @Nullable Void unused) { public Integer peerPort(DbRequest request, @Nullable Void unused) { return request.getDbInfo().getPort(); } + + @Nullable + @Override + public String sockFamily(DbRequest dbRequest, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(DbRequest dbRequest, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String sockPeerName(DbRequest dbRequest, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(DbRequest dbRequest, @Nullable Void unused) { + return null; + } } diff --git a/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisNetAttributesGetter.java b/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisNetAttributesGetter.java index ab1973760b37..468d3f6debd0 100644 --- a/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisNetAttributesGetter.java +++ b/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisNetAttributesGetter.java @@ -25,4 +25,28 @@ public String peerName(JedisRequest request, @Nullable Void unused) { public Integer peerPort(JedisRequest request, @Nullable Void unused) { return request.getConnection().getPort(); } + + @Nullable + @Override + public String sockFamily(JedisRequest jedisRequest, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(JedisRequest jedisRequest, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String sockPeerName(JedisRequest jedisRequest, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(JedisRequest jedisRequest, @Nullable Void unused) { + return null; + } } diff --git a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesGetter.java b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesGetter.java index 395626a1d6ba..40bcd5731e9f 100644 --- a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesGetter.java +++ b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesGetter.java @@ -15,17 +15,28 @@ final class JedisNetAttributesGetter extends InetSocketAddressNetClientAttributesGetter { @Override + public String transport(JedisRequest jedisRequest, @Nullable Void unused) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } + @Nullable - public InetSocketAddress getAddress(JedisRequest jedisRequest, @Nullable Void unused) { + @Override + public String peerName(JedisRequest jedisRequest, @Nullable Void unused) { + return jedisRequest.getConnection().getHost(); + } + + @Override + public Integer peerPort(JedisRequest jedisRequest, @Nullable Void unused) { + return jedisRequest.getConnection().getPort(); + } + + @Override + @Nullable + public InetSocketAddress getPeerAddress(JedisRequest jedisRequest, @Nullable Void unused) { Socket socket = jedisRequest.getConnection().getSocket(); if (socket != null && socket.getRemoteSocketAddress() instanceof InetSocketAddress) { return (InetSocketAddress) socket.getRemoteSocketAddress(); } return null; } - - @Override - public String transport(JedisRequest jedisRequest, @Nullable Void unused) { - return SemanticAttributes.NetTransportValues.IP_TCP; - } } diff --git a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetAttributesGetter.java b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetAttributesGetter.java index 873daf066ec0..fb5bfac5f395 100644 --- a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetAttributesGetter.java +++ b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetAttributesGetter.java @@ -15,17 +15,29 @@ final class JedisNetAttributesGetter extends InetSocketAddressNetClientAttributesGetter { @Override + public String transport(JedisRequest jedisRequest, @Nullable Void unused) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } + @Nullable - public InetSocketAddress getAddress(JedisRequest jedisRequest, @Nullable Void unused) { - SocketAddress socketAddress = jedisRequest.getRemoteSocketAddress(); - if (socketAddress != null && socketAddress instanceof InetSocketAddress) { - return (InetSocketAddress) socketAddress; - } + @Override + public String peerName(JedisRequest jedisRequest, @Nullable Void unused) { return null; } + @Nullable @Override - public String transport(JedisRequest jedisRequest, @Nullable Void unused) { - return SemanticAttributes.NetTransportValues.IP_TCP; + public Integer peerPort(JedisRequest jedisRequest, @Nullable Void unused) { + return null; + } + + @Override + @Nullable + public InetSocketAddress getPeerAddress(JedisRequest jedisRequest, @Nullable Void unused) { + SocketAddress socketAddress = jedisRequest.getRemoteSocketAddress(); + if (socketAddress instanceof InetSocketAddress) { + return (InetSocketAddress) socketAddress; + } + return null; } } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesGetter.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesGetter.java index 1ac6a689748b..dddfe309622a 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesGetter.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesGetter.java @@ -34,4 +34,28 @@ public String peerName(Request request, @Nullable Response response) { public Integer peerPort(Request request, @Nullable Response response) { return request.getPort(); } + + @Nullable + @Override + public String sockFamily(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerName(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(Request request, @Nullable Response response) { + return null; + } } diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt index 01222d7e2475..3e80bf48802b 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt @@ -20,10 +20,34 @@ internal class KtorNetServerAttributesGetter : NetServerAttributesGetter response) { public Integer peerPort(Request request, @Nullable ApiResponse response) { return request.url().port(); } + + @Nullable + @Override + public String sockFamily(Request request, @Nullable ApiResponse apiResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(Request request, @Nullable ApiResponse apiResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerName(Request request, @Nullable ApiResponse apiResponse) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(Request request, @Nullable ApiResponse apiResponse) { + return null; + } } diff --git a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectNetAttributesGetter.java b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectNetAttributesGetter.java index 5592d4aec647..c6ab42867ec1 100644 --- a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectNetAttributesGetter.java +++ b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectNetAttributesGetter.java @@ -26,4 +26,28 @@ public String peerName(RedisURI redisUri, @Nullable Void unused) { public Integer peerPort(RedisURI redisUri, @Nullable Void unused) { return redisUri.getPort(); } + + @Nullable + @Override + public String sockFamily(RedisURI redisUri, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(RedisURI redisUri, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String sockPeerName(RedisURI redisUri, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(RedisURI redisUri, @Nullable Void unused) { + return null; + } } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectNetAttributesGetter.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectNetAttributesGetter.java index 28a33c9b1d3d..cef5c772ba2d 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectNetAttributesGetter.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectNetAttributesGetter.java @@ -26,4 +26,28 @@ public String peerName(RedisURI redisUri, @Nullable Void unused) { public Integer peerPort(RedisURI redisUri, @Nullable Void unused) { return redisUri.getPort(); } + + @Nullable + @Override + public String sockFamily(RedisURI redisUri, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(RedisURI redisUri, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String sockPeerName(RedisURI redisUri, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(RedisURI redisUri, @Nullable Void unused) { + return null; + } } diff --git a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceNetAttributesGetter.java b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceNetAttributesGetter.java index 98ce762d5371..14ec9575f12e 100644 --- a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceNetAttributesGetter.java +++ b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceNetAttributesGetter.java @@ -22,7 +22,19 @@ public String transport(OpenTelemetryEndpoint endpoint, @Nullable Void unused) { @Nullable @Override - public InetSocketAddress getAddress( + public String peerName(OpenTelemetryEndpoint openTelemetryEndpoint, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public Integer peerPort(OpenTelemetryEndpoint openTelemetryEndpoint, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public InetSocketAddress getPeerAddress( OpenTelemetryEndpoint openTelemetryEndpoint, @Nullable Void unused) { return openTelemetryEndpoint.address; } diff --git a/instrumentation/liberty/compile-stub/src/main/java/com/ibm/ws/http/dispatcher/internal/channel/HttpDispatcherLink.java b/instrumentation/liberty/compile-stub/src/main/java/com/ibm/ws/http/dispatcher/internal/channel/HttpDispatcherLink.java index 8d481ed40212..0f59dc23d6f5 100644 --- a/instrumentation/liberty/compile-stub/src/main/java/com/ibm/ws/http/dispatcher/internal/channel/HttpDispatcherLink.java +++ b/instrumentation/liberty/compile-stub/src/main/java/com/ibm/ws/http/dispatcher/internal/channel/HttpDispatcherLink.java @@ -11,15 +11,19 @@ @SuppressWarnings("OtelInternalJavadoc") public class HttpDispatcherLink { + public String getRemoteHostAddress() { + throw new UnsupportedOperationException(); + } + public int getRemotePort() { throw new UnsupportedOperationException(); } - public String getRemoteHostAddress() { + public String getLocalHostAddress() { throw new UnsupportedOperationException(); } - public int getRequestedPort() { + public int getLocalPort() { throw new UnsupportedOperationException(); } diff --git a/instrumentation/liberty/compile-stub/src/main/java/com/ibm/wsspi/http/channel/HttpRequestMessage.java b/instrumentation/liberty/compile-stub/src/main/java/com/ibm/wsspi/http/channel/HttpRequestMessage.java index e4357701db9a..5705c162a0a8 100644 --- a/instrumentation/liberty/compile-stub/src/main/java/com/ibm/wsspi/http/channel/HttpRequestMessage.java +++ b/instrumentation/liberty/compile-stub/src/main/java/com/ibm/wsspi/http/channel/HttpRequestMessage.java @@ -26,4 +26,8 @@ public interface HttpRequestMessage { String getVersion(); List getAllHeaderNames(); + + String getURLHost(); + + int getURLPort(); } diff --git a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java index 95f447ac41a3..8694c1dde953 100644 --- a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java +++ b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java @@ -13,19 +13,53 @@ public class LibertyDispatcherNetAttributesGetter implements NetServerAttributesGetter { @Override - public String transport(LibertyRequest libertyRequest) { + public String transport(LibertyRequest request) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable + @Override + public String hostName(LibertyRequest request) { + return request.request().getURLHost(); + } + + @Override + public Integer hostPort(LibertyRequest request) { + return request.request().getURLPort(); + } + + @Nullable + @Override + public String sockFamily(LibertyRequest request) { + return null; + } + @Override @Nullable - public Integer sockPeerPort(LibertyRequest libertyRequest) { - return libertyRequest.peerPort(); + public String sockPeerAddr(LibertyRequest request) { + return request.dispatcher().getRemoteHostAddress(); } @Override + public Integer sockPeerPort(LibertyRequest request) { + return request.dispatcher().getRemotePort(); + } + + @Nullable + @Override + public String sockHostAddr(LibertyRequest request) { + return request.dispatcher().getLocalHostAddress(); + } + @Nullable - public String sockPeerAddr(LibertyRequest libertyRequest) { - return libertyRequest.peerIp(); + @Override + public String sockHostName(LibertyRequest request) { + return null; + } + + @Nullable + @Override + public Integer sockHostPort(LibertyRequest request) { + return request.dispatcher().getLocalPort(); } } diff --git a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java index 8edc81bee185..245e77e6f229 100644 --- a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java +++ b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java @@ -38,10 +38,6 @@ public String getQueryString() { return httpRequestMessage.getQueryString(); } - public int getServerPort() { - return httpDispatcherLink.getRequestedPort(); - } - public List getAllHeaderNames() { return httpRequestMessage.getAllHeaderNames(); } @@ -63,15 +59,15 @@ public List getHeaderValues(String name) { return stringHeaders; } - public int peerPort() { - return httpDispatcherLink.getRemotePort(); + public String getProtocol() { + return httpRequestMessage.getVersion(); } - public String peerIp() { - return httpDispatcherLink.getRemoteHostAddress(); + public HttpDispatcherLink dispatcher() { + return httpDispatcherLink; } - public String getProtocol() { - return httpRequestMessage.getVersion(); + public HttpRequestMessage request() { + return httpRequestMessage; } } diff --git a/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoNetAttributesGetter.java b/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoNetAttributesGetter.java index 787ec3272cc1..48188df9494e 100644 --- a/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoNetAttributesGetter.java +++ b/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoNetAttributesGetter.java @@ -6,26 +6,58 @@ package io.opentelemetry.instrumentation.mongo.v3_1; import com.mongodb.event.CommandStartedEvent; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; -import java.net.InetSocketAddress; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import javax.annotation.Nullable; -class MongoNetAttributesGetter - extends InetSocketAddressNetClientAttributesGetter { +class MongoNetAttributesGetter implements NetClientAttributesGetter { + @Override @Nullable - public InetSocketAddress getAddress(CommandStartedEvent event, @Nullable Void unused) { + public String transport(CommandStartedEvent event, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String peerName(CommandStartedEvent event, @Nullable Void unused) { if (event.getConnectionDescription() != null && event.getConnectionDescription().getServerAddress() != null) { - return event.getConnectionDescription().getServerAddress().getSocketAddress(); - } else { - return null; + return event.getConnectionDescription().getServerAddress().getHost(); } + return null; + } + + @Nullable + @Override + public Integer peerPort(CommandStartedEvent event, @Nullable Void unused) { + if (event.getConnectionDescription() != null + && event.getConnectionDescription().getServerAddress() != null) { + return event.getConnectionDescription().getServerAddress().getPort(); + } + return null; } + @Nullable @Override + public String sockFamily(CommandStartedEvent event, @Nullable Void unused) { + return null; + } + @Nullable - public String transport(CommandStartedEvent commandStartedEvent, @Nullable Void unused) { + @Override + public String sockPeerAddr(CommandStartedEvent event, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public String sockPeerName(CommandStartedEvent event, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(CommandStartedEvent event, @Nullable Void unused) { return null; } } diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectNetAttributesGetter.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectNetAttributesGetter.java index e15feaa5c129..1841fcd281bc 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectNetAttributesGetter.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectNetAttributesGetter.java @@ -19,25 +19,42 @@ final class NettyConnectNetAttributesGetter extends InetSocketAddressNetClientAttributesGetter { + @Override + public String transport(NettyConnectionRequest request, @Nullable Channel channel) { + return channel instanceof DatagramChannel ? IP_UDP : IP_TCP; + } + @Nullable @Override - public InetSocketAddress getAddress(NettyConnectionRequest request, @Nullable Channel channel) { - SocketAddress remoteAddress = null; - if (channel != null) { - remoteAddress = channel.getRemoteAddress(); - } - // remote address on end() may be null when connection hasn't been established - if (remoteAddress == null) { - remoteAddress = request.remoteAddressOnStart(); + public String peerName(NettyConnectionRequest request, @Nullable Channel channel) { + SocketAddress requestedAddress = request.remoteAddressOnStart(); + if (requestedAddress instanceof InetSocketAddress) { + return ((InetSocketAddress) requestedAddress).getHostString(); } - if (remoteAddress instanceof InetSocketAddress) { - return (InetSocketAddress) remoteAddress; + return null; + } + + @Nullable + @Override + public Integer peerPort(NettyConnectionRequest request, @Nullable Channel channel) { + SocketAddress requestedAddress = request.remoteAddressOnStart(); + if (requestedAddress instanceof InetSocketAddress) { + return ((InetSocketAddress) requestedAddress).getPort(); } return null; } + @Nullable @Override - public String transport(NettyConnectionRequest request, @Nullable Channel channel) { - return channel instanceof DatagramChannel ? IP_UDP : IP_TCP; + public InetSocketAddress getPeerAddress( + NettyConnectionRequest request, @Nullable Channel channel) { + if (channel == null) { + return null; + } + SocketAddress remoteAddress = channel.getRemoteAddress(); + if (remoteAddress instanceof InetSocketAddress) { + return (InetSocketAddress) remoteAddress; + } + return null; } } diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyNetClientAttributesGetter.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyNetClientAttributesGetter.java index 8364398b0618..38275ad82ea6 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyNetClientAttributesGetter.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyNetClientAttributesGetter.java @@ -5,31 +5,48 @@ package io.opentelemetry.javaagent.instrumentation.netty.v3_8.client; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP; + import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; +import org.jboss.netty.channel.socket.DatagramChannel; import org.jboss.netty.handler.codec.http.HttpResponse; final class NettyNetClientAttributesGetter extends InetSocketAddressNetClientAttributesGetter { @Override - @Nullable - public InetSocketAddress getAddress( + public String transport( HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - SocketAddress address = requestAndChannel.channel().getRemoteAddress(); - if (address instanceof InetSocketAddress) { - return (InetSocketAddress) address; - } + return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; + } + + @Nullable + @Override + public String peerName( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public Integer peerPort( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) { return null; } @Override @Nullable - public String transport( + public InetSocketAddress getPeerAddress( HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + SocketAddress address = requestAndChannel.channel().getRemoteAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } return null; } } diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java index bed71eb95b02..07be1ce4c87f 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java @@ -19,18 +19,39 @@ final class NettyNetServerAttributesGetter extends InetSocketAddressNetServerAttributesGetter { @Override - @Nullable public String transport(HttpRequestAndChannel requestAndChannel) { return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; } + @Nullable @Override + public String hostName(HttpRequestAndChannel requestAndChannel) { + return null; + } + @Nullable - public InetSocketAddress getAddress(HttpRequestAndChannel requestAndChannel) { + @Override + public Integer hostPort(HttpRequestAndChannel requestAndChannel) { + return null; + } + + @Override + @Nullable + public InetSocketAddress getPeerAddress(HttpRequestAndChannel requestAndChannel) { SocketAddress address = requestAndChannel.channel().getRemoteAddress(); if (address instanceof InetSocketAddress) { return (InetSocketAddress) address; } return null; } + + @Nullable + @Override + public InetSocketAddress getHostAddress(HttpRequestAndChannel requestAndChannel) { + SocketAddress address = requestAndChannel.channel().getLocalAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } + return null; + } } diff --git a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettyConnectNetAttributesGetter.java b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettyConnectNetAttributesGetter.java index e4eed780c643..201ba847ec88 100644 --- a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettyConnectNetAttributesGetter.java +++ b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettyConnectNetAttributesGetter.java @@ -19,25 +19,42 @@ final class NettyConnectNetAttributesGetter extends InetSocketAddressNetClientAttributesGetter { + @Override + public String transport(NettyConnectionRequest request, @Nullable Channel channel) { + return channel instanceof DatagramChannel ? IP_UDP : IP_TCP; + } + @Nullable @Override - public InetSocketAddress getAddress(NettyConnectionRequest request, @Nullable Channel channel) { - SocketAddress remoteAddress = null; - if (channel != null) { - remoteAddress = channel.remoteAddress(); - } - // remote address on end() may be null when connection hasn't been established - if (remoteAddress == null) { - remoteAddress = request.remoteAddressOnStart(); + public String peerName(NettyConnectionRequest request, @Nullable Channel channel) { + SocketAddress requestedAddress = request.remoteAddressOnStart(); + if (requestedAddress instanceof InetSocketAddress) { + return ((InetSocketAddress) requestedAddress).getHostString(); } - if (remoteAddress instanceof InetSocketAddress) { - return (InetSocketAddress) remoteAddress; + return null; + } + + @Nullable + @Override + public Integer peerPort(NettyConnectionRequest request, @Nullable Channel channel) { + SocketAddress requestedAddress = request.remoteAddressOnStart(); + if (requestedAddress instanceof InetSocketAddress) { + return ((InetSocketAddress) requestedAddress).getPort(); } return null; } + @Nullable @Override - public String transport(NettyConnectionRequest request, @Nullable Channel channel) { - return channel instanceof DatagramChannel ? IP_UDP : IP_TCP; + public InetSocketAddress getPeerAddress( + NettyConnectionRequest request, @Nullable Channel channel) { + if (channel == null) { + return null; + } + SocketAddress remoteAddress = channel.remoteAddress(); + if (remoteAddress instanceof InetSocketAddress) { + return (InetSocketAddress) remoteAddress; + } + return null; } } diff --git a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettyNetClientAttributesGetter.java b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettyNetClientAttributesGetter.java index eaa541fd7b5b..0ad10ce347fb 100644 --- a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettyNetClientAttributesGetter.java +++ b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettyNetClientAttributesGetter.java @@ -5,6 +5,10 @@ package io.opentelemetry.javaagent.instrumentation.netty.v4.common.client; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP; + +import io.netty.channel.socket.DatagramChannel; import io.netty.handler.codec.http.HttpResponse; import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; import io.opentelemetry.javaagent.instrumentation.netty.v4.common.HttpRequestAndChannel; @@ -16,20 +20,33 @@ final class NettyNetClientAttributesGetter extends InetSocketAddressNetClientAttributesGetter { @Override - @Nullable - public InetSocketAddress getAddress( + public String transport( HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - SocketAddress address = requestAndChannel.remoteAddress(); - if (address instanceof InetSocketAddress) { - return (InetSocketAddress) address; - } + return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; + } + + @Nullable + @Override + public String peerName( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public Integer peerPort( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) { return null; } @Override @Nullable - public String transport( + public InetSocketAddress getPeerAddress( HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + SocketAddress address = requestAndChannel.remoteAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } return null; } } diff --git a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettySslNetAttributesGetter.java b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettySslNetAttributesGetter.java index a836893583d9..0ac439c7629e 100644 --- a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettySslNetAttributesGetter.java +++ b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/client/NettySslNetAttributesGetter.java @@ -16,17 +16,29 @@ final class NettySslNetAttributesGetter extends InetSocketAddressNetClientAttributesGetter { + @Override + public String transport(NettySslRequest request, @Nullable Void unused) { + return request.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; + } + @Nullable @Override - public InetSocketAddress getAddress(NettySslRequest request, @Nullable Void unused) { - if (request.remoteAddress() instanceof InetSocketAddress) { - return (InetSocketAddress) request.remoteAddress(); - } + public String peerName(NettySslRequest nettySslRequest, @Nullable Void unused) { return null; } + @Nullable @Override - public String transport(NettySslRequest request, @Nullable Void unused) { - return request.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; + public Integer peerPort(NettySslRequest nettySslRequest, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public InetSocketAddress getPeerAddress(NettySslRequest request, @Nullable Void unused) { + if (request.remoteAddress() instanceof InetSocketAddress) { + return (InetSocketAddress) request.remoteAddress(); + } + return null; } } diff --git a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/server/NettyNetServerAttributesGetter.java b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/server/NettyNetServerAttributesGetter.java index c0247d1ef672..d21319eb6e82 100644 --- a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/server/NettyNetServerAttributesGetter.java +++ b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/server/NettyNetServerAttributesGetter.java @@ -24,13 +24,35 @@ public String transport(HttpRequestAndChannel requestAndChannel) { return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; } + @Nullable + @Override + public String hostName(HttpRequestAndChannel requestAndChannel) { + return null; + } + + @Nullable + @Override + public Integer hostPort(HttpRequestAndChannel requestAndChannel) { + return null; + } + @Override @Nullable - public InetSocketAddress getAddress(HttpRequestAndChannel requestAndChannel) { + public InetSocketAddress getPeerAddress(HttpRequestAndChannel requestAndChannel) { SocketAddress address = requestAndChannel.remoteAddress(); if (address instanceof InetSocketAddress) { return (InetSocketAddress) address; } return null; } + + @Nullable + @Override + public InetSocketAddress getHostAddress(HttpRequestAndChannel requestAndChannel) { + SocketAddress address = requestAndChannel.channel().localAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } + return null; + } } diff --git a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesGetter.java b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesGetter.java index 874dd82591ed..53ead976a539 100644 --- a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesGetter.java +++ b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesGetter.java @@ -29,4 +29,28 @@ public String peerName(Request request, @Nullable Response response) { public Integer peerPort(Request request, @Nullable Response response) { return request.url().getPort(); } + + @Nullable + @Override + public String sockFamily(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerName(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(Request request, @Nullable Response response) { + return null; + } } diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesGetter.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesGetter.java index 318b6d8d9733..32d3291870d7 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesGetter.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesGetter.java @@ -33,4 +33,28 @@ public String peerName(Request request, @Nullable Response response) { public Integer peerPort(Request request, @Nullable Response response) { return request.url().port(); } + + @Nullable + @Override + public String sockFamily(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public String sockPeerName(Request request, @Nullable Response response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(Request request, @Nullable Response response) { + return null; + } } diff --git a/instrumentation/play/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientNetAttributesGetter.java b/instrumentation/play/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientNetAttributesGetter.java index 96df0b34088f..3b3ee1c09c37 100644 --- a/instrumentation/play/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientNetAttributesGetter.java +++ b/instrumentation/play/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientNetAttributesGetter.java @@ -20,9 +20,20 @@ public String transport(Request request, @Nullable Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable + @Override + public String peerName(Request request, @Nullable Response response) { + return request.getUri().getHost(); + } + + @Override + public Integer peerPort(Request request, @Nullable Response response) { + return request.getUri().getPort(); + } + @Override @Nullable - public InetSocketAddress getAddress(Request request, @Nullable Response response) { + public InetSocketAddress getPeerAddress(Request request, @Nullable Response response) { if (response != null && response.getRemoteAddress() instanceof InetSocketAddress) { return (InetSocketAddress) response.getRemoteAddress(); } diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitChannelNetAttributesGetter.java b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitChannelNetAttributesGetter.java index 3b30d16be2b6..794c186c81a3 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitChannelNetAttributesGetter.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitChannelNetAttributesGetter.java @@ -21,14 +21,13 @@ public String transport(ChannelAndMethod channelAndMethod, @Nullable Void unused @Nullable @Override public String peerName(ChannelAndMethod channelAndMethod, @Nullable Void unused) { - // not using InetAddress.getHostName() since that can trigger reverse name lookup - return channelAndMethod.getChannel().getConnection().getAddress().getHostAddress(); + return null; } @Nullable @Override public Integer peerPort(ChannelAndMethod channelAndMethod, @Nullable Void unused) { - return channelAndMethod.getChannel().getConnection().getPort(); + return null; } @Nullable @@ -37,6 +36,17 @@ public String sockPeerAddr(ChannelAndMethod channelAndMethod, @Nullable Void unu return channelAndMethod.getChannel().getConnection().getAddress().getHostAddress(); } + @Nullable + @Override + public String sockPeerName(ChannelAndMethod channelAndMethod, @Nullable Void unused) { + return null; + } + + @Override + public Integer sockPeerPort(ChannelAndMethod channelAndMethod, @Nullable Void unused) { + return channelAndMethod.getChannel().getConnection().getPort(); + } + @Nullable @Override public String sockFamily(ChannelAndMethod channelAndMethod, @Nullable Void unused) { diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitReceiveNetAttributesGetter.java b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitReceiveNetAttributesGetter.java index a34f22c4bb9a..f2f6109ec45b 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitReceiveNetAttributesGetter.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitReceiveNetAttributesGetter.java @@ -22,14 +22,13 @@ public String transport(ReceiveRequest request, @Nullable GetResponse response) @Nullable @Override public String peerName(ReceiveRequest request, @Nullable GetResponse response) { - // not using InetAddress.getHostName() since that can trigger reverse name lookup - return request.getConnection().getAddress().getHostAddress(); + return null; } @Nullable @Override public Integer peerPort(ReceiveRequest request, @Nullable GetResponse response) { - return request.getConnection().getPort(); + return null; } @Nullable @@ -38,6 +37,18 @@ public String sockPeerAddr(ReceiveRequest request, @Nullable GetResponse respons return request.getConnection().getAddress().getHostAddress(); } + @Nullable + @Override + public String sockPeerName(ReceiveRequest request, @Nullable GetResponse response) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(ReceiveRequest request, @Nullable GetResponse response) { + return request.getConnection().getPort(); + } + @Nullable @Override public String sockFamily(ReceiveRequest request, @Nullable GetResponse response) { diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackHttpNetAttributesGetter.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackHttpNetAttributesGetter.java index 8d5cfb8674ea..25abcb9e0810 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackHttpNetAttributesGetter.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackHttpNetAttributesGetter.java @@ -17,6 +17,7 @@ */ public final class RatpackHttpNetAttributesGetter implements NetClientAttributesGetter { + @Override public String transport(RequestSpec request, @Nullable HttpResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; @@ -32,4 +33,28 @@ public String peerName(RequestSpec request, @Nullable HttpResponse response) { public Integer peerPort(RequestSpec request, @Nullable HttpResponse response) { return request.getUri().getPort(); } + + @Nullable + @Override + public String sockFamily(RequestSpec requestSpec, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(RequestSpec requestSpec, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerName(RequestSpec requestSpec, @Nullable HttpResponse httpResponse) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort(RequestSpec requestSpec, @Nullable HttpResponse httpResponse) { + return null; + } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesGetter.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesGetter.java index 4c24558fba46..5481b6cd52fa 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesGetter.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesGetter.java @@ -8,7 +8,9 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; +import ratpack.handling.Context; import ratpack.http.Request; +import ratpack.server.PublicAddress; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at @@ -20,14 +22,60 @@ public String transport(Request request) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable + @Override + public String hostName(Request request) { + PublicAddress publicAddress = getPublicAddress(request); + return publicAddress == null ? null : publicAddress.get().getHost(); + } + + @Nullable + @Override + public Integer hostPort(Request request) { + PublicAddress publicAddress = getPublicAddress(request); + return publicAddress == null ? null : publicAddress.get().getPort(); + } + + private static PublicAddress getPublicAddress(Request request) { + Context ratpackContext = request.get(Context.class); + if (ratpackContext == null) { + return null; + } + return ratpackContext.get(PublicAddress.class); + } + + @Nullable + @Override + public String sockFamily(Request request) { + return null; + } + + @Override + @Nullable + public String sockPeerAddr(Request request) { + return null; + } + @Override public Integer sockPeerPort(Request request) { return request.getRemoteAddress().getPort(); } + @Nullable + @Override + public String sockHostAddr(Request request) { + return null; + } + + @Nullable @Override + public String sockHostName(Request request) { + return null; + } + @Nullable - public String sockPeerAddr(Request request) { + @Override + public Integer sockHostPort(Request request) { return null; } } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyNetClientAttributesGetter.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyNetClientAttributesGetter.java index 067cc10feaa3..0ba5064c6a51 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyNetClientAttributesGetter.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyNetClientAttributesGetter.java @@ -8,6 +8,8 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.net.URI; +import java.net.URISyntaxException; import javax.annotation.Nullable; import reactor.netty.Connection; import reactor.netty.http.client.HttpClientConfig; @@ -24,7 +26,21 @@ public String transport(HttpClientConfig request, @Nullable HttpClientResponse r @Nullable @Override - public InetSocketAddress getAddress( + public String peerName(HttpClientConfig request, @Nullable HttpClientResponse response) { + URI parsedUri = parseUri(request); + return parsedUri == null ? null : parsedUri.getHost(); + } + + @Nullable + @Override + public Integer peerPort(HttpClientConfig request, @Nullable HttpClientResponse response) { + URI parsedUri = parseUri(request); + return parsedUri == null ? null : parsedUri.getPort(); + } + + @Nullable + @Override + public InetSocketAddress getPeerAddress( HttpClientConfig request, @Nullable HttpClientResponse response) { // we're making use of the fact that HttpClientOperations is both a Connection and an @@ -38,4 +54,21 @@ public InetSocketAddress getAddress( } return null; } + + private static URI parseUri(HttpClientConfig request) { + String baseUrl = request.baseUrl(); + String uri = request.uri(); + + URI parsedUri; + try { + if (baseUrl != null && uri.startsWith("/")) { + parsedUri = new URI(baseUrl); + } else { + parsedUri = new URI(uri); + } + } catch (URISyntaxException ignored) { + return null; + } + return parsedUri; + } } diff --git a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java index 0700622183e0..cf34f4458689 100644 --- a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java +++ b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java @@ -12,14 +12,26 @@ final class RedissonNetAttributesGetter extends InetSocketAddressNetClientAttributesGetter { + @Nullable @Override - public InetSocketAddress getAddress(RedissonRequest request, @Nullable Void unused) { - return request.getAddress(); + public String transport(RedissonRequest request, @Nullable Void unused) { + return null; } @Nullable @Override - public String transport(RedissonRequest request, @Nullable Void unused) { + public String peerName(RedissonRequest redissonRequest, @Nullable Void unused) { + return null; + } + + @Nullable + @Override + public Integer peerPort(RedissonRequest redissonRequest, @Nullable Void unused) { return null; } + + @Override + public InetSocketAddress getPeerAddress(RedissonRequest request, @Nullable Void unused) { + return request.getAddress(); + } } diff --git a/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletNetAttributesGetter.java b/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletNetAttributesGetter.java index e94f1c6d11e1..6e0fc4afd028 100644 --- a/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletNetAttributesGetter.java +++ b/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletNetAttributesGetter.java @@ -5,20 +5,38 @@ package io.opentelemetry.instrumentation.restlet.v1_0; +import com.noelios.restlet.http.HttpCall; +import com.noelios.restlet.http.HttpRequest; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; import org.restlet.data.Request; final class RestletNetAttributesGetter implements NetServerAttributesGetter { + @Override public String transport(Request request) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable @Override - public Integer sockPeerPort(Request request) { - return request.getClientInfo().getPort(); + public String hostName(Request request) { + HttpCall call = httpCall(request); + return call == null ? null : call.getHostDomain(); + } + + @Nullable + @Override + public Integer hostPort(Request request) { + HttpCall call = httpCall(request); + return call == null ? null : call.getServerPort(); + } + + @Nullable + @Override + public String sockFamily(Request request) { + return null; } @Override @@ -26,4 +44,36 @@ public Integer sockPeerPort(Request request) { public String sockPeerAddr(Request request) { return request.getClientInfo().getAddress(); } + + @Override + public Integer sockPeerPort(Request request) { + return request.getClientInfo().getPort(); + } + + @Nullable + @Override + public String sockHostAddr(Request request) { + HttpCall call = httpCall(request); + return call == null ? null : call.getServerAddress(); + } + + @Nullable + @Override + public String sockHostName(Request request) { + return null; + } + + @Nullable + @Override + public Integer sockHostPort(Request request) { + return null; + } + + @Nullable + private static HttpCall httpCall(Request request) { + if (request instanceof HttpRequest) { + return ((HttpRequest) request).getHttpCall(); + } + return null; + } } diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletNetAttributesGetter.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletNetAttributesGetter.java index d883e5e4df3a..f7b4b001ca00 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletNetAttributesGetter.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletNetAttributesGetter.java @@ -9,16 +9,34 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; import org.restlet.Request; +import org.restlet.engine.http.HttpRequest; +import org.restlet.engine.http.ServerCall; final class RestletNetAttributesGetter implements NetServerAttributesGetter { + @Override public String transport(Request request) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable @Override - public Integer sockPeerPort(Request request) { - return request.getClientInfo().getPort(); + public String hostName(Request request) { + ServerCall call = serverCall(request); + return call == null ? null : call.getHostDomain(); + } + + @Nullable + @Override + public Integer hostPort(Request request) { + ServerCall call = serverCall(request); + return call == null ? null : call.getServerPort(); + } + + @Nullable + @Override + public String sockFamily(Request request) { + return null; } @Override @@ -26,4 +44,36 @@ public Integer sockPeerPort(Request request) { public String sockPeerAddr(Request request) { return request.getClientInfo().getAddress(); } + + @Override + public Integer sockPeerPort(Request request) { + return request.getClientInfo().getPort(); + } + + @Nullable + @Override + public String sockHostAddr(Request request) { + ServerCall call = serverCall(request); + return call == null ? null : call.getServerAddress(); + } + + @Nullable + @Override + public String sockHostName(Request request) { + return null; + } + + @Nullable + @Override + public Integer sockHostPort(Request request) { + return null; + } + + @Nullable + private static ServerCall serverCall(Request request) { + if (request instanceof HttpRequest) { + return ((HttpRequest) request).getHttpCall(); + } + return null; + } } diff --git a/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2Accessor.java b/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2Accessor.java index 6325f265e1b5..3797738541eb 100644 --- a/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2Accessor.java +++ b/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2Accessor.java @@ -22,6 +22,21 @@ public Integer getRequestRemotePort(HttpServletRequest httpServletRequest) { return null; } + @Override + public String getRequestLocalName(HttpServletRequest request) { + return null; + } + + @Override + public String getRequestLocalAddr(HttpServletRequest request) { + return null; + } + + @Override + public Integer getRequestLocalPort(HttpServletRequest request) { + return null; + } + @Override public void addRequestAsyncListener( HttpServletRequest httpServletRequest, diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3Accessor.java b/instrumentation/servlet/servlet-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3Accessor.java index 68514bdc659a..0a0249723691 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3Accessor.java +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3Accessor.java @@ -26,6 +26,21 @@ public Integer getRequestRemotePort(HttpServletRequest request) { return request.getRemotePort(); } + @Override + public String getRequestLocalName(HttpServletRequest request) { + return request.getLocalName(); + } + + @Override + public String getRequestLocalAddr(HttpServletRequest request) { + return request.getLocalAddr(); + } + + @Override + public Integer getRequestLocalPort(HttpServletRequest request) { + return request.getLocalPort(); + } + @Override public void addRequestAsyncListener( HttpServletRequest request, diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/Servlet5Accessor.java b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/Servlet5Accessor.java index 7d56896c38a7..4d77ee603edc 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/Servlet5Accessor.java +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/Servlet5Accessor.java @@ -65,11 +65,41 @@ public String getRequestMethod(HttpServletRequest request) { return request.getMethod(); } + @Override + public String getRequestServerName(HttpServletRequest request) { + return request.getServerName(); + } + + @Override + public Integer getRequestServerPort(HttpServletRequest request) { + return request.getServerPort(); + } + @Override public String getRequestRemoteAddr(HttpServletRequest request) { return request.getRemoteAddr(); } + @Override + public Integer getRequestRemotePort(HttpServletRequest request) { + return request.getRemotePort(); + } + + @Override + public String getRequestLocalName(HttpServletRequest request) { + return request.getLocalName(); + } + + @Override + public String getRequestLocalAddr(HttpServletRequest request) { + return request.getLocalAddr(); + } + + @Override + public Integer getRequestLocalPort(HttpServletRequest request) { + return request.getLocalPort(); + } + @Override public String getRequestHeader(HttpServletRequest request, String name) { return request.getHeader(name); @@ -108,11 +138,6 @@ public Principal getRequestUserPrincipal(HttpServletRequest request) { return request.getUserPrincipal(); } - @Override - public Integer getRequestRemotePort(HttpServletRequest request) { - return request.getRemotePort(); - } - @Override public void addRequestAsyncListener( HttpServletRequest request, diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletAccessor.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletAccessor.java index 6d24c11fb321..394692171e99 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletAccessor.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletAccessor.java @@ -35,8 +35,20 @@ public interface ServletAccessor { String getRequestMethod(REQUEST request); + String getRequestServerName(REQUEST request); + + Integer getRequestServerPort(REQUEST request); + String getRequestRemoteAddr(REQUEST request); + Integer getRequestRemotePort(REQUEST request); + + String getRequestLocalName(REQUEST request); + + String getRequestLocalAddr(REQUEST request); + + Integer getRequestLocalPort(REQUEST request); + String getRequestHeader(REQUEST request, String name); List getRequestHeaderValues(REQUEST request, String name); @@ -51,8 +63,6 @@ public interface ServletAccessor { Principal getRequestUserPrincipal(REQUEST request); - Integer getRequestRemotePort(REQUEST request); - void addRequestAsyncListener( REQUEST request, ServletAsyncListener listener, Object response); diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesGetter.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesGetter.java index ec0ff1bbab1e..18721f06bc63 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesGetter.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesGetter.java @@ -11,6 +11,7 @@ public class ServletNetAttributesGetter implements NetServerAttributesGetter> { + private final ServletAccessor accessor; public ServletNetAttributesGetter(ServletAccessor accessor) { @@ -23,10 +24,22 @@ public String transport(ServletRequestContext requestContext) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable @Override + public String hostName(ServletRequestContext requestContext) { + return accessor.getRequestServerName(requestContext.request()); + } + @Nullable - public Integer sockPeerPort(ServletRequestContext requestContext) { - return accessor.getRequestRemotePort(requestContext.request()); + @Override + public Integer hostPort(ServletRequestContext requestContext) { + return accessor.getRequestServerPort(requestContext.request()); + } + + @Nullable + @Override + public String sockFamily(ServletRequestContext requestContext) { + return null; } @Override @@ -34,4 +47,28 @@ public Integer sockPeerPort(ServletRequestContext requestContext) { public String sockPeerAddr(ServletRequestContext requestContext) { return accessor.getRequestRemoteAddr(requestContext.request()); } + + @Override + @Nullable + public Integer sockPeerPort(ServletRequestContext requestContext) { + return accessor.getRequestRemotePort(requestContext.request()); + } + + @Nullable + @Override + public String sockHostAddr(ServletRequestContext requestContext) { + return accessor.getRequestLocalAddr(requestContext.request()); + } + + @Nullable + @Override + public String sockHostName(ServletRequestContext requestContext) { + return accessor.getRequestLocalName(requestContext.request()); + } + + @Nullable + @Override + public Integer sockHostPort(ServletRequestContext requestContext) { + return accessor.getRequestLocalPort(requestContext.request()); + } } diff --git a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/JavaxServletAccessor.java b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/JavaxServletAccessor.java index db1a6198092a..7a300c16313f 100644 --- a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/JavaxServletAccessor.java +++ b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/JavaxServletAccessor.java @@ -55,6 +55,16 @@ public String getRequestMethod(HttpServletRequest request) { return request.getMethod(); } + @Override + public String getRequestServerName(HttpServletRequest request) { + return request.getServerName(); + } + + @Override + public Integer getRequestServerPort(HttpServletRequest request) { + return request.getServerPort(); + } + @Override public String getRequestRemoteAddr(HttpServletRequest request) { return request.getRemoteAddr(); diff --git a/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebNetAttributesGetter.java b/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebNetAttributesGetter.java index 2996c93fbe13..4a59373d7a3f 100644 --- a/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebNetAttributesGetter.java +++ b/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebNetAttributesGetter.java @@ -13,6 +13,7 @@ final class SpringWebNetAttributesGetter implements NetClientAttributesGetter { + @Override public String transport(HttpRequest httpRequest, @Nullable ClientHttpResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; @@ -28,4 +29,32 @@ public String peerName(HttpRequest httpRequest, @Nullable ClientHttpResponse res public Integer peerPort(HttpRequest httpRequest, @Nullable ClientHttpResponse response) { return httpRequest.getURI().getPort(); } + + @Nullable + @Override + public String sockFamily( + HttpRequest httpRequest, @Nullable ClientHttpResponse clientHttpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr( + HttpRequest httpRequest, @Nullable ClientHttpResponse clientHttpResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerName( + HttpRequest httpRequest, @Nullable ClientHttpResponse clientHttpResponse) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort( + HttpRequest httpRequest, @Nullable ClientHttpResponse clientHttpResponse) { + return null; + } } diff --git a/instrumentation/spring/spring-webflux-5.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/internal/SpringWebfluxNetAttributesGetter.java b/instrumentation/spring/spring-webflux-5.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/internal/SpringWebfluxNetAttributesGetter.java index 090694ea317e..17f3ad559c78 100644 --- a/instrumentation/spring/spring-webflux-5.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/internal/SpringWebfluxNetAttributesGetter.java +++ b/instrumentation/spring/spring-webflux-5.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/internal/SpringWebfluxNetAttributesGetter.java @@ -33,4 +33,29 @@ public String peerName(ClientRequest request, @Nullable ClientResponse response) public Integer peerPort(ClientRequest request, @Nullable ClientResponse response) { return request.url().getPort(); } + + @Nullable + @Override + public String sockFamily(ClientRequest clientRequest, @Nullable ClientResponse clientResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerAddr(ClientRequest clientRequest, @Nullable ClientResponse clientResponse) { + return null; + } + + @Nullable + @Override + public String sockPeerName(ClientRequest clientRequest, @Nullable ClientResponse clientResponse) { + return null; + } + + @Nullable + @Override + public Integer sockPeerPort( + ClientRequest clientRequest, @Nullable ClientResponse clientResponse) { + return null; + } } diff --git a/instrumentation/spring/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java b/instrumentation/spring/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java index f961ab636a37..c1320f2301ea 100644 --- a/instrumentation/spring/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java +++ b/instrumentation/spring/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java @@ -18,9 +18,21 @@ public String transport(HttpServletRequest request) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable @Override - public Integer sockPeerPort(HttpServletRequest request) { - return request.getRemotePort(); + public String hostName(HttpServletRequest request) { + return request.getServerName(); + } + + @Override + public Integer hostPort(HttpServletRequest request) { + return request.getServerPort(); + } + + @Nullable + @Override + public String sockFamily(HttpServletRequest request) { + return null; } @Override @@ -28,4 +40,26 @@ public Integer sockPeerPort(HttpServletRequest request) { public String sockPeerAddr(HttpServletRequest request) { return request.getRemoteAddr(); } + + @Override + public Integer sockPeerPort(HttpServletRequest request) { + return request.getRemotePort(); + } + + @Nullable + @Override + public String sockHostAddr(HttpServletRequest request) { + return request.getLocalAddr(); + } + + @Nullable + @Override + public String sockHostName(HttpServletRequest request) { + return request.getLocalName(); + } + + @Override + public Integer sockHostPort(HttpServletRequest request) { + return request.getLocalPort(); + } } diff --git a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesGetter.java b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesGetter.java index 2573db0127bc..e950b66e836f 100644 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesGetter.java +++ b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesGetter.java @@ -19,11 +19,21 @@ public String transport(Request request) { return SemanticAttributes.NetTransportValues.IP_TCP; } + @Nullable + @Override + public String hostName(Request request) { + return request.serverName().toString(); + } + @Override + public Integer hostPort(Request request) { + return request.getServerPort(); + } + @Nullable - public Integer sockPeerPort(Request request) { - request.action(ActionCode.REQ_REMOTEPORT_ATTRIBUTE, request); - return request.getRemotePort(); + @Override + public String sockFamily(Request request) { + return null; } @Override @@ -32,4 +42,32 @@ public String sockPeerAddr(Request request) { request.action(ActionCode.REQ_HOST_ADDR_ATTRIBUTE, request); return request.remoteAddr().toString(); } + + @Override + @Nullable + public Integer sockPeerPort(Request request) { + request.action(ActionCode.REQ_REMOTEPORT_ATTRIBUTE, request); + return request.getRemotePort(); + } + + @Nullable + @Override + public String sockHostAddr(Request request) { + request.action(ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE, request); + return request.localAddr().toString(); + } + + @Nullable + @Override + public String sockHostName(Request request) { + request.action(ActionCode.REQ_LOCAL_NAME_ATTRIBUTE, request); + return request.localName().toString(); + } + + @Nullable + @Override + public Integer sockHostPort(Request request) { + request.action(ActionCode.REQ_LOCALPORT_ATTRIBUTE, request); + return request.getLocalPort(); + } } diff --git a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowNetAttributesGetter.java b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowNetAttributesGetter.java index f4fe5e4a61cf..19a4a12f8e96 100644 --- a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowNetAttributesGetter.java +++ b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowNetAttributesGetter.java @@ -15,13 +15,31 @@ public class UndertowNetAttributesGetter extends InetSocketAddressNetServerAttributesGetter { @Override + public String transport(HttpServerExchange exchange) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } + + @Nullable + @Override + public String hostName(HttpServerExchange exchange) { + return exchange.getHostName(); + } + @Nullable - public InetSocketAddress getAddress(HttpServerExchange exchange) { + @Override + public Integer hostPort(HttpServerExchange exchange) { + return exchange.getHostPort(); + } + + @Override + @Nullable + public InetSocketAddress getPeerAddress(HttpServerExchange exchange) { return exchange.getConnection().getPeerAddress(InetSocketAddress.class); } + @Nullable @Override - public String transport(HttpServerExchange exchange) { - return SemanticAttributes.NetTransportValues.IP_TCP; + public InetSocketAddress getHostAddress(HttpServerExchange exchange) { + return exchange.getConnection().getLocalAddress(InetSocketAddress.class); } } diff --git a/instrumentation/vertx/vertx-http-client/vertx-http-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client/Vertx4NetAttributesGetter.java b/instrumentation/vertx/vertx-http-client/vertx-http-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client/Vertx4NetAttributesGetter.java index b7b8154d9a3e..1973e7a25977 100644 --- a/instrumentation/vertx/vertx-http-client/vertx-http-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client/Vertx4NetAttributesGetter.java +++ b/instrumentation/vertx/vertx-http-client/vertx-http-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client/Vertx4NetAttributesGetter.java @@ -5,14 +5,16 @@ package io.opentelemetry.javaagent.instrumentation.vertx.v4_0.client; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.vertx.core.http.HttpClientRequest; import io.vertx.core.http.HttpClientResponse; +import io.vertx.core.net.SocketAddress; +import java.net.InetSocketAddress; import javax.annotation.Nullable; final class Vertx4NetAttributesGetter - implements NetClientAttributesGetter { + extends InetSocketAddressNetClientAttributesGetter { @Override public String transport(HttpClientRequest request, @Nullable HttpClientResponse response) { @@ -29,4 +31,18 @@ public String peerName(HttpClientRequest request, @Nullable HttpClientResponse r public Integer peerPort(HttpClientRequest request, @Nullable HttpClientResponse response) { return request.getPort(); } + + @Nullable + @Override + public InetSocketAddress getPeerAddress( + HttpClientRequest request, @Nullable HttpClientResponse response) { + if (response == null) { + return null; + } + SocketAddress address = response.netSocket().remoteAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } + return null; + } }