From f148592360c790e5610107df101da716d7653fd4 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Mon, 30 Oct 2023 15:35:36 +0100 Subject: [PATCH] Remove conditional requirement on network.peer.address and network.peer.port --- .../ForwardedHostAddressAndPortExtractor.java | 7 +++ .../HttpClientAttributesExtractorBuilder.java | 1 - .../HttpServerAttributesExtractorBuilder.java | 6 +-- .../http/HttpServerAttributesGetter.java | 29 +++++++++++ .../net/NetClientAttributesExtractor.java | 1 - .../net/NetServerAttributesExtractor.java | 1 - .../network/NetworkAttributesExtractor.java | 1 - .../network/ServerAttributesGetter.java | 2 - .../InternalNetworkAttributesExtractor.java | 10 ++-- ...wardedHostAddressAndPortExtractorTest.java | 16 ++++++ .../HttpServerAttributesExtractorTest.java | 33 ------------ .../net/NetClientAttributesExtractorTest.java | 30 ----------- .../net/NetServerAttributesExtractorTest.java | 30 ----------- ...verAttributesExtractorBothSemconvTest.java | 12 ----- ...tAttributesExtractorStableSemconvTest.java | 7 ++- ...rAttributesExtractorStableSemconvTest.java | 52 ++++++++++++------- .../AkkaHttpServerAttributesGetter.java | 13 ----- .../ArmeriaHttpServerAttributesGetter.java | 12 ----- .../grizzly/GrizzlyHttpAttributesGetter.java | 13 ----- .../v1_0/KtorHttpServerAttributesGetter.kt | 8 --- .../server/KtorHttpServerAttributesGetter.kt | 8 --- .../http/channel/HttpRequestMessage.java | 4 -- ...LibertyDispatcherHttpAttributesGetter.java | 11 ---- .../liberty/dispatcher/LibertyRequest.java | 4 -- .../NettyHttpServerAttributesGetter.java | 12 ----- .../NettyHttpServerAttributesGetter.java | 12 ----- .../MockHttpServerAttributesGetter.java | 12 ----- .../PekkoHttpServerAttributesGetter.java | 13 ----- .../v1_7/RatpackHttpAttributesGetter.java | 22 -------- .../v1_1/RestletHttpAttributesGetter.java | 14 ----- .../internal/RestletHttpAttributesGetter.java | 12 ----- .../v2_0/internal/ServerCallAccess.java | 41 --------------- .../servlet/v5_0/Servlet5Accessor.java | 10 ---- .../servlet/ServletAccessor.java | 4 -- .../servlet/ServletHttpAttributesGetter.java | 12 ----- .../servlet/javax/JavaxServletAccessor.java | 10 ---- .../WebfluxServerHttpAttributesGetter.java | 13 ----- .../SpringWebMvcHttpAttributesGetter.java | 11 ---- .../SpringWebMvcHttpAttributesGetter.java | 11 ---- .../common/TomcatHttpAttributesGetter.java | 11 ---- .../UndertowHttpAttributesGetter.java | 12 ----- .../testing/TestInstrumenters.java | 12 ----- 42 files changed, 95 insertions(+), 460 deletions(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedHostAddressAndPortExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedHostAddressAndPortExtractor.java index abb2d55eaa55..14bdf04b63b1 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedHostAddressAndPortExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedHostAddressAndPortExtractor.java @@ -42,6 +42,13 @@ public void extract(AddressPortSink sink, REQUEST request) { return; } } + + // try :authority (HTTP 2.0 pseudo-header) + for (String host : getter.getHttpRequestHeader(request, ":authority")) { + if (extractHost(sink, host, 0, host.length())) { + return; + } + } } private static boolean extractFromForwardedHeader(AddressPortSink sink, String forwarded) { diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java index 3e5bdde89b59..7b7969f52457 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java @@ -135,7 +135,6 @@ InternalNetClientAttributesExtractor buildNetExtractor() { InternalNetworkAttributesExtractor buildNetworkExtractor() { return new InternalNetworkAttributesExtractor<>( netAttributesGetter, - AddressAndPortExtractor.noop(), serverAddressAndPortExtractor, /* captureNetworkTransportAndType= */ false, /* captureLocalSocketAttributes= */ false, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java index bcf3c40c7075..c16834e69e4a 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java @@ -16,7 +16,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.InternalUrlAttributesExtractor; import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.SemconvStability; @@ -55,9 +54,7 @@ public final class HttpServerAttributesExtractorBuilder { clientAddressPortExtractor = new ClientAddressAndPortExtractor<>( netAttributesGetter, new ForwardedForAddressAndPortExtractor<>(httpAttributesGetter)); - serverAddressPortExtractor = - new ServerAddressAndPortExtractor<>( - netAttributesGetter, new ForwardedHostAddressAndPortExtractor<>(httpAttributesGetter)); + serverAddressPortExtractor = new ForwardedHostAddressAndPortExtractor<>(httpAttributesGetter); } /** @@ -151,7 +148,6 @@ InternalNetServerAttributesExtractor buildNetExtractor() { InternalNetworkAttributesExtractor buildNetworkExtractor() { return new InternalNetworkAttributesExtractor<>( netAttributesGetter, - serverAddressPortExtractor, clientAddressPortExtractor, /* captureNetworkTransportAndType= */ false, /* captureLocalSocketAttributes= */ false, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesGetter.java index 5837a493e157..c77e21b45f8c 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesGetter.java @@ -27,6 +27,7 @@ public interface HttpServerAttributesGetter io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter< REQUEST, RESPONSE>, NetworkAttributesGetter, + // TODO remove ServerAttributesGetter from here ServerAttributesGetter, ClientAttributesGetter { @@ -55,4 +56,32 @@ public interface HttpServerAttributesGetter default String getHttpRoute(REQUEST request) { return null; } + + /** + * Returns the name of the local HTTP server that received the request. + * + * @deprecated This method is deprecated and will be removed without replacement. The {@link + * HttpServerAttributesExtractor} now extracts the server address and port from the received + * HTTP request's headers. + */ + @Deprecated + @Nullable + @Override + default String getServerAddress(REQUEST request) { + return null; + } + + /** + * Returns the port of the local HTTP server that received the request. + * + * @deprecated This method is deprecated and will be removed without replacement. The {@link + * HttpServerAttributesExtractor} now extracts the server address and port from the received + * HTTP request's headers. + */ + @Deprecated + @Nullable + @Override + default Integer getServerPort(REQUEST request) { + return null; + } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java index 5e9458ece162..aaf6d1f531ad 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java @@ -50,7 +50,6 @@ private NetClientAttributesExtractor(NetClientAttributesGetter( getter, - AddressAndPortExtractor.noop(), serverAddressAndPortExtractor, /* captureNetworkTransportAndType= */ true, /* captureLocalSocketAttributes= */ false, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java index 67493be7ed77..dae29c4b33dc 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java @@ -52,7 +52,6 @@ private NetServerAttributesExtractor(NetServerAttributesGetter( getter, - serverAddressAndPortExtractor, clientAddressAndPortExtractor, /* captureNetworkTransportAndType= */ true, /* captureLocalSocketAttributes= */ true, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java index 89ea385b8b34..e232a8db1067 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java @@ -37,7 +37,6 @@ public static NetworkAttributesExtractor new InternalNetworkAttributesExtractor<>( getter, AddressAndPortExtractor.noop(), - AddressAndPortExtractor.noop(), /* captureNetworkTransportAndType= */ true, /* captureLocalSocketAttributes= */ true, // capture the old net.sock.peer.name attr for backwards compatibility diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesGetter.java index 18b777e469a6..fefc9c630101 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesGetter.java @@ -39,8 +39,6 @@ default Integer getServerPort(REQUEST request) { return null; } - // TODO deprecate - /** * Returns an {@link InetSocketAddress} object representing the server socket address. * diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java index f2529cbe7a0d..6ebadd2657d5 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java @@ -22,7 +22,6 @@ public final class InternalNetworkAttributesExtractor { private final NetworkAttributesGetter getter; - private final AddressAndPortExtractor logicalLocalAddressAndPortExtractor; private final AddressAndPortExtractor logicalPeerAddressAndPortExtractor; private final boolean captureNetworkTransportAndType; private final boolean captureLocalSocketAttributes; @@ -32,7 +31,6 @@ public final class InternalNetworkAttributesExtractor { public InternalNetworkAttributesExtractor( NetworkAttributesGetter getter, - AddressAndPortExtractor logicalLocalAddressAndPortExtractor, AddressAndPortExtractor logicalPeerAddressAndPortExtractor, boolean captureNetworkTransportAndType, boolean captureLocalSocketAttributes, @@ -40,7 +38,6 @@ public InternalNetworkAttributesExtractor( boolean emitStableUrlAttributes, boolean emitOldHttpAttributes) { this.getter = getter; - this.logicalLocalAddressAndPortExtractor = logicalLocalAddressAndPortExtractor; this.logicalPeerAddressAndPortExtractor = logicalPeerAddressAndPortExtractor; this.captureNetworkTransportAndType = captureNetworkTransportAndType; this.captureLocalSocketAttributes = captureLocalSocketAttributes; @@ -74,8 +71,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO } String localAddress = getter.getNetworkLocalAddress(request, response); - String logicalLocalAddress = logicalLocalAddressAndPortExtractor.extract(request).address; - if (localAddress != null && !localAddress.equals(logicalLocalAddress)) { + if (localAddress != null) { if (emitStableUrlAttributes && captureLocalSocketAttributes) { internalSet(attributes, NetworkAttributes.NETWORK_LOCAL_ADDRESS, localAddress); } @@ -95,8 +91,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO } String peerAddress = getter.getNetworkPeerAddress(request, response); - String logicalPeerAddress = logicalPeerAddressAndPortExtractor.extract(request).address; - if (peerAddress != null && !peerAddress.equals(logicalPeerAddress)) { + if (peerAddress != null) { if (emitStableUrlAttributes) { internalSet(attributes, NetworkAttributes.NETWORK_PEER_ADDRESS, peerAddress); } @@ -119,6 +114,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO getter.getNetworkPeerInetSocketAddress(request, response); if (peerSocketAddress != null) { String peerSocketDomain = InetSocketAddressUtil.getDomainName(peerSocketAddress); + String logicalPeerAddress = logicalPeerAddressAndPortExtractor.extract(request).address; if (peerSocketDomain != null && !peerSocketDomain.equals(logicalPeerAddress)) { internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_NAME, peerSocketDomain); } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedHostAddressAndPortExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedHostAddressAndPortExtractorTest.java index ea60836c427f..51b2d5df8bd9 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedHostAddressAndPortExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedHostAddressAndPortExtractorTest.java @@ -109,6 +109,22 @@ void shouldParseHost( assertThat(sink.getPort()).isEqualTo(expectedPort); } + @ParameterizedTest + @ArgumentsSource(HostArgs.class) + void shouldParsePseudoAuthority( + List headers, @Nullable String expectedAddress, @Nullable Integer expectedPort) { + doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "forwarded"); + doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "x-forwarded-host"); + doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "host"); + doReturn(headers).when(getter).getHttpRequestHeader(REQUEST, ":authority"); + + AddressAndPort sink = new AddressAndPort(); + underTest.extract(sink, REQUEST); + + assertThat(sink.getAddress()).isEqualTo(expectedAddress); + assertThat(sink.getPort()).isEqualTo(expectedPort); + } + static final class HostArgs implements ArgumentsProvider { @Override diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java index 132144e86cba..2335c59323f5 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java @@ -111,18 +111,6 @@ public String getNetworkProtocolVersion( Map request, Map response) { return (String) request.get("protocolVersion"); } - - @Nullable - @Override - public String getServerAddress(Map request) { - return (String) request.get("serverAddress"); - } - - @Nullable - @Override - public Integer getServerPort(Map request) { - return (Integer) request.get("serverPort"); - } } @Test @@ -247,27 +235,6 @@ void extractNetHostAndPortFromHostHeader() { entry(SemanticAttributes.NET_HOST_PORT, 777L)); } - @Test - void extractNetHostAndPortFromNetAttributesGetter() { - Map request = new HashMap<>(); - request.put("header.host", "notthehost:77777"); // this should have lower precedence - request.put("serverAddress", "thehost"); - request.put("serverPort", 777); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) - .setCapturedRequestHeaders(emptyList()) - .setCapturedResponseHeaders(emptyList()) - .build(); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - assertThat(attributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_HOST_NAME, "thehost"), - entry(SemanticAttributes.NET_HOST_PORT, 777L)); - } - @ParameterizedTest @ArgumentsSource(DefaultHostPortArgumentSource.class) void defaultHostPort(int hostPort, String scheme) { diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java index 79fbf5bdec9d..1a4d66015da0 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java @@ -147,36 +147,6 @@ void empty() { assertThat(endAttributes.build()).isEmpty(); } - @Test - void doesNotSetDuplicateSocketAddress() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("peerName", "1:2:3:4::"); - map.put("peerPort", "42"); - map.put("sockFamily", "inet6"); - map.put("sockPeerAddr", "1:2:3:4::"); - map.put("sockPeerName", "proxy.opentelemetry.io"); - map.put("sockPeerPort", "123"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); - - // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_PEER_NAME, "1:2:3:4::"), - entry(SemanticAttributes.NET_PEER_PORT, 42L)); - - assertThat(endAttributes.build()).containsOnly(entry(SemanticAttributes.NET_TRANSPORT, IP_TCP)); - } - @Test void doesNotSetNegativePortValues() { // given diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java index ac332991027c..498e046b9160 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java @@ -163,36 +163,6 @@ void empty() { assertThat(endAttributes.build()).isEmpty(); } - @Test - void doesNotSetDuplicatesSocketAddress() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("hostName", "4:3:2:1::"); - map.put("hostPort", "80"); - map.put("sockFamily", "inet6"); - map.put("sockHostAddr", "4:3:2:1::"); - map.put("sockHostPort", "8080"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, null, null); - - // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), - entry(SemanticAttributes.NET_HOST_NAME, "4:3:2:1::"), - entry(SemanticAttributes.NET_HOST_PORT, 80L)); - - assertThat(endAttributes.build()).isEmpty(); - } - @Test void doesNotSetNegativePort() { // given diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java index d3646575b785..99f6b8d93175 100644 --- a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java +++ b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java @@ -103,18 +103,6 @@ public String getNetworkProtocolVersion( Map request, Map response) { return (String) request.get("protocolVersion"); } - - @Nullable - @Override - public String getServerAddress(Map request) { - return (String) request.get("serverAddress"); - } - - @Nullable - @Override - public Integer getServerPort(Map request) { - return (Integer) request.get("serverPort"); - } } @Test diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java index 60c4d7f6187d..98acc5d207fd 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java @@ -372,7 +372,7 @@ void shouldExtractServerAddressAndPortFromHostHeader() { } @Test - void shouldNotExtractDuplicatePeerAddress() { + void shouldExtractPeerAddressEvenIfItDuplicatesServerAddress() { Map request = new HashMap<>(); request.put("networkPeerAddress", "1.2.3.4"); request.put("networkPeerPort", "456"); @@ -395,6 +395,9 @@ void shouldNotExtractDuplicatePeerAddress() { AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, response, null); assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + .containsOnly( + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java index e3e70429fefa..096d0e32f0a4 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java @@ -143,19 +143,6 @@ public Integer getNetworkPeerPort( return value == null ? null : Integer.parseInt(value); } - @Nullable - @Override - public String getServerAddress(Map request) { - return request.get("serverAddress"); - } - - @Nullable - @Override - public Integer getServerPort(Map request) { - String value = request.get("serverPort"); - return value == null ? null : Integer.parseInt(value); - } - @Nullable @Override public String getErrorType( @@ -177,7 +164,7 @@ void normal() { request.put("header.content-length", "10"); request.put("route", "/repositories/{id}"); request.put("header.user-agent", "okhttp 3.x"); - request.put("header.host", "www.github.com:456"); + request.put("header.host", "github.com:123"); request.put("header.forwarded", "for=1.1.1.1;proto=https"); request.put("header.custom-request-header", "123,456"); request.put("networkTransport", "udp"); @@ -188,8 +175,6 @@ void normal() { request.put("networkLocalPort", "42"); request.put("networkPeerAddress", "4.3.2.1"); request.put("networkPeerPort", "456"); - request.put("serverAddress", "github.com"); - request.put("serverPort", "123"); Map response = new HashMap<>(); response.put("statusCode", "202"); @@ -419,6 +404,7 @@ void shouldExtractServerAddressAndPortFromForwardedHeader() { request.put("header.forwarded", "host=example.com:42"); request.put("header.x-forwarded-host", "opentelemetry.io:987"); request.put("header.host", "github.com:123"); + request.put("header.:authority", "opentelemetry.io:42"); Map response = new HashMap<>(); response.put("statusCode", "200"); @@ -445,6 +431,7 @@ void shouldExtractServerAddressAndPortFromForwardedHostHeader() { Map request = new HashMap<>(); request.put("header.x-forwarded-host", "opentelemetry.io:987"); request.put("header.host", "github.com:123"); + request.put("header.:authority", "opentelemetry.io:42"); Map response = new HashMap<>(); response.put("statusCode", "200"); @@ -470,6 +457,7 @@ void shouldExtractServerAddressAndPortFromForwardedHostHeader() { void shouldExtractServerAddressAndPortFromHostHeader() { Map request = new HashMap<>(); request.put("header.host", "github.com:123"); + request.put("header.:authority", "opentelemetry.io:42"); Map response = new HashMap<>(); response.put("statusCode", "200"); @@ -492,7 +480,32 @@ void shouldExtractServerAddressAndPortFromHostHeader() { } @Test - void shouldNotExtractDuplicatePeerAddress() { + void shouldExtractServerAddressAndPortFromAuthorityPseudoHeader() { + Map request = new HashMap<>(); + request.put("header.:authority", "opentelemetry.io:42"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), + entry(SemanticAttributes.SERVER_PORT, 42L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + } + + @Test + void shouldExtractPeerAddressEvenIfItDuplicatesClientAddress() { Map request = new HashMap<>(); request.put("networkPeerAddress", "1.2.3.4"); request.put("networkPeerPort", "456"); @@ -514,6 +527,9 @@ void shouldNotExtractDuplicatePeerAddress() { AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, response, null); assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + .containsOnly( + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); } } diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerAttributesGetter.java b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerAttributesGetter.java index 94d1e5f910db..be4c2d8989ad 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerAttributesGetter.java +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerAttributesGetter.java @@ -7,7 +7,6 @@ import akka.http.scaladsl.model.HttpRequest; import akka.http.scaladsl.model.HttpResponse; -import akka.http.scaladsl.model.Uri; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; import io.opentelemetry.javaagent.instrumentation.akkahttp.AkkaHttpUtil; import java.util.List; @@ -68,16 +67,4 @@ public String getNetworkProtocolVersion( HttpRequest request, @Nullable HttpResponse httpResponse) { return AkkaHttpUtil.protocolVersion(request); } - - @Nullable - @Override - public String getServerAddress(HttpRequest request) { - Uri.Host host = request.uri().authority().host(); - return host.isEmpty() ? null : host.address(); - } - - @Override - public Integer getServerPort(HttpRequest request) { - return request.uri().authority().port(); - } } diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java index 9de2e6ea50ef..d9fe4ec1af43 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java @@ -89,18 +89,6 @@ public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog return protocol.isMultiplex() ? "2" : "1.1"; } - @Nullable - @Override - public String getServerAddress(RequestContext ctx) { - return null; - } - - @Nullable - @Override - public Integer getServerPort(RequestContext ctx) { - return null; - } - @Override @Nullable public InetSocketAddress getNetworkPeerInetSocketAddress( diff --git a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyHttpAttributesGetter.java b/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyHttpAttributesGetter.java index 827d357bc70d..328627a03ac2 100644 --- a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyHttpAttributesGetter.java +++ b/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyHttpAttributesGetter.java @@ -117,19 +117,6 @@ public String getNetworkProtocolVersion( return null; } - @Nullable - @Override - public String getServerAddress(HttpRequestPacket request) { - // rely on the 'host' header parsing - return null; - } - - @Override - public Integer getServerPort(HttpRequestPacket request) { - // rely on the 'host' header parsing - return null; - } - @Nullable @Override public String getNetworkPeerAddress( diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerAttributesGetter.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerAttributesGetter.kt index a9f1c533869c..46cb4e3e88ff 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerAttributesGetter.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerAttributesGetter.kt @@ -56,12 +56,4 @@ internal enum class KtorHttpServerAttributesGetter : } return null } - - override fun getServerAddress(request: ApplicationRequest): String { - return request.local.host - } - - override fun getServerPort(request: ApplicationRequest): Int { - return request.local.port - } } diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerAttributesGetter.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerAttributesGetter.kt index 4caa85d0ad30..ce6b4420c29b 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerAttributesGetter.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerAttributesGetter.kt @@ -49,14 +49,6 @@ internal enum class KtorHttpServerAttributesGetter : override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null - override fun getServerAddress(request: ApplicationRequest): String { - return request.local.host - } - - override fun getServerPort(request: ApplicationRequest): Int { - return request.local.port - } - override fun getNetworkPeerAddress(request: ApplicationRequest, response: ApplicationResponse?): String? { val remote = request.local.remoteHost if ("unknown" != remote && isIpAddress(remote)) { 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 34984b225a3a..25163026b1d5 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 @@ -27,8 +27,4 @@ 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/LibertyDispatcherHttpAttributesGetter.java b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherHttpAttributesGetter.java index 176c7ca65a06..e039fa341549 100644 --- a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherHttpAttributesGetter.java +++ b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherHttpAttributesGetter.java @@ -76,17 +76,6 @@ public String getNetworkProtocolVersion( return null; } - @Nullable - @Override - public String getServerAddress(LibertyRequest request) { - return request.request().getURLHost(); - } - - @Override - public Integer getServerPort(LibertyRequest request) { - return request.request().getURLPort(); - } - @Override @Nullable public String getNetworkPeerAddress(LibertyRequest request, @Nullable LibertyResponse response) { 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 fbce488b16b8..4f6020a7dd25 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 @@ -91,8 +91,4 @@ public String getClientSocketAddress() { public int getClientSocketPort() { return clientSocketPort; } - - public HttpRequestMessage request() { - return httpRequestMessage; - } } diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyHttpServerAttributesGetter.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyHttpServerAttributesGetter.java index a71425be582d..aa2877da6566 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyHttpServerAttributesGetter.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyHttpServerAttributesGetter.java @@ -91,18 +91,6 @@ public String getNetworkProtocolVersion( return version.getMajorVersion() + "." + version.getMinorVersion(); } - @Nullable - @Override - public String getServerAddress(HttpRequestAndChannel requestAndChannel) { - return null; - } - - @Nullable - @Override - public Integer getServerPort(HttpRequestAndChannel requestAndChannel) { - return null; - } - @Override @Nullable public InetSocketAddress getNetworkPeerInetSocketAddress( diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyHttpServerAttributesGetter.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyHttpServerAttributesGetter.java index b9fde47717d6..4d9577e36e9d 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyHttpServerAttributesGetter.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyHttpServerAttributesGetter.java @@ -91,18 +91,6 @@ public String getNetworkProtocolVersion( return version.majorVersion() + "." + version.minorVersion(); } - @Nullable - @Override - public String getServerAddress(HttpRequestAndChannel requestAndChannel) { - return null; - } - - @Nullable - @Override - public Integer getServerPort(HttpRequestAndChannel requestAndChannel) { - return null; - } - @Override @Nullable public InetSocketAddress getNetworkPeerInetSocketAddress( diff --git a/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockHttpServerAttributesGetter.java b/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockHttpServerAttributesGetter.java index 11b2346eddc0..4718afd97d8d 100644 --- a/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockHttpServerAttributesGetter.java +++ b/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockHttpServerAttributesGetter.java @@ -54,16 +54,4 @@ public String getUrlPath(String s) { public String getUrlQuery(String s) { return null; } - - @Nullable - @Override - public String getServerAddress(String s) { - return null; - } - - @Nullable - @Override - public Integer getServerPort(String s) { - return null; - } } diff --git a/instrumentation/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/PekkoHttpServerAttributesGetter.java b/instrumentation/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/PekkoHttpServerAttributesGetter.java index d81e145aeb5f..34a4167815b2 100644 --- a/instrumentation/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/PekkoHttpServerAttributesGetter.java +++ b/instrumentation/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/PekkoHttpServerAttributesGetter.java @@ -11,7 +11,6 @@ import javax.annotation.Nullable; import org.apache.pekko.http.scaladsl.model.HttpRequest; import org.apache.pekko.http.scaladsl.model.HttpResponse; -import org.apache.pekko.http.scaladsl.model.Uri; import scala.Option; class PekkoHttpServerAttributesGetter @@ -68,16 +67,4 @@ public String getNetworkProtocolVersion( HttpRequest request, @Nullable HttpResponse httpResponse) { return PekkoHttpUtil.protocolVersion(request); } - - @Nullable - @Override - public String getServerAddress(HttpRequest request) { - Uri.Host host = request.uri().authority().host(); - return host.isEmpty() ? null : host.address(); - } - - @Override - public Integer getServerPort(HttpRequest request) { - return request.uri().authority().port(); - } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpAttributesGetter.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpAttributesGetter.java index 7581db23cbf6..553a07142737 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpAttributesGetter.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpAttributesGetter.java @@ -83,28 +83,6 @@ public String getNetworkProtocolVersion(Request request, @Nullable Response resp return null; } - @Nullable - @Override - public String getServerAddress(Request request) { - PublicAddress publicAddress = getPublicAddress(request); - return publicAddress == null ? null : publicAddress.get().getHost(); - } - - @Nullable - @Override - public Integer getServerPort(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); - } - @Override public Integer getNetworkPeerPort(Request request, @Nullable Response response) { return request.getRemoteAddress().getPort(); diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java index 48fa6bee0692..9ba45c4681e4 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java @@ -106,20 +106,6 @@ private static String getProtocolString(Request request) { return (String) request.getAttributes().get("org.restlet.http.version"); } - @Nullable - @Override - public String getServerAddress(Request request) { - HttpCall call = httpCall(request); - return call == null ? null : call.getHostDomain(); - } - - @Nullable - @Override - public Integer getServerPort(Request request) { - HttpCall call = httpCall(request); - return call == null ? null : call.getServerPort(); - } - @Override @Nullable public String getNetworkPeerAddress(Request request, @Nullable Response response) { diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletHttpAttributesGetter.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletHttpAttributesGetter.java index 008b0bdc04da..aea6c1275202 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletHttpAttributesGetter.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletHttpAttributesGetter.java @@ -82,18 +82,6 @@ public String getNetworkProtocolVersion(Request request, @Nullable Response resp return request.getProtocol().getVersion(); } - @Nullable - @Override - public String getServerAddress(Request request) { - return ServerCallAccess.getHostDomain(request); - } - - @Nullable - @Override - public Integer getServerPort(Request request) { - return ServerCallAccess.getServerPort(request); - } - @Override @Nullable public String getNetworkPeerAddress(Request request, @Nullable Response response) { diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/ServerCallAccess.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/ServerCallAccess.java index 719e07ec2c39..61a0aada1463 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/ServerCallAccess.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/ServerCallAccess.java @@ -16,16 +16,12 @@ final class ServerCallAccess { private static final Class HTTP_REQUEST_CLASS; private static final MethodHandle GET_HTTP_CALL; - private static final MethodHandle GET_HOST_DOMAIN; - private static final MethodHandle GET_SERVER_PORT; private static final MethodHandle GET_SERVER_ADDRESS; static { Class httpRequestClass = null; Class serverCallClass = null; MethodHandle getHttpCall = null; - MethodHandle getHostDomain = null; - MethodHandle getServerPort = null; MethodHandle getServerAddress = null; try { @@ -55,9 +51,6 @@ final class ServerCallAccess { MethodHandles.Lookup lookup = MethodHandles.publicLookup(); getHttpCall = lookup.findVirtual(httpRequestClass, "getHttpCall", methodType(serverCallClass)); - getHostDomain = - lookup.findVirtual(serverCallClass, "getHostDomain", methodType(String.class)); - getServerPort = lookup.findVirtual(serverCallClass, "getServerPort", methodType(int.class)); getServerAddress = lookup.findVirtual(serverCallClass, "getServerAddress", methodType(String.class)); } catch (NoSuchMethodException | IllegalAccessException e) { @@ -67,43 +60,9 @@ final class ServerCallAccess { HTTP_REQUEST_CLASS = httpRequestClass; GET_HTTP_CALL = getHttpCall; - GET_HOST_DOMAIN = getHostDomain; - GET_SERVER_PORT = getServerPort; GET_SERVER_ADDRESS = getServerAddress; } - @Nullable - static String getHostDomain(Request request) { - if (GET_HOST_DOMAIN == null) { - return null; - } - Object call = serverCall(request); - if (call == null) { - return null; - } - try { - return (String) GET_HOST_DOMAIN.invoke(call); - } catch (Throwable e) { - return null; - } - } - - @Nullable - static Integer getServerPort(Request request) { - if (GET_SERVER_PORT == null) { - return null; - } - Object call = serverCall(request); - if (call == null) { - return null; - } - try { - return (int) GET_SERVER_PORT.invoke(call); - } catch (Throwable e) { - return null; - } - } - @Nullable static String getServerAddress(Request request) { if (GET_SERVER_ADDRESS == null) { 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 b05d37c24b03..2a22a9ecf2c6 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 @@ -68,16 +68,6 @@ 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/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 1b1f49b8e0c9..2504da6d4bf3 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,10 +35,6 @@ public interface ServletAccessor { String getRequestMethod(REQUEST request); - String getRequestServerName(REQUEST request); - - Integer getRequestServerPort(REQUEST request); - String getRequestRemoteAddr(REQUEST request); Integer getRequestRemotePort(REQUEST request); diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletHttpAttributesGetter.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletHttpAttributesGetter.java index e25f7c2af2f9..6f270762a42a 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletHttpAttributesGetter.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletHttpAttributesGetter.java @@ -106,18 +106,6 @@ public String getNetworkProtocolVersion( return null; } - @Nullable - @Override - public String getServerAddress(ServletRequestContext requestContext) { - return accessor.getRequestServerName(requestContext.request()); - } - - @Nullable - @Override - public Integer getServerPort(ServletRequestContext requestContext) { - return accessor.getRequestServerPort(requestContext.request()); - } - @Override @Nullable public String getNetworkPeerAddress( 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 7a300c16313f..db1a6198092a 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,16 +55,6 @@ 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-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerHttpAttributesGetter.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerHttpAttributesGetter.java index dcc78750dc49..a62d1da7b27e 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerHttpAttributesGetter.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerHttpAttributesGetter.java @@ -79,19 +79,6 @@ public String getHttpRoute(ServerWebExchange request) { return contextPath + (route.startsWith("/") ? route : ("/" + route)); } - @Nullable - @Override - public String getServerAddress(ServerWebExchange request) { - return request.getRequest().getURI().getHost(); - } - - @Nullable - @Override - public Integer getServerPort(ServerWebExchange request) { - int port = request.getRequest().getURI().getPort(); - return port == -1 ? null : port; - } - @Nullable @Override public InetSocketAddress getNetworkPeerInetSocketAddress( diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcHttpAttributesGetter.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcHttpAttributesGetter.java index 9853a0fb446a..f305e0b90d60 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcHttpAttributesGetter.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcHttpAttributesGetter.java @@ -103,17 +103,6 @@ public String getNetworkProtocolVersion( return null; } - @Nullable - @Override - public String getServerAddress(HttpServletRequest request) { - return request.getServerName(); - } - - @Override - public Integer getServerPort(HttpServletRequest request) { - return request.getServerPort(); - } - @Override @Nullable public String getNetworkPeerAddress( diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcHttpAttributesGetter.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcHttpAttributesGetter.java index 238769e13ad9..2a8ec7adf215 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcHttpAttributesGetter.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcHttpAttributesGetter.java @@ -103,17 +103,6 @@ public String getNetworkProtocolVersion( return null; } - @Nullable - @Override - public String getServerAddress(HttpServletRequest request) { - return request.getServerName(); - } - - @Override - public Integer getServerPort(HttpServletRequest request) { - return request.getServerPort(); - } - @Override @Nullable public String getNetworkPeerAddress( diff --git a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatHttpAttributesGetter.java b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatHttpAttributesGetter.java index ff1e261ebebe..6385e584c91a 100644 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatHttpAttributesGetter.java +++ b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatHttpAttributesGetter.java @@ -79,17 +79,6 @@ public String getNetworkProtocolVersion(Request request, @Nullable Response resp return null; } - @Nullable - @Override - public String getServerAddress(Request request) { - return messageBytesToString(request.serverName()); - } - - @Override - public Integer getServerPort(Request request) { - return request.getServerPort(); - } - @Override @Nullable public String getNetworkPeerAddress(Request request, @Nullable Response response) { diff --git a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowHttpAttributesGetter.java b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowHttpAttributesGetter.java index 139e2f591244..6c833bb65ef5 100644 --- a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowHttpAttributesGetter.java +++ b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowHttpAttributesGetter.java @@ -83,18 +83,6 @@ public String getNetworkProtocolVersion( return null; } - @Nullable - @Override - public String getServerAddress(HttpServerExchange exchange) { - return exchange.getHostName(); - } - - @Nullable - @Override - public Integer getServerPort(HttpServerExchange exchange) { - return exchange.getHostPort(); - } - @Override @Nullable public InetSocketAddress getNetworkPeerInetSocketAddress( diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java index a8d3a9cfc4e5..b8f16ceaa1bf 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java @@ -177,17 +177,5 @@ public String getUrlPath(String s) { public String getUrlQuery(String s) { return null; } - - @Nullable - @Override - public String getServerAddress(String unused) { - return null; - } - - @Nullable - @Override - public Integer getServerPort(String unused) { - return null; - } } }