From 27faf8f5b79551cb958a35f23b73c6eb80e248f9 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Wed, 2 Aug 2023 17:52:44 +0200 Subject: [PATCH] Make `HttpServerAttributesGetter` extend `NetServerAttributesGetter` (#9088) --- .../http/HttpServerAttributesExtractor.java | 27 +++++ .../http/HttpServerAttributesGetter.java | 11 +- .../HttpServerAttributesExtractorTest.java | 26 ++--- ...verAttributesExtractorBothSemconvTest.java | 8 +- ...rAttributesExtractorStableSemconvTest.java | 26 ++--- .../AkkaHttpServerAttributesGetter.java | 26 +++++ .../server/AkkaHttpServerSingletons.java | 3 +- .../server/AkkaNetServerAttributesGetter.java | 42 ------- .../ArmeriaHttpServerAttributesGetter.java | 40 +++++++ .../ArmeriaNetServerAttributesGetter.java | 55 --------- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 3 +- .../grizzly/GrizzlyHttpAttributesGetter.java | 91 +++++++++++++++ .../grizzly/GrizzlyNetAttributesGetter.java | 107 ------------------ .../grizzly/GrizzlySingletons.java | 3 +- .../v1_0/KtorHttpServerAttributesGetter.kt | 23 ++++ .../v1_0/KtorNetServerAttributesGetter.kt | 36 ------ .../ktor/v1_0/KtorServerTracing.kt | 5 +- .../server/KtorHttpServerAttributesGetter.kt | 23 ++++ .../server/KtorNetServerAttributesGetter.kt | 36 ------ .../ktor/v2_0/server/KtorServerTracing.kt | 5 +- ...LibertyDispatcherHttpAttributesGetter.java | 56 +++++++++ .../LibertyDispatcherNetAttributesGetter.java | 69 ----------- .../LibertyDispatcherSingletons.java | 4 +- .../NettyHttpServerAttributesGetter.java | 66 +++++++++++ .../NettyNetServerAttributesGetter.java | 81 ------------- .../v3_8/server/NettyServerSingletons.java | 3 +- .../NettyHttpServerAttributesGetter.java | 66 +++++++++++ .../NettyNetServerAttributesGetter.java | 81 ------------- .../NettyServerInstrumenterFactory.java | 3 +- .../testing/AgentSpanTestingInstrumenter.java | 3 +- .../MockHttpServerAttributesGetter.java | 12 ++ .../MockNetServerAttributesGetter.java | 26 ----- .../v1_7/RatpackHttpAttributesGetter.java | 47 ++++++++ .../ratpack/v1_7/RatpackTelemetryBuilder.java | 4 +- .../RatpackNetServerAttributesGetter.java | 68 ----------- .../v1_1/RestletHttpAttributesGetter.java | 66 +++++++++++ .../v1_1/RestletNetAttributesGetter.java | 80 ------------- .../restlet/v1_1/RestletTelemetryBuilder.java | 3 +- .../restlet/v2_0/RestletSingletons.java | 4 +- .../restlet/v2_0/RestletTelemetryBuilder.java | 4 +- .../internal/RestletHttpAttributesGetter.java | 41 +++++++ ...butesGetter.java => ServerCallAccess.java} | 43 +------ .../servlet/ServletHttpAttributesGetter.java | 68 +++++++++++ .../servlet/ServletInstrumenterBuilder.java | 4 +- .../servlet/ServletNetAttributesGetter.java | 88 -------------- .../v5_3/SpringWebfluxTelemetryBuilder.java | 3 +- .../WebfluxServerHttpAttributesGetter.java | 28 +++++ .../WebfluxServerNetAttributesGetter.java | 42 ------- .../SpringWebMvcHttpAttributesGetter.java | 59 ++++++++++ .../v5_3/SpringWebMvcNetAttributesGetter.java | 75 ------------ .../v5_3/SpringWebMvcTelemetryBuilder.java | 3 +- .../SpringWebMvcHttpAttributesGetter.java | 59 ++++++++++ .../v6_0/SpringWebMvcNetAttributesGetter.java | 75 ------------ .../v6_0/SpringWebMvcTelemetryBuilder.java | 3 +- .../common/TomcatHttpAttributesGetter.java | 60 ++++++++++ .../common/TomcatInstrumenterFactory.java | 3 +- .../common/TomcatNetAttributesGetter.java | 76 ------------- .../UndertowHttpAttributesGetter.java | 49 ++++++++ .../undertow/UndertowNetAttributesGetter.java | 63 ----------- .../undertow/UndertowSingletons.java | 3 +- .../testing/TestInstrumenters.java | 9 +- 61 files changed, 958 insertions(+), 1238 deletions(-) delete mode 100644 instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaNetServerAttributesGetter.java delete mode 100644 instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java delete mode 100644 instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java delete mode 100644 instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt delete mode 100644 instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorNetServerAttributesGetter.kt delete mode 100644 instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java delete mode 100644 instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java delete mode 100644 instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyNetServerAttributesGetter.java delete mode 100644 instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockNetServerAttributesGetter.java delete mode 100644 instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/RatpackNetServerAttributesGetter.java delete mode 100644 instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletNetAttributesGetter.java rename instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/{RestletNetAttributesGetter.java => ServerCallAccess.java} (75%) delete mode 100644 instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesGetter.java delete mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerNetAttributesGetter.java delete mode 100644 instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java delete mode 100644 instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcNetAttributesGetter.java delete mode 100644 instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesGetter.java delete mode 100644 instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowNetAttributesGetter.java diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java index ac03f3987dde..5ae5f49aef3e 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java @@ -37,6 +37,19 @@ public final class HttpServerAttributesExtractor implements SpanKeyProvider { /** Creates the HTTP server attributes extractor with default configuration. */ + public static AttributesExtractor create( + HttpServerAttributesGetter httpAttributesGetter) { + return builder(httpAttributesGetter).build(); + } + + /** + * Creates the HTTP server attributes extractor with default configuration. + * + * @deprecated Make sure that your {@linkplain HttpServerAttributesGetter getter} implements all + * the network-related methods and use {@link #create(HttpServerAttributesGetter)} instead. + * This method will be removed in the 2.0 release. + */ + @Deprecated public static AttributesExtractor create( HttpServerAttributesGetter httpAttributesGetter, NetServerAttributesGetter netAttributesGetter) { @@ -47,6 +60,20 @@ public static AttributesExtractor create( * Returns a new {@link HttpServerAttributesExtractorBuilder} that can be used to configure the * HTTP client attributes extractor. */ + public static HttpServerAttributesExtractorBuilder builder( + HttpServerAttributesGetter httpAttributesGetter) { + return new HttpServerAttributesExtractorBuilder<>(httpAttributesGetter, httpAttributesGetter); + } + + /** + * Returns a new {@link HttpServerAttributesExtractorBuilder} that can be used to configure the + * HTTP client attributes extractor. + * + * @deprecated Make sure that your {@linkplain HttpServerAttributesGetter getter} implements all + * the network-related methods and use {@link #builder(HttpServerAttributesGetter)} instead. + * This method will be removed in the 2.0 release. + */ + @Deprecated public static HttpServerAttributesExtractorBuilder builder( HttpServerAttributesGetter httpAttributesGetter, NetServerAttributesGetter netAttributesGetter) { 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 b377f5b441bb..a1f7ef3e53b9 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 @@ -5,6 +5,10 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.url.UrlAttributesGetter; import javax.annotation.Nullable; @@ -16,7 +20,12 @@ * various HTTP server attributes in a type-generic way. */ public interface HttpServerAttributesGetter - extends HttpCommonAttributesGetter, UrlAttributesGetter { + extends HttpCommonAttributesGetter, + UrlAttributesGetter, + NetServerAttributesGetter, + NetworkAttributesGetter, + ServerAttributesGetter, + ClientAttributesGetter { /** {@inheritDoc} */ @Nullable 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 8c387d5bfdbf..3ea68b9bcf9a 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 @@ -17,7 +17,6 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.List; @@ -83,10 +82,6 @@ public List getHttpResponseHeader( String values = (String) response.get("header." + name); return values == null ? emptyList() : asList(values.split(",")); } - } - - static class TestNetServerAttributesGetter - implements NetServerAttributesGetter, Map> { @Nullable @Override @@ -156,8 +151,7 @@ void normal() { Function routeFromContext = ctx -> "/repositories/{repoId}"; AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setCapturedRequestHeaders(singletonList("Custom-Request-Header")) .setCapturedResponseHeaders(singletonList("Custom-Response-Header")) .setHttpRouteGetter(routeFromContext) @@ -199,8 +193,7 @@ void extractClientIpFromX_Forwarded_For() { request.put("header.x-forwarded-for", "1.1.1.1"); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setCapturedRequestHeaders(emptyList()) .setCapturedResponseHeaders(emptyList()) .build(); @@ -221,8 +214,7 @@ void extractClientIpFromX_Forwarded_Proto() { request.put("header.x-forwarded-proto", "https"); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setCapturedRequestHeaders(emptyList()) .setCapturedResponseHeaders(emptyList()) .build(); @@ -241,8 +233,7 @@ void extractNetHostAndPortFromHostHeader() { request.put("header.host", "thehost:777"); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setCapturedRequestHeaders(emptyList()) .setCapturedResponseHeaders(emptyList()) .build(); @@ -263,8 +254,7 @@ void extractNetHostAndPortFromNetAttributesGetter() { request.put("hostPort", 777); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setCapturedRequestHeaders(emptyList()) .setCapturedResponseHeaders(emptyList()) .build(); @@ -285,8 +275,7 @@ void defaultHostPort(int hostPort, String scheme) { request.put("hostPort", hostPort); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setCapturedRequestHeaders(emptyList()) .setCapturedResponseHeaders(emptyList()) .build(); @@ -313,8 +302,7 @@ void computeTargetFromPathAndQuery(String path, String query, String expectedTar request.put("query", query); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()); + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); 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 9a52314e2980..eb8a91db3b1a 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 @@ -16,7 +16,6 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @@ -78,10 +77,6 @@ public List getHttpResponseHeader( String values = (String) response.get("header." + name); return values == null ? emptyList() : asList(values.split(",")); } - } - - static class TestNetServerAttributesGetter - implements NetServerAttributesGetter, Map> { @Nullable @Override @@ -151,8 +146,7 @@ void normal() { Function routeFromContext = ctx -> "/repositories/{repoId}"; AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setCapturedRequestHeaders(singletonList("Custom-Request-Header")) .setCapturedResponseHeaders(singletonList("Custom-Response-Header")) .setHttpRouteGetter(routeFromContext) 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 42a758559485..12bf9798fb38 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 @@ -18,7 +18,6 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes; import io.opentelemetry.instrumentation.api.internal.HttpConstants; @@ -89,10 +88,6 @@ public List getHttpResponseHeader( String values = response.get("header." + name); return values == null ? emptyList() : asList(values.split(",")); } - } - - static class TestNetServerAttributesGetter - implements NetServerAttributesGetter, Map> { @Nullable @Override @@ -180,8 +175,7 @@ void normal() { Function routeFromContext = ctx -> "/repositories/{repoId}"; AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setCapturedRequestHeaders(singletonList("Custom-Request-Header")) .setCapturedResponseHeaders(singletonList("Custom-Response-Header")) .setHttpRouteGetter(routeFromContext) @@ -233,8 +227,7 @@ void skipNetworkTransportIfDefaultForProtocol( request.put("transport", observedTransport); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()); + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); @@ -271,8 +264,7 @@ void shouldExtractKnownMethods(String requestMethod) { request.put("method", requestMethod); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()); + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); @@ -290,8 +282,7 @@ void shouldTreatMethodsAsCaseSensitive(String requestMethod) { request.put("method", requestMethod); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()); + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); @@ -309,8 +300,7 @@ void shouldUseOtherForUnknownMethods(String requestMethod) { request.put("method", requestMethod); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()); + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); @@ -328,8 +318,7 @@ void shouldExtractKnownMethods_override(String requestMethod) { request.put("method", requestMethod); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) .build(); @@ -349,8 +338,7 @@ void shouldUseOtherForUnknownMethods_override(String requestMethod) { request.put("method", requestMethod); AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder( - new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) .build(); 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 9360a82af6c6..94d1e5f910db 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,6 +7,7 @@ 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; @@ -54,4 +55,29 @@ public String getUrlQuery(HttpRequest request) { Option queryString = request.uri().rawQueryString(); return queryString.isDefined() ? queryString.get() : null; } + + @Nullable + @Override + public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse httpResponse) { + return AkkaHttpUtil.protocolName(request); + } + + @Nullable + @Override + 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/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerSingletons.java b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerSingletons.java index 69378306ee91..046e04778da4 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerSingletons.java +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerSingletons.java @@ -30,8 +30,7 @@ public final class AkkaHttpServerSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpServerAttributesExtractor.builder( - httpAttributesGetter, new AkkaNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(httpAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .setKnownMethods(CommonConfig.get().getKnownHttpRequestMethods()) diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaNetServerAttributesGetter.java b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaNetServerAttributesGetter.java deleted file mode 100644 index a85ac5a3492d..000000000000 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaNetServerAttributesGetter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.akkahttp.server; - -import akka.http.scaladsl.model.HttpRequest; -import akka.http.scaladsl.model.HttpResponse; -import akka.http.scaladsl.model.Uri; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import io.opentelemetry.javaagent.instrumentation.akkahttp.AkkaHttpUtil; -import javax.annotation.Nullable; - -class AkkaNetServerAttributesGetter - implements NetServerAttributesGetter { - - @Nullable - @Override - public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse httpResponse) { - return AkkaHttpUtil.protocolName(request); - } - - @Nullable - @Override - 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 25f183c8b88f..a87cd0f14f44 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 @@ -8,9 +8,12 @@ import com.linecorp.armeria.common.HttpRequest; import com.linecorp.armeria.common.HttpStatus; import com.linecorp.armeria.common.RequestContext; +import com.linecorp.armeria.common.SessionProtocol; import com.linecorp.armeria.common.logging.RequestLog; import com.linecorp.armeria.server.ServiceRequestContext; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.RequestContextAccess; +import java.net.InetSocketAddress; import java.util.List; import javax.annotation.Nullable; @@ -75,6 +78,43 @@ public String getHttpRoute(RequestContext ctx) { return null; } + @Override + public String getNetworkProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) { + return "http"; + } + + @Override + public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) { + SessionProtocol protocol = ctx.sessionProtocol(); + return protocol.isMultiplex() ? "2.0" : "1.1"; + } + + @Nullable + @Override + public String getServerAddress(RequestContext ctx) { + return null; + } + + @Nullable + @Override + public Integer getServerPort(RequestContext ctx) { + return null; + } + + @Override + @Nullable + public InetSocketAddress getClientInetSocketAddress( + RequestContext ctx, @Nullable RequestLog requestLog) { + return RequestContextAccess.remoteAddress(ctx); + } + + @Nullable + @Override + public InetSocketAddress getServerInetSocketAddress( + RequestContext ctx, @Nullable RequestLog log) { + return RequestContextAccess.localAddress(ctx); + } + private static HttpRequest request(RequestContext ctx) { HttpRequest request = ctx.request(); if (request == 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 deleted file mode 100644 index 74206910ac93..000000000000 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.armeria.v1_3; - -import com.linecorp.armeria.common.RequestContext; -import com.linecorp.armeria.common.SessionProtocol; -import com.linecorp.armeria.common.logging.RequestLog; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import io.opentelemetry.instrumentation.armeria.v1_3.internal.RequestContextAccess; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; - -final class ArmeriaNetServerAttributesGetter - implements NetServerAttributesGetter { - - @Override - public String getNetworkProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) { - return "http"; - } - - @Override - public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) { - SessionProtocol protocol = ctx.sessionProtocol(); - return protocol.isMultiplex() ? "2.0" : "1.1"; - } - - @Nullable - @Override - public String getServerAddress(RequestContext ctx) { - return null; - } - - @Nullable - @Override - public Integer getServerPort(RequestContext ctx) { - return null; - } - - @Override - @Nullable - public InetSocketAddress getClientInetSocketAddress( - RequestContext ctx, @Nullable RequestLog requestLog) { - return RequestContextAccess.remoteAddress(ctx); - } - - @Nullable - @Override - public InetSocketAddress getServerInetSocketAddress( - RequestContext ctx, @Nullable RequestLog log) { - return RequestContextAccess.localAddress(ctx); - } -} diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java index 0b16d26c4e19..87d88fbb5e79 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java @@ -52,8 +52,7 @@ public final class ArmeriaTelemetryBuilder { HttpClientAttributesExtractor.builder(ArmeriaHttpClientAttributesGetter.INSTANCE); private final HttpServerAttributesExtractorBuilder httpServerAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder( - ArmeriaHttpServerAttributesGetter.INSTANCE, new ArmeriaNetServerAttributesGetter()); + HttpServerAttributesExtractor.builder(ArmeriaHttpServerAttributesGetter.INSTANCE); private Function< SpanStatusExtractor, 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 67e47b6c7f64..a51130679ca3 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 @@ -5,14 +5,19 @@ 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 static java.util.Collections.emptyList; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; +import org.glassfish.grizzly.Transport; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.HttpResponsePacket; +import org.glassfish.grizzly.nio.transport.TCPNIOTransport; +import org.glassfish.grizzly.nio.transport.UDPNIOTransport; final class GrizzlyHttpAttributesGetter implements HttpServerAttributesGetter { @@ -64,4 +69,90 @@ public String getUrlPath(HttpRequestPacket request) { public String getUrlQuery(HttpRequestPacket request) { return request.getQueryString(); } + + @Override + public String getTransport(HttpRequestPacket request) { + Transport transport = request.getConnection().getTransport(); + if (transport instanceof TCPNIOTransport) { + return IP_TCP; + } + if (transport instanceof UDPNIOTransport) { + return IP_UDP; + } + return null; + } + + @Nullable + @Override + public String getNetworkTransport( + HttpRequestPacket request, @Nullable HttpResponsePacket response) { + Transport transport = request.getConnection().getTransport(); + if (transport instanceof TCPNIOTransport) { + return "tcp"; + } else if (transport instanceof UDPNIOTransport) { + return "udp"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolName( + HttpRequestPacket request, @Nullable HttpResponsePacket response) { + String protocol = request.getProtocolString(); + if (protocol.startsWith("HTTP/")) { + return "http"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolVersion( + HttpRequestPacket request, @Nullable HttpResponsePacket response) { + String protocol = request.getProtocolString(); + if (protocol.startsWith("HTTP/")) { + return protocol.substring("HTTP/".length()); + } + 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 getClientSocketAddress( + HttpRequestPacket request, @Nullable HttpResponsePacket response) { + return request.getRemoteAddress(); + } + + @Override + public Integer getClientSocketPort( + HttpRequestPacket request, @Nullable HttpResponsePacket response) { + return request.getRemotePort(); + } + + @Nullable + @Override + public String getServerSocketAddress( + HttpRequestPacket request, @Nullable HttpResponsePacket response) { + return request.getLocalAddress(); + } + + @Override + public Integer getServerSocketPort( + HttpRequestPacket request, @Nullable HttpResponsePacket response) { + return request.getLocalPort(); + } } diff --git a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java b/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java deleted file mode 100644 index 6d866e7ba152..000000000000 --- a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -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.Transport; -import org.glassfish.grizzly.http.HttpRequestPacket; -import org.glassfish.grizzly.http.HttpResponsePacket; -import org.glassfish.grizzly.nio.transport.TCPNIOTransport; -import org.glassfish.grizzly.nio.transport.UDPNIOTransport; - -final class GrizzlyNetAttributesGetter - implements NetServerAttributesGetter { - - @Override - public String getTransport(HttpRequestPacket request) { - Transport transport = request.getConnection().getTransport(); - if (transport instanceof TCPNIOTransport) { - return IP_TCP; - } - if (transport instanceof UDPNIOTransport) { - return IP_UDP; - } - return null; - } - - @Nullable - @Override - public String getNetworkTransport( - HttpRequestPacket request, @Nullable HttpResponsePacket response) { - Transport transport = request.getConnection().getTransport(); - if (transport instanceof TCPNIOTransport) { - return "tcp"; - } else if (transport instanceof UDPNIOTransport) { - return "udp"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolName( - HttpRequestPacket request, @Nullable HttpResponsePacket response) { - String protocol = request.getProtocolString(); - if (protocol.startsWith("HTTP/")) { - return "http"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - HttpRequestPacket request, @Nullable HttpResponsePacket response) { - String protocol = request.getProtocolString(); - if (protocol.startsWith("HTTP/")) { - return protocol.substring("HTTP/".length()); - } - 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 getClientSocketAddress( - HttpRequestPacket request, @Nullable HttpResponsePacket response) { - return request.getRemoteAddress(); - } - - @Override - public Integer getClientSocketPort( - HttpRequestPacket request, @Nullable HttpResponsePacket response) { - return request.getRemotePort(); - } - - @Nullable - @Override - public String getServerSocketAddress( - HttpRequestPacket request, @Nullable HttpResponsePacket response) { - return request.getLocalAddress(); - } - - @Override - public Integer getServerSocketPort( - HttpRequestPacket request, @Nullable HttpResponsePacket response) { - return request.getLocalPort(); - } -} diff --git a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java b/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java index 988011570838..b9567f199b3f 100644 --- a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java +++ b/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java @@ -23,7 +23,6 @@ public final class GrizzlySingletons { static { GrizzlyHttpAttributesGetter httpAttributesGetter = new GrizzlyHttpAttributesGetter(); - GrizzlyNetAttributesGetter netAttributesGetter = new GrizzlyNetAttributesGetter(); INSTRUMENTER = Instrumenter.builder( @@ -32,7 +31,7 @@ public final class GrizzlySingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) + HttpServerAttributesExtractor.builder(httpAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .setKnownMethods(CommonConfig.get().getKnownHttpRequestMethods()) 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 884638e07f85..2cb7f6c8d9be 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 @@ -9,6 +9,7 @@ import io.ktor.features.* import io.ktor.request.* import io.ktor.response.* import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter +import io.opentelemetry.instrumentation.ktor.isIpAddress internal enum class KtorHttpServerAttributesGetter : HttpServerAttributesGetter { @@ -41,4 +42,26 @@ internal enum class KtorHttpServerAttributesGetter : override fun getUrlQuery(request: ApplicationRequest): String { return request.queryString() } + + override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = + if (request.httpVersion.startsWith("HTTP/")) "http" else null + + override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = + if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null + + override fun getClientSocketAddress(request: ApplicationRequest, response: ApplicationResponse?): String? { + val remote = request.local.remoteHost + if ("unknown" != remote && isIpAddress(remote)) { + return remote + } + 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-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 deleted file mode 100644 index 50aeda5af36b..000000000000 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.ktor.v1_0 - -import io.ktor.request.* -import io.ktor.response.* -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter -import io.opentelemetry.instrumentation.ktor.isIpAddress - -internal class KtorNetServerAttributesGetter : NetServerAttributesGetter { - - override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = - if (request.httpVersion.startsWith("HTTP/")) "http" else null - - override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = - if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null - - override fun getClientSocketAddress(request: ApplicationRequest, response: ApplicationResponse?): String? { - val remote = request.local.remoteHost - if ("unknown" != remote && isIpAddress(remote)) { - return remote - } - 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-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index 6cdb375d376a..6ecc43d93cfb 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -36,10 +36,7 @@ class KtorServerTracing private constructor( internal val additionalExtractors = mutableListOf>() - internal val httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder( - KtorHttpServerAttributesGetter.INSTANCE, - KtorNetServerAttributesGetter() - ) + internal val httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder(KtorHttpServerAttributesGetter.INSTANCE) internal var statusExtractor: (SpanStatusExtractor) -> SpanStatusExtractor = { a -> a } 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 330b75a71134..8bb05aa50ba5 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 @@ -9,6 +9,7 @@ import io.ktor.server.plugins.* import io.ktor.server.request.* import io.ktor.server.response.* import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter +import io.opentelemetry.instrumentation.ktor.isIpAddress internal enum class KtorHttpServerAttributesGetter : HttpServerAttributesGetter { @@ -41,4 +42,26 @@ internal enum class KtorHttpServerAttributesGetter : override fun getUrlQuery(request: ApplicationRequest): String { return request.queryString() } + + override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = + if (request.httpVersion.startsWith("HTTP/")) "http" else null + + 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 getClientSocketAddress(request: ApplicationRequest, response: ApplicationResponse?): String? { + val remote = request.local.remoteHost + if ("unknown" != remote && isIpAddress(remote)) { + return remote + } + return null + } } diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorNetServerAttributesGetter.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorNetServerAttributesGetter.kt deleted file mode 100644 index 39d2e65532e0..000000000000 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorNetServerAttributesGetter.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.ktor.v2_0.server - -import io.ktor.server.request.* -import io.ktor.server.response.* -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter -import io.opentelemetry.instrumentation.ktor.isIpAddress - -internal class KtorNetServerAttributesGetter : NetServerAttributesGetter { - - override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = - if (request.httpVersion.startsWith("HTTP/")) "http" else null - - 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 getClientSocketAddress(request: ApplicationRequest, response: ApplicationResponse?): String? { - val remote = request.local.remoteHost - if ("unknown" != remote && isIpAddress(remote)) { - return remote - } - return null - } -} diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index b0e2953c40b8..c600c60bc776 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -37,10 +37,7 @@ class KtorServerTracing private constructor( internal val additionalExtractors = mutableListOf>() - internal val httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder( - KtorHttpServerAttributesGetter.INSTANCE, - KtorNetServerAttributesGetter() - ) + internal val httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder(KtorHttpServerAttributesGetter.INSTANCE) internal var statusExtractor: (SpanStatusExtractor) -> SpanStatusExtractor = { a -> a } 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 62fd1959200b..933ed13d29ee 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 @@ -53,4 +53,60 @@ public String getUrlPath(LibertyRequest request) { public String getUrlQuery(LibertyRequest request) { return request.getQueryString(); } + + @Nullable + @Override + public String getNetworkProtocolName( + LibertyRequest request, @Nullable LibertyResponse libertyResponse) { + String protocol = request.getProtocol(); + if (protocol != null && protocol.startsWith("HTTP/")) { + return "http"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolVersion( + LibertyRequest request, @Nullable LibertyResponse libertyResponse) { + String protocol = request.getProtocol(); + if (protocol != null && protocol.startsWith("HTTP/")) { + return protocol.substring("HTTP/".length()); + } + 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 getClientSocketAddress(LibertyRequest request, @Nullable LibertyResponse response) { + return request.getClientSocketAddress(); + } + + @Override + public Integer getClientSocketPort(LibertyRequest request, @Nullable LibertyResponse response) { + return request.getClientSocketPort(); + } + + @Nullable + @Override + public String getServerSocketAddress(LibertyRequest request, @Nullable LibertyResponse response) { + return request.getServerSocketAddress(); + } + + @Nullable + @Override + public Integer getServerSocketPort(LibertyRequest request, @Nullable LibertyResponse response) { + return request.getServerSocketPort(); + } } 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 deleted file mode 100644 index 18f4b4fbb04c..000000000000 --- a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; - -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import javax.annotation.Nullable; - -public class LibertyDispatcherNetAttributesGetter - implements NetServerAttributesGetter { - - @Nullable - @Override - public String getNetworkProtocolName( - LibertyRequest request, @Nullable LibertyResponse libertyResponse) { - String protocol = request.getProtocol(); - if (protocol != null && protocol.startsWith("HTTP/")) { - return "http"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - LibertyRequest request, @Nullable LibertyResponse libertyResponse) { - String protocol = request.getProtocol(); - if (protocol != null && protocol.startsWith("HTTP/")) { - return protocol.substring("HTTP/".length()); - } - 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 getClientSocketAddress(LibertyRequest request, @Nullable LibertyResponse response) { - return request.getClientSocketAddress(); - } - - @Override - public Integer getClientSocketPort(LibertyRequest request, @Nullable LibertyResponse response) { - return request.getClientSocketPort(); - } - - @Nullable - @Override - public String getServerSocketAddress(LibertyRequest request, @Nullable LibertyResponse response) { - return request.getServerSocketAddress(); - } - - @Nullable - @Override - public Integer getServerSocketPort(LibertyRequest request, @Nullable LibertyResponse response) { - return request.getServerSocketPort(); - } -} diff --git a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java index 040be775b46d..9cc5bc278654 100644 --- a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java +++ b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java @@ -22,8 +22,6 @@ public final class LibertyDispatcherSingletons { static { LibertyDispatcherHttpAttributesGetter httpAttributesGetter = new LibertyDispatcherHttpAttributesGetter(); - LibertyDispatcherNetAttributesGetter netAttributesGetter = - new LibertyDispatcherNetAttributesGetter(); INSTRUMENTER = Instrumenter.builder( @@ -32,7 +30,7 @@ public final class LibertyDispatcherSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) + HttpServerAttributesExtractor.builder(httpAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .setKnownMethods(CommonConfig.get().getKnownHttpRequestMethods()) 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 7b2661430014..c159bea4fd6f 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 @@ -5,12 +5,20 @@ package io.opentelemetry.javaagent.instrumentation.netty.v3_8.server; +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.http.HttpServerAttributesGetter; import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel; +import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.ChannelUtil; import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.HttpSchemeUtil; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.util.List; import javax.annotation.Nullable; +import org.jboss.netty.channel.socket.DatagramChannel; import org.jboss.netty.handler.codec.http.HttpResponse; +import org.jboss.netty.handler.codec.http.HttpVersion; final class NettyHttpServerAttributesGetter implements HttpServerAttributesGetter { @@ -55,4 +63,62 @@ public String getUrlQuery(HttpRequestAndChannel requestAndChannel) { int separatorPos = fullPath.indexOf('?'); return separatorPos == -1 ? null : fullPath.substring(separatorPos + 1); } + + @Override + public String getTransport(HttpRequestAndChannel requestAndChannel) { + return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; + } + + @Override + public String getNetworkTransport( + HttpRequestAndChannel requestAndChannel, HttpResponse response) { + return ChannelUtil.getNetworkTransport(requestAndChannel.channel()); + } + + @Override + public String getNetworkProtocolName( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + return requestAndChannel.request().getProtocolVersion().getProtocolName(); + } + + @Override + public String getNetworkProtocolVersion( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + HttpVersion version = requestAndChannel.request().getProtocolVersion(); + 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 getClientInetSocketAddress( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + SocketAddress address = requestAndChannel.channel().getRemoteAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } + return null; + } + + @Nullable + @Override + public InetSocketAddress getServerInetSocketAddress( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + SocketAddress address = requestAndChannel.channel().getLocalAddress(); + 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 deleted file mode 100644 index 269a7b16a219..000000000000 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.netty.v3_8.server; - -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 io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel; -import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.ChannelUtil; -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; -import org.jboss.netty.handler.codec.http.HttpVersion; - -final class NettyNetServerAttributesGetter - implements NetServerAttributesGetter { - - @Override - public String getTransport(HttpRequestAndChannel requestAndChannel) { - return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; - } - - @Override - public String getNetworkTransport( - HttpRequestAndChannel requestAndChannel, HttpResponse response) { - return ChannelUtil.getNetworkTransport(requestAndChannel.channel()); - } - - @Override - public String getNetworkProtocolName( - HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - return requestAndChannel.request().getProtocolVersion().getProtocolName(); - } - - @Override - public String getNetworkProtocolVersion( - HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - HttpVersion version = requestAndChannel.request().getProtocolVersion(); - 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 getClientInetSocketAddress( - HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - SocketAddress address = requestAndChannel.channel().getRemoteAddress(); - if (address instanceof InetSocketAddress) { - return (InetSocketAddress) address; - } - return null; - } - - @Nullable - @Override - public InetSocketAddress getServerInetSocketAddress( - HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - SocketAddress address = requestAndChannel.channel().getLocalAddress(); - 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/NettyServerSingletons.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyServerSingletons.java index 4338c88971f0..2644520390a8 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyServerSingletons.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyServerSingletons.java @@ -32,8 +32,7 @@ final class NettyServerSingletons { HttpSpanNameExtractor.create(httpServerAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpServerAttributesGetter)) .addAttributesExtractor( - HttpServerAttributesExtractor.builder( - httpServerAttributesGetter, new NettyNetServerAttributesGetter()) + HttpServerAttributesExtractor.builder(httpServerAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .setKnownMethods(CommonConfig.get().getKnownHttpRequestMethods()) 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 27ca3dda734c..ef5d1ed6b61a 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 @@ -5,10 +5,18 @@ package io.opentelemetry.instrumentation.netty.v4.common.internal.server; +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.netty.handler.codec.http.HttpVersion; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; +import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil; import io.opentelemetry.instrumentation.netty.v4.common.internal.HttpSchemeUtil; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.util.List; import javax.annotation.Nullable; @@ -55,4 +63,62 @@ public String getUrlQuery(HttpRequestAndChannel requestAndChannel) { int separatorPos = fullPath.indexOf('?'); return separatorPos == -1 ? null : fullPath.substring(separatorPos + 1); } + + @Override + public String getTransport(HttpRequestAndChannel requestAndChannel) { + return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; + } + + @Override + public String getNetworkTransport( + HttpRequestAndChannel requestAndChannel, HttpResponse response) { + return ChannelUtil.getNetworkTransport(requestAndChannel.channel()); + } + + @Override + public String getNetworkProtocolName( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + return requestAndChannel.request().getProtocolVersion().protocolName(); + } + + @Override + public String getNetworkProtocolVersion( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + HttpVersion version = requestAndChannel.request().getProtocolVersion(); + 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 getClientInetSocketAddress( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + SocketAddress address = requestAndChannel.remoteAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } + return null; + } + + @Nullable + @Override + public InetSocketAddress getServerInetSocketAddress( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + SocketAddress address = requestAndChannel.channel().localAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } + return null; + } } diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyNetServerAttributesGetter.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyNetServerAttributesGetter.java deleted file mode 100644 index b2a837c141ba..000000000000 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyNetServerAttributesGetter.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.netty.v4.common.internal.server; - -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.netty.handler.codec.http.HttpVersion; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; -import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import javax.annotation.Nullable; - -final class NettyNetServerAttributesGetter - implements NetServerAttributesGetter { - - @Override - public String getTransport(HttpRequestAndChannel requestAndChannel) { - return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; - } - - @Override - public String getNetworkTransport( - HttpRequestAndChannel requestAndChannel, HttpResponse response) { - return ChannelUtil.getNetworkTransport(requestAndChannel.channel()); - } - - @Override - public String getNetworkProtocolName( - HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - return requestAndChannel.request().getProtocolVersion().protocolName(); - } - - @Override - public String getNetworkProtocolVersion( - HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - HttpVersion version = requestAndChannel.request().getProtocolVersion(); - 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 getClientInetSocketAddress( - HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - SocketAddress address = requestAndChannel.remoteAddress(); - if (address instanceof InetSocketAddress) { - return (InetSocketAddress) address; - } - return null; - } - - @Nullable - @Override - public InetSocketAddress getServerInetSocketAddress( - HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { - SocketAddress address = requestAndChannel.channel().localAddress(); - if (address instanceof InetSocketAddress) { - return (InetSocketAddress) address; - } - return null; - } -} diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyServerInstrumenterFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyServerInstrumenterFactory.java index 2b1510a55030..01ac51a9b46c 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyServerInstrumenterFactory.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyServerInstrumenterFactory.java @@ -33,8 +33,7 @@ public static Instrumenter create( NettyHttpServerAttributesGetter httpAttributesGetter = new NettyHttpServerAttributesGetter(); HttpServerAttributesExtractorBuilder extractorBuilder = - HttpServerAttributesExtractor.builder( - httpAttributesGetter, new NettyNetServerAttributesGetter()); + HttpServerAttributesExtractor.builder(httpAttributesGetter); extractorConfigurer.accept(extractorBuilder); return Instrumenter.builder( diff --git a/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/AgentSpanTestingInstrumenter.java b/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/AgentSpanTestingInstrumenter.java index 39a95e5afed7..ac83a016f85f 100644 --- a/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/AgentSpanTestingInstrumenter.java +++ b/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/AgentSpanTestingInstrumenter.java @@ -30,8 +30,7 @@ public final class AgentSpanTestingInstrumenter { private static final Instrumenter HTTP_SERVER_INSTRUMENTER = Instrumenter.builder(GlobalOpenTelemetry.get(), "test", request -> request) .addAttributesExtractor( - HttpServerAttributesExtractor.create( - MockHttpServerAttributesGetter.INSTANCE, MockNetServerAttributesGetter.INSTANCE)) + HttpServerAttributesExtractor.create(MockHttpServerAttributesGetter.INSTANCE)) .addContextCustomizer(HttpRouteHolder.create(MockHttpServerAttributesGetter.INSTANCE)) .addContextCustomizer( (context, request, startAttributes) -> context.with(REQUEST_CONTEXT_KEY, request)) 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 4718afd97d8d..11b2346eddc0 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,4 +54,16 @@ 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/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockNetServerAttributesGetter.java b/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockNetServerAttributesGetter.java deleted file mode 100644 index 7dec1b276123..000000000000 --- a/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockNetServerAttributesGetter.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.testing; - -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import javax.annotation.Nullable; - -// only needed so that HttpServerAttributesExtractor can be added to the HTTP server instrumenter -enum MockNetServerAttributesGetter implements NetServerAttributesGetter { - INSTANCE; - - @Nullable - @Override - public String getServerAddress(String s) { - return null; - } - - @Nullable - @Override - public Integer getServerPort(String s) { - return null; - } -} 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 f580816cb4e5..1d28a2ae464b 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 @@ -62,4 +62,51 @@ public Integer getHttpResponseStatusCode( public List getHttpResponseHeader(Request request, Response response, String name) { return response.getHeaders().getAll(name); } + + @Nullable + @Override + public String getNetworkProtocolName(Request request, @Nullable Response response) { + String protocol = request.getProtocol(); + if (protocol.startsWith("HTTP/")) { + return "http"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { + String protocol = request.getProtocol(); + if (protocol.startsWith("HTTP/")) { + return protocol.substring("HTTP/".length()); + } + 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 getClientSocketPort(Request request, @Nullable Response response) { + return request.getRemoteAddress().getPort(); + } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java index 9147ce3eb040..af3cca76056a 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java @@ -17,7 +17,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.ratpack.v1_7.internal.RatpackNetServerAttributesGetter; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -40,8 +39,7 @@ public final class RatpackTelemetryBuilder { HttpClientAttributesExtractor.builder(RatpackHttpClientAttributesGetter.INSTANCE); private final HttpServerAttributesExtractorBuilder httpServerAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder( - RatpackHttpAttributesGetter.INSTANCE, new RatpackNetServerAttributesGetter()); + HttpServerAttributesExtractor.builder(RatpackHttpAttributesGetter.INSTANCE); private final List> additionalHttpClientExtractors = new ArrayList<>(); diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/RatpackNetServerAttributesGetter.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/RatpackNetServerAttributesGetter.java deleted file mode 100644 index 33e588e590fe..000000000000 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/RatpackNetServerAttributesGetter.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.ratpack.v1_7.internal; - -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import javax.annotation.Nullable; -import ratpack.handling.Context; -import ratpack.http.Request; -import ratpack.http.Response; -import ratpack.server.PublicAddress; - -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public final class RatpackNetServerAttributesGetter - implements NetServerAttributesGetter { - - @Nullable - @Override - public String getNetworkProtocolName(Request request, @Nullable Response response) { - String protocol = request.getProtocol(); - if (protocol.startsWith("HTTP/")) { - return "http"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolVersion(Request request, @Nullable Response response) { - String protocol = request.getProtocol(); - if (protocol.startsWith("HTTP/")) { - return protocol.substring("HTTP/".length()); - } - 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 getClientSocketPort(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 aee20cf4bfb0..9f22138153e9 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 @@ -7,6 +7,8 @@ import static io.opentelemetry.instrumentation.restlet.v1_1.RestletHeadersGetter.getHeaders; +import com.noelios.restlet.http.HttpCall; +import com.noelios.restlet.http.HttpRequest; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; import java.util.ArrayList; import java.util.Collections; @@ -79,4 +81,68 @@ private static List parametersToList(Series headers) { } return stringHeaders; } + + @Nullable + @Override + public String getNetworkProtocolName(Request request, @Nullable Response response) { + String protocol = getProtocolString(request); + if (protocol.startsWith("HTTP/")) { + return "http"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { + String protocol = getProtocolString(request); + if (protocol.startsWith("HTTP/")) { + return protocol.substring("HTTP/".length()); + } + return null; + } + + 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 getClientSocketAddress(Request request, @Nullable Response response) { + return request.getClientInfo().getAddress(); + } + + @Override + public Integer getClientSocketPort(Request request, @Nullable Response response) { + return request.getClientInfo().getPort(); + } + + @Nullable + @Override + public String getServerSocketAddress(Request request, @Nullable Response response) { + HttpCall call = httpCall(request); + return call == null ? null : call.getServerAddress(); + } + + @Nullable + private static HttpCall httpCall(Request request) { + if (request instanceof HttpRequest) { + return ((HttpRequest) request).getHttpCall(); + } + return null; + } } diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletNetAttributesGetter.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletNetAttributesGetter.java deleted file mode 100644 index 65777fae1d1e..000000000000 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletNetAttributesGetter.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.restlet.v1_1; - -import com.noelios.restlet.http.HttpCall; -import com.noelios.restlet.http.HttpRequest; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import javax.annotation.Nullable; -import org.restlet.data.Request; -import org.restlet.data.Response; - -final class RestletNetAttributesGetter implements NetServerAttributesGetter { - - @Nullable - @Override - public String getNetworkProtocolName(Request request, @Nullable Response response) { - String protocol = getProtocolString(request); - if (protocol.startsWith("HTTP/")) { - return "http"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolVersion(Request request, @Nullable Response response) { - String protocol = getProtocolString(request); - if (protocol.startsWith("HTTP/")) { - return protocol.substring("HTTP/".length()); - } - return null; - } - - 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 getClientSocketAddress(Request request, @Nullable Response response) { - return request.getClientInfo().getAddress(); - } - - @Override - public Integer getClientSocketPort(Request request, @Nullable Response response) { - return request.getClientInfo().getPort(); - } - - @Nullable - @Override - public String getServerSocketAddress(Request request, @Nullable Response response) { - HttpCall call = httpCall(request); - return call == null ? null : call.getServerAddress(); - } - - @Nullable - private static HttpCall httpCall(Request request) { - if (request instanceof HttpRequest) { - return ((HttpRequest) request).getHttpCall(); - } - return null; - } -} diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java index 7d469004b88e..678f00394dde 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java @@ -31,8 +31,7 @@ public final class RestletTelemetryBuilder { new ArrayList<>(); private final HttpServerAttributesExtractorBuilder httpAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder( - RestletHttpAttributesGetter.INSTANCE, new RestletNetAttributesGetter()); + HttpServerAttributesExtractor.builder(RestletHttpAttributesGetter.INSTANCE); RestletTelemetryBuilder(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; diff --git a/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletSingletons.java b/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletSingletons.java index 821d5aa9f6d7..f4474970d354 100644 --- a/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletSingletons.java +++ b/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletHttpAttributesGetter; import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletInstrumenterFactory; -import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletNetAttributesGetter; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import java.util.Collections; @@ -23,8 +22,7 @@ public final class RestletSingletons { private static final Instrumenter INSTRUMENTER = RestletInstrumenterFactory.newServerInstrumenter( GlobalOpenTelemetry.get(), - HttpServerAttributesExtractor.builder( - RestletHttpAttributesGetter.INSTANCE, new RestletNetAttributesGetter()) + HttpServerAttributesExtractor.builder(RestletHttpAttributesGetter.INSTANCE) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .setKnownMethods(CommonConfig.get().getKnownHttpRequestMethods()) diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java index 692545a68f36..4332c68b4ccc 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java @@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractorBuilder; import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletHttpAttributesGetter; import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletInstrumenterFactory; -import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletNetAttributesGetter; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -28,8 +27,7 @@ public final class RestletTelemetryBuilder { new ArrayList<>(); private final HttpServerAttributesExtractorBuilder httpAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder( - RestletHttpAttributesGetter.INSTANCE, new RestletNetAttributesGetter()); + HttpServerAttributesExtractor.builder(RestletHttpAttributesGetter.INSTANCE); RestletTelemetryBuilder(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; 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 43daf7658c39..52babb249be1 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 @@ -69,4 +69,45 @@ public List getHttpResponseHeader(Request request, Response response, St } return Arrays.asList(headers.getValuesArray(name, true)); } + + @Nullable + @Override + public String getNetworkProtocolName(Request request, @Nullable Response response) { + return request.getProtocol().getSchemeName(); + } + + @Nullable + @Override + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { + 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 getClientSocketAddress(Request request, @Nullable Response response) { + return request.getClientInfo().getAddress(); + } + + @Override + public Integer getClientSocketPort(Request request, @Nullable Response response) { + return request.getClientInfo().getPort(); + } + + @Nullable + @Override + public String getServerSocketAddress(Request request, @Nullable Response response) { + return ServerCallAccess.getServerAddress(request); + } } 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/ServerCallAccess.java similarity index 75% rename from instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletNetAttributesGetter.java rename to instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/ServerCallAccess.java index a42ba7da5097..719e07ec2c39 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/ServerCallAccess.java @@ -7,19 +7,12 @@ import static java.lang.invoke.MethodType.methodType; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import javax.annotation.Nullable; import org.restlet.Request; -import org.restlet.Response; -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public final class RestletNetAttributesGetter - implements NetServerAttributesGetter { +final class ServerCallAccess { private static final Class HTTP_REQUEST_CLASS; private static final MethodHandle GET_HTTP_CALL; @@ -80,20 +73,7 @@ public final class RestletNetAttributesGetter } @Nullable - @Override - public String getNetworkProtocolName(Request request, @Nullable Response response) { - return request.getProtocol().getSchemeName(); - } - - @Nullable - @Override - public String getNetworkProtocolVersion(Request request, @Nullable Response response) { - return request.getProtocol().getVersion(); - } - - @Nullable - @Override - public String getServerAddress(Request request) { + static String getHostDomain(Request request) { if (GET_HOST_DOMAIN == null) { return null; } @@ -109,8 +89,7 @@ public String getServerAddress(Request request) { } @Nullable - @Override - public Integer getServerPort(Request request) { + static Integer getServerPort(Request request) { if (GET_SERVER_PORT == null) { return null; } @@ -125,20 +104,8 @@ public Integer getServerPort(Request request) { } } - @Override @Nullable - public String getClientSocketAddress(Request request, @Nullable Response response) { - return request.getClientInfo().getAddress(); - } - - @Override - public Integer getClientSocketPort(Request request, @Nullable Response response) { - return request.getClientInfo().getPort(); - } - - @Nullable - @Override - public String getServerSocketAddress(Request request, @Nullable Response response) { + static String getServerAddress(Request request) { if (GET_SERVER_ADDRESS == null) { return null; } @@ -167,4 +134,6 @@ private static Object serverCall(Request request) { } return null; } + + private ServerCallAccess() {} } 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 e25ae5e514ff..a6499dce1daf 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 @@ -81,4 +81,72 @@ public List getHttpResponseHeader( String name) { return accessor.getResponseHeaderValues(responseContext.response(), name); } + + @Nullable + @Override + public String getNetworkProtocolName( + ServletRequestContext requestContext, + @Nullable ServletResponseContext responseContext) { + String protocol = accessor.getRequestProtocol(requestContext.request()); + if (protocol != null && protocol.startsWith("HTTP/")) { + return "http"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolVersion( + ServletRequestContext requestContext, + @Nullable ServletResponseContext responseContext) { + String protocol = accessor.getRequestProtocol(requestContext.request()); + if (protocol != null && protocol.startsWith("HTTP/")) { + return protocol.substring("HTTP/".length()); + } + 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 getClientSocketAddress( + ServletRequestContext requestContext, + @Nullable ServletResponseContext response) { + return accessor.getRequestRemoteAddr(requestContext.request()); + } + + @Override + @Nullable + public Integer getClientSocketPort( + ServletRequestContext requestContext, + @Nullable ServletResponseContext response) { + return accessor.getRequestRemotePort(requestContext.request()); + } + + @Nullable + @Override + public String getServerSocketAddress( + ServletRequestContext requestContext, + @Nullable ServletResponseContext response) { + return accessor.getRequestLocalAddr(requestContext.request()); + } + + @Nullable + @Override + public Integer getServerSocketPort( + ServletRequestContext requestContext, + @Nullable ServletResponseContext response) { + return accessor.getRequestLocalPort(requestContext.request()); + } } diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java index df1b57cf03a2..c14f0e06c09f 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java @@ -47,8 +47,6 @@ public Instrumenter, ServletResponseContext, ServletResponseContext> httpAttributesGetter) { - ServletNetAttributesGetter netAttributesGetter = - new ServletNetAttributesGetter<>(accessor); ServletErrorCauseExtractor errorCauseExtractor = new ServletErrorCauseExtractor<>(accessor); AttributesExtractor, ServletResponseContext> @@ -60,7 +58,7 @@ public Instrumenter, ServletResponseContext - implements NetServerAttributesGetter< - ServletRequestContext, ServletResponseContext> { - - private final ServletAccessor accessor; - - public ServletNetAttributesGetter(ServletAccessor accessor) { - this.accessor = accessor; - } - - @Nullable - @Override - public String getNetworkProtocolName( - ServletRequestContext requestContext, - @Nullable ServletResponseContext responseContext) { - String protocol = accessor.getRequestProtocol(requestContext.request()); - if (protocol != null && protocol.startsWith("HTTP/")) { - return "http"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - ServletRequestContext requestContext, - @Nullable ServletResponseContext responseContext) { - String protocol = accessor.getRequestProtocol(requestContext.request()); - if (protocol != null && protocol.startsWith("HTTP/")) { - return protocol.substring("HTTP/".length()); - } - 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 getClientSocketAddress( - ServletRequestContext requestContext, - @Nullable ServletResponseContext response) { - return accessor.getRequestRemoteAddr(requestContext.request()); - } - - @Override - @Nullable - public Integer getClientSocketPort( - ServletRequestContext requestContext, - @Nullable ServletResponseContext response) { - return accessor.getRequestRemotePort(requestContext.request()); - } - - @Nullable - @Override - public String getServerSocketAddress( - ServletRequestContext requestContext, - @Nullable ServletResponseContext response) { - return accessor.getRequestLocalAddr(requestContext.request()); - } - - @Nullable - @Override - public Integer getServerSocketPort( - ServletRequestContext requestContext, - @Nullable ServletResponseContext response) { - return accessor.getRequestLocalPort(requestContext.request()); - } -} diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java index bbd871130ff1..7388a091cbad 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java @@ -39,8 +39,7 @@ public final class SpringWebfluxTelemetryBuilder { private final HttpServerAttributesExtractorBuilder httpServerAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder( - WebfluxServerHttpAttributesGetter.INSTANCE, new WebfluxServerNetAttributesGetter()); + HttpServerAttributesExtractor.builder(WebfluxServerHttpAttributesGetter.INSTANCE); private Consumer> clientExtractorConfigurer = builder -> {}; private boolean captureExperimentalSpanAttributes; 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 cd611a8cac39..fdf79cbf3308 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 @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.spring.webflux.v5_3; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; +import java.net.InetSocketAddress; import java.util.Collections; import java.util.List; import javax.annotation.Nullable; @@ -77,4 +78,31 @@ public String getHttpRoute(ServerWebExchange request) { String contextPath = request.getRequest().getPath().contextPath().value(); 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 getClientInetSocketAddress( + ServerWebExchange request, @Nullable ServerWebExchange response) { + return request.getRequest().getRemoteAddress(); + } + + @Nullable + @Override + public InetSocketAddress getServerInetSocketAddress( + ServerWebExchange request, @Nullable ServerWebExchange response) { + return request.getRequest().getLocalAddress(); + } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerNetAttributesGetter.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerNetAttributesGetter.java deleted file mode 100644 index af6aab37a172..000000000000 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerNetAttributesGetter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.spring.webflux.v5_3; - -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; -import org.springframework.web.server.ServerWebExchange; - -final class WebfluxServerNetAttributesGetter - implements NetServerAttributesGetter { - - @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 getClientInetSocketAddress( - ServerWebExchange request, @Nullable ServerWebExchange response) { - return request.getRequest().getRemoteAddress(); - } - - @Nullable - @Override - public InetSocketAddress getServerInetSocketAddress( - ServerWebExchange request, @Nullable ServerWebExchange response) { - return request.getRequest().getLocalAddress(); - } -} 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 cb72b288ed91..5acf91a8fa3e 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 @@ -80,4 +80,63 @@ public String getUrlPath(HttpServletRequest request) { public String getUrlQuery(HttpServletRequest request) { return request.getQueryString(); } + + @Nullable + @Override + public String getNetworkProtocolName( + HttpServletRequest request, @Nullable HttpServletResponse response) { + String protocol = request.getProtocol(); + if (protocol != null && protocol.startsWith("HTTP/")) { + return "http"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolVersion( + HttpServletRequest request, @Nullable HttpServletResponse response) { + String protocol = request.getProtocol(); + if (protocol != null && protocol.startsWith("HTTP/")) { + return protocol.substring("HTTP/".length()); + } + 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 getClientSocketAddress( + HttpServletRequest request, @Nullable HttpServletResponse response) { + return request.getRemoteAddr(); + } + + @Override + public Integer getClientSocketPort( + HttpServletRequest request, @Nullable HttpServletResponse response) { + return request.getRemotePort(); + } + + @Nullable + @Override + public String getServerSocketAddress( + HttpServletRequest request, @Nullable HttpServletResponse response) { + return request.getLocalAddr(); + } + + @Override + public Integer getServerSocketPort( + HttpServletRequest request, @Nullable HttpServletResponse respo) { + return request.getLocalPort(); + } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java deleted file mode 100644 index 207be21c7360..000000000000 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.spring.webmvc.v5_3; - -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import javax.annotation.Nullable; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -enum SpringWebMvcNetAttributesGetter - implements NetServerAttributesGetter { - INSTANCE; - - @Nullable - @Override - public String getNetworkProtocolName( - HttpServletRequest request, @Nullable HttpServletResponse response) { - String protocol = request.getProtocol(); - if (protocol != null && protocol.startsWith("HTTP/")) { - return "http"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - HttpServletRequest request, @Nullable HttpServletResponse response) { - String protocol = request.getProtocol(); - if (protocol != null && protocol.startsWith("HTTP/")) { - return protocol.substring("HTTP/".length()); - } - 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 getClientSocketAddress( - HttpServletRequest request, @Nullable HttpServletResponse response) { - return request.getRemoteAddr(); - } - - @Override - public Integer getClientSocketPort( - HttpServletRequest request, @Nullable HttpServletResponse response) { - return request.getRemotePort(); - } - - @Nullable - @Override - public String getServerSocketAddress( - HttpServletRequest request, @Nullable HttpServletResponse response) { - return request.getLocalAddr(); - } - - @Override - public Integer getServerSocketPort( - HttpServletRequest request, @Nullable HttpServletResponse respo) { - return request.getLocalPort(); - } -} diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index d492824b7da4..178b793d72bd 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java @@ -34,8 +34,7 @@ public final class SpringWebMvcTelemetryBuilder { additionalExtractors = new ArrayList<>(); private final HttpServerAttributesExtractorBuilder httpAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder( - SpringWebMvcHttpAttributesGetter.INSTANCE, SpringWebMvcNetAttributesGetter.INSTANCE); + HttpServerAttributesExtractor.builder(SpringWebMvcHttpAttributesGetter.INSTANCE); @Nullable private Function< 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 edb8941e1470..797505beaec6 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 @@ -80,4 +80,63 @@ public String getUrlPath(HttpServletRequest request) { public String getUrlQuery(HttpServletRequest request) { return request.getQueryString(); } + + @Nullable + @Override + public String getNetworkProtocolName( + HttpServletRequest request, @Nullable HttpServletResponse response) { + String protocol = request.getProtocol(); + if (protocol != null && protocol.startsWith("HTTP/")) { + return "http"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolVersion( + HttpServletRequest request, @Nullable HttpServletResponse response) { + String protocol = request.getProtocol(); + if (protocol != null && protocol.startsWith("HTTP/")) { + return protocol.substring("HTTP/".length()); + } + 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 getClientSocketAddress( + HttpServletRequest request, @Nullable HttpServletResponse response) { + return request.getRemoteAddr(); + } + + @Override + public Integer getClientSocketPort( + HttpServletRequest request, @Nullable HttpServletResponse response) { + return request.getRemotePort(); + } + + @Nullable + @Override + public String getServerSocketAddress( + HttpServletRequest request, @Nullable HttpServletResponse response) { + return request.getLocalAddr(); + } + + @Override + public Integer getServerSocketPort( + HttpServletRequest request, @Nullable HttpServletResponse response) { + return request.getLocalPort(); + } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcNetAttributesGetter.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcNetAttributesGetter.java deleted file mode 100644 index 6e67255f0ff6..000000000000 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcNetAttributesGetter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.spring.webmvc.v6_0; - -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import javax.annotation.Nullable; - -enum SpringWebMvcNetAttributesGetter - implements NetServerAttributesGetter { - INSTANCE; - - @Nullable - @Override - public String getNetworkProtocolName( - HttpServletRequest request, @Nullable HttpServletResponse response) { - String protocol = request.getProtocol(); - if (protocol != null && protocol.startsWith("HTTP/")) { - return "http"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - HttpServletRequest request, @Nullable HttpServletResponse response) { - String protocol = request.getProtocol(); - if (protocol != null && protocol.startsWith("HTTP/")) { - return protocol.substring("HTTP/".length()); - } - 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 getClientSocketAddress( - HttpServletRequest request, @Nullable HttpServletResponse response) { - return request.getRemoteAddr(); - } - - @Override - public Integer getClientSocketPort( - HttpServletRequest request, @Nullable HttpServletResponse response) { - return request.getRemotePort(); - } - - @Nullable - @Override - public String getServerSocketAddress( - HttpServletRequest request, @Nullable HttpServletResponse response) { - return request.getLocalAddr(); - } - - @Override - public Integer getServerSocketPort( - HttpServletRequest request, @Nullable HttpServletResponse response) { - return request.getLocalPort(); - } -} diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index f1aabe7f2bc5..dfe67944605e 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java @@ -34,8 +34,7 @@ public final class SpringWebMvcTelemetryBuilder { additionalExtractors = new ArrayList<>(); private final HttpServerAttributesExtractorBuilder httpAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder( - SpringWebMvcHttpAttributesGetter.INSTANCE, SpringWebMvcNetAttributesGetter.INSTANCE); + HttpServerAttributesExtractor.builder(SpringWebMvcHttpAttributesGetter.INSTANCE); @Nullable private Function< 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 60b89046a4b2..9a35d383e9b5 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 @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.List; import javax.annotation.Nullable; +import org.apache.coyote.ActionCode; import org.apache.coyote.Request; import org.apache.coyote.Response; import org.apache.tomcat.util.buf.MessageBytes; @@ -57,4 +58,63 @@ public Integer getHttpResponseStatusCode( public List getHttpResponseHeader(Request request, Response response, String name) { return Collections.list(response.getMimeHeaders().values(name)); } + + @Nullable + @Override + public String getNetworkProtocolName(Request request, @Nullable Response response) { + String protocol = messageBytesToString(request.protocol()); + if (protocol != null && protocol.startsWith("HTTP/")) { + return "http"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { + String protocol = messageBytesToString(request.protocol()); + if (protocol != null && protocol.startsWith("HTTP/")) { + return protocol.substring("HTTP/".length()); + } + 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 getClientSocketAddress(Request request, @Nullable Response response) { + request.action(ActionCode.REQ_HOST_ADDR_ATTRIBUTE, request); + return messageBytesToString(request.remoteAddr()); + } + + @Override + @Nullable + public Integer getClientSocketPort(Request request, @Nullable Response response) { + request.action(ActionCode.REQ_REMOTEPORT_ATTRIBUTE, request); + return request.getRemotePort(); + } + + @Nullable + @Override + public String getServerSocketAddress(Request request, @Nullable Response response) { + request.action(ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE, request); + return messageBytesToString(request.localAddr()); + } + + @Nullable + @Override + public Integer getServerSocketPort(Request request, @Nullable Response response) { + request.action(ActionCode.REQ_LOCALPORT_ATTRIBUTE, request); + return request.getLocalPort(); + } } diff --git a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterFactory.java b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterFactory.java index 4c048f103621..9b5baa5ea058 100644 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterFactory.java +++ b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterFactory.java @@ -26,7 +26,6 @@ private TomcatInstrumenterFactory() {} public static Instrumenter create( String instrumentationName, ServletAccessor accessor) { TomcatHttpAttributesGetter httpAttributesGetter = new TomcatHttpAttributesGetter(); - TomcatNetAttributesGetter netAttributesGetter = new TomcatNetAttributesGetter(); return Instrumenter.builder( GlobalOpenTelemetry.get(), @@ -35,7 +34,7 @@ public static Instrumenter create( .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .setErrorCauseExtractor(new ServletErrorCauseExtractor<>(accessor)) .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) + HttpServerAttributesExtractor.builder(httpAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .setKnownMethods(CommonConfig.get().getKnownHttpRequestMethods()) 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 deleted file mode 100644 index 92434ceced35..000000000000 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesGetter.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.tomcat.common; - -import static io.opentelemetry.javaagent.instrumentation.tomcat.common.TomcatHelper.messageBytesToString; - -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import javax.annotation.Nullable; -import org.apache.coyote.ActionCode; -import org.apache.coyote.Request; -import org.apache.coyote.Response; - -public class TomcatNetAttributesGetter implements NetServerAttributesGetter { - - @Nullable - @Override - public String getNetworkProtocolName(Request request, @Nullable Response response) { - String protocol = messageBytesToString(request.protocol()); - if (protocol != null && protocol.startsWith("HTTP/")) { - return "http"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolVersion(Request request, @Nullable Response response) { - String protocol = messageBytesToString(request.protocol()); - if (protocol != null && protocol.startsWith("HTTP/")) { - return protocol.substring("HTTP/".length()); - } - 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 getClientSocketAddress(Request request, @Nullable Response response) { - request.action(ActionCode.REQ_HOST_ADDR_ATTRIBUTE, request); - return messageBytesToString(request.remoteAddr()); - } - - @Override - @Nullable - public Integer getClientSocketPort(Request request, @Nullable Response response) { - request.action(ActionCode.REQ_REMOTEPORT_ATTRIBUTE, request); - return request.getRemotePort(); - } - - @Nullable - @Override - public String getServerSocketAddress(Request request, @Nullable Response response) { - request.action(ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE, request); - return messageBytesToString(request.localAddr()); - } - - @Nullable - @Override - public Integer getServerSocketPort(Request request, @Nullable Response response) { - 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/UndertowHttpAttributesGetter.java b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowHttpAttributesGetter.java index c54ebd27c53d..ae52ba37d7aa 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 @@ -8,6 +8,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; import io.undertow.server.HttpServerExchange; import io.undertow.util.HeaderValues; +import java.net.InetSocketAddress; import java.util.Collections; import java.util.List; import javax.annotation.Nullable; @@ -56,4 +57,52 @@ public String getUrlPath(HttpServerExchange exchange) { public String getUrlQuery(HttpServerExchange exchange) { return exchange.getQueryString(); } + + @Nullable + @Override + public String getNetworkProtocolName( + HttpServerExchange exchange, @Nullable HttpServerExchange unused) { + String protocol = exchange.getProtocol().toString(); + if (protocol.startsWith("HTTP/")) { + return "http"; + } + return null; + } + + @Nullable + @Override + public String getNetworkProtocolVersion( + HttpServerExchange exchange, @Nullable HttpServerExchange unused) { + String protocol = exchange.getProtocol().toString(); + if (protocol.startsWith("HTTP/")) { + return protocol.substring("HTTP/".length()); + } + 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 getClientInetSocketAddress( + HttpServerExchange exchange, @Nullable HttpServerExchange unused) { + return exchange.getConnection().getPeerAddress(InetSocketAddress.class); + } + + @Nullable + @Override + public InetSocketAddress getServerInetSocketAddress( + HttpServerExchange exchange, @Nullable HttpServerExchange unused) { + return exchange.getConnection().getLocalAddress(InetSocketAddress.class); + } } 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 deleted file mode 100644 index e89854faf872..000000000000 --- a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowNetAttributesGetter.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.undertow; - -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import io.undertow.server.HttpServerExchange; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; - -public class UndertowNetAttributesGetter - implements NetServerAttributesGetter { - - @Nullable - @Override - public String getNetworkProtocolName( - HttpServerExchange exchange, @Nullable HttpServerExchange unused) { - String protocol = exchange.getProtocol().toString(); - if (protocol.startsWith("HTTP/")) { - return "http"; - } - return null; - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - HttpServerExchange exchange, @Nullable HttpServerExchange unused) { - String protocol = exchange.getProtocol().toString(); - if (protocol.startsWith("HTTP/")) { - return protocol.substring("HTTP/".length()); - } - 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 getClientInetSocketAddress( - HttpServerExchange exchange, @Nullable HttpServerExchange unused) { - return exchange.getConnection().getPeerAddress(InetSocketAddress.class); - } - - @Nullable - @Override - public InetSocketAddress getServerInetSocketAddress( - HttpServerExchange exchange, @Nullable HttpServerExchange unused) { - return exchange.getConnection().getLocalAddress(InetSocketAddress.class); - } -} diff --git a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java index 0acc237ee9ea..2e694bcce3a1 100644 --- a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java +++ b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java @@ -24,7 +24,6 @@ public final class UndertowSingletons { static { UndertowHttpAttributesGetter httpAttributesGetter = new UndertowHttpAttributesGetter(); - UndertowNetAttributesGetter netAttributesGetter = new UndertowNetAttributesGetter(); INSTRUMENTER = Instrumenter.builder( @@ -33,7 +32,7 @@ public final class UndertowSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) + HttpServerAttributesExtractor.builder(httpAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .setKnownMethods(CommonConfig.get().getKnownHttpRequestMethods()) 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 0f5ef5d7fa41..2205f2f2c998 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 @@ -22,7 +22,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.instrumentation.api.internal.SpanKey; import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier; @@ -50,9 +49,7 @@ final class TestInstrumenters { Instrumenter.builder( openTelemetry, "test", HttpSpanNameExtractor.create(HttpServerGetter.INSTANCE)) // cover both semconv and span-kind strategies - .addAttributesExtractor( - HttpServerAttributesExtractor.create( - HttpServerGetter.INSTANCE, NetServerGetter.INSTANCE)) + .addAttributesExtractor(HttpServerAttributesExtractor.create(HttpServerGetter.INSTANCE)) .addAttributesExtractor(new SpanKeyAttributesExtractor(SpanKey.KIND_SERVER)) .addContextCustomizer(HttpRouteHolder.create(HttpServerGetter.INSTANCE)) .buildInstrumenter(SpanKindExtractor.alwaysServer()); @@ -180,10 +177,6 @@ public String getUrlPath(String s) { public String getUrlQuery(String s) { return null; } - } - - private enum NetServerGetter implements NetServerAttributesGetter { - INSTANCE; @Nullable @Override