diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java index 816cc66fcd99..2c51b4226aaa 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java @@ -98,7 +98,8 @@ public static HttpClientAttributesExtractorBuilder HttpServerAttributesExtractorBuilder httpAttributesGetter, NetServerAttributesGetter netAttributesGetter, List capturedRequestHeaders, - List capturedResponseHeaders) { + List capturedResponseHeaders, + boolean captureServerSocketAttributes) { this( httpAttributesGetter, netAttributesGetter, capturedRequestHeaders, capturedResponseHeaders, + captureServerSocketAttributes, HttpRouteHolder::getRoute); } @@ -93,6 +95,7 @@ public static HttpServerAttributesExtractorBuilder netAttributesGetter, List capturedRequestHeaders, List capturedResponseHeaders, + boolean captureServerSocketAttributes, Function httpRouteHolderGetter) { super(httpAttributesGetter, capturedRequestHeaders, capturedResponseHeaders); HttpNetNamePortGetter namePortGetter = @@ -119,7 +122,8 @@ public static HttpServerAttributesExtractorBuilder( netAttributesGetter, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java index eccb8ba08175..06ad4ad9922f 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java @@ -19,6 +19,7 @@ public final class HttpServerAttributesExtractorBuilder { final NetServerAttributesGetter netAttributesGetter; List capturedRequestHeaders = emptyList(); List capturedResponseHeaders = emptyList(); + boolean captureServerSocketAttributes = false; HttpServerAttributesExtractorBuilder( HttpServerAttributesGetter httpAttributesGetter, @@ -64,12 +65,30 @@ public HttpServerAttributesExtractorBuilder setCapturedRespon return this; } + /** + * Configures the extractor to capture the optional {@code server.socket.address} and {@code + * server.socket.port} attributes, which are not collected by default. + * + * @param captureServerSocketAttributes {@code true} if the extractor should collect the optional + * {@code server.socket.address} and {@code server.socket.port} attributes. + */ + @CanIgnoreReturnValue + public HttpServerAttributesExtractorBuilder setCaptureServerSocketAttributes( + boolean captureServerSocketAttributes) { + this.captureServerSocketAttributes = captureServerSocketAttributes; + return this; + } + /** * Returns a new {@link HttpServerAttributesExtractor} with the settings of this {@link * HttpServerAttributesExtractorBuilder}. */ public AttributesExtractor build() { return new HttpServerAttributesExtractor<>( - httpAttributesGetter, netAttributesGetter, capturedRequestHeaders, capturedResponseHeaders); + httpAttributesGetter, + netAttributesGetter, + capturedRequestHeaders, + capturedResponseHeaders, + captureServerSocketAttributes); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java index 5fc580f04bf9..5bf414697691 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java @@ -54,7 +54,8 @@ private NetClientAttributesExtractor(NetClientAttributesGetter( getter, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java index c622da9adb64..159962d93e0e 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java @@ -41,7 +41,8 @@ public static ServerAttributesExtractor c /* emitStableUrlAttributes= */ true, /* emitOldHttpAttributes= */ false, // this param does not matter when old semconv is off - InternalServerAttributesExtractor.Mode.HOST); + InternalServerAttributesExtractor.Mode.HOST, + /* captureServerSocketAttributes= */ true); } @Override diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java index 68e4ef1db9ce..742f1e334679 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java @@ -27,6 +27,7 @@ public final class InternalServerAttributesExtractor { private final boolean emitStableUrlAttributes; private final boolean emitOldHttpAttributes; private final Mode oldSemconvMode; + private final boolean captureServerSocketAttributes; public InternalServerAttributesExtractor( ServerAttributesGetter getter, @@ -34,13 +35,15 @@ public InternalServerAttributesExtractor( FallbackNamePortGetter fallbackNamePortGetter, boolean emitStableUrlAttributes, boolean emitOldHttpAttributes, - Mode oldSemconvMode) { + Mode oldSemconvMode, + boolean captureServerSocketAttributes) { this.getter = getter; this.captureServerPortCondition = captureServerPortCondition; this.fallbackNamePortGetter = fallbackNamePortGetter; this.emitStableUrlAttributes = emitStableUrlAttributes; this.emitOldHttpAttributes = emitOldHttpAttributes; this.oldSemconvMode = oldSemconvMode; + this.captureServerSocketAttributes = captureServerSocketAttributes; } public void onStart(AttributesBuilder attributes, REQUEST request) { @@ -73,7 +76,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO String serverSocketAddress = getter.getServerSocketAddress(request, response); if (serverSocketAddress != null && !serverSocketAddress.equals(serverAddress)) { - if (emitStableUrlAttributes) { + if (emitStableUrlAttributes && captureServerSocketAttributes) { internalSet(attributes, NetworkAttributes.SERVER_SOCKET_ADDRESS, serverSocketAddress); } if (emitOldHttpAttributes) { @@ -85,7 +88,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO if (serverSocketPort != null && serverSocketPort > 0 && !serverSocketPort.equals(serverPort)) { - if (emitStableUrlAttributes) { + if (emitStableUrlAttributes && captureServerSocketAttributes) { internalSet(attributes, NetworkAttributes.SERVER_SOCKET_PORT, (long) serverSocketPort); } if (emitOldHttpAttributes) { @@ -95,7 +98,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO String serverSocketDomain = getter.getServerSocketDomain(request, response); if (serverSocketDomain != null && !serverSocketDomain.equals(serverAddress)) { - if (emitStableUrlAttributes) { + if (emitStableUrlAttributes && captureServerSocketAttributes) { internalSet(attributes, NetworkAttributes.SERVER_SOCKET_DOMAIN, serverSocketDomain); } if (emitOldHttpAttributes && oldSemconvMode.socketDomain != null) { 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 ab2fcc33f3fd..6fd9fa5fbac7 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 @@ -162,6 +162,7 @@ void normal() { new TestNetServerAttributesGetter(), singletonList("Custom-Request-Header"), singletonList("Custom-Response-Header"), + false, routeFromContext); AttributesBuilder startAttributes = Attributes.builder(); 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 8f926a62da85..18b5121b64b6 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 @@ -156,6 +156,7 @@ void normal() { new TestNetServerAttributesGetter(), singletonList("Custom-Request-Header"), singletonList("Custom-Response-Header"), + false, routeFromContext); AttributesBuilder startAttributes = Attributes.builder(); 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 ea26ec3591ad..9e4b273a8267 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 @@ -38,103 +38,119 @@ class HttpServerAttributesExtractorStableSemconvTest { static class TestHttpServerAttributesGetter - implements HttpServerAttributesGetter, Map> { + implements HttpServerAttributesGetter, Map> { @Override - public String getHttpRequestMethod(Map request) { - return (String) request.get("method"); + public String getHttpRequestMethod(Map request) { + return request.get("method"); } @Override - public String getUrlScheme(Map request) { - return (String) request.get("scheme"); + public String getUrlScheme(Map request) { + return request.get("scheme"); } @Nullable @Override - public String getUrlPath(Map request) { - return (String) request.get("path"); + public String getUrlPath(Map request) { + return request.get("path"); } @Nullable @Override - public String getUrlQuery(Map request) { - return (String) request.get("query"); + public String getUrlQuery(Map request) { + return request.get("query"); } @Override - public String getHttpRoute(Map request) { - return (String) request.get("route"); + public String getHttpRoute(Map request) { + return request.get("route"); } @Override - public List getHttpRequestHeader(Map request, String name) { - String values = (String) request.get("header." + name); + public List getHttpRequestHeader(Map request, String name) { + String values = request.get("header." + name); return values == null ? emptyList() : asList(values.split(",")); } @Override public Integer getHttpResponseStatusCode( - Map request, Map response, @Nullable Throwable error) { - String value = (String) response.get("statusCode"); + Map request, Map response, @Nullable Throwable error) { + String value = response.get("statusCode"); return value == null ? null : Integer.parseInt(value); } @Override public List getHttpResponseHeader( - Map request, Map response, String name) { - String values = (String) response.get("header." + name); + Map request, Map response, String name) { + String values = response.get("header." + name); return values == null ? emptyList() : asList(values.split(",")); } } static class TestNetServerAttributesGetter - implements NetServerAttributesGetter, Map> { + implements NetServerAttributesGetter, Map> { @Nullable @Override public String getNetworkTransport( - Map request, @Nullable Map response) { - return (String) request.get("transport"); + Map request, @Nullable Map response) { + return request.get("transport"); } @Nullable @Override public String getNetworkType( - Map request, @Nullable Map response) { - return (String) request.get("type"); + Map request, @Nullable Map response) { + return request.get("type"); } @Nullable @Override public String getNetworkProtocolName( - Map request, Map response) { - return (String) request.get("protocolName"); + Map request, Map response) { + return request.get("protocolName"); } @Nullable @Override public String getNetworkProtocolVersion( - Map request, Map response) { - return (String) request.get("protocolVersion"); + Map request, Map response) { + return request.get("protocolVersion"); } @Nullable @Override - public String getServerAddress(Map request) { - return (String) request.get("hostName"); + public String getServerAddress(Map request) { + return request.get("hostName"); } @Nullable @Override - public Integer getServerPort(Map request) { - return (Integer) request.get("hostPort"); + public Integer getServerPort(Map request) { + String value = request.get("hostPort"); + return value == null ? null : Integer.parseInt(value); + } + + @Nullable + @Override + public String getServerSocketAddress( + Map request, @Nullable Map response) { + return request.get("serverSocketAddress"); + } + + @Nullable + @Override + public Integer getServerSocketPort( + Map request, @Nullable Map response) { + String value = request.get("serverSocketPort"); + return value == null ? null : Integer.parseInt(value); } } @Test void normal() { - Map request = new HashMap<>(); + Map request = new HashMap<>(); request.put("method", "POST"); request.put("url", "http://github.com"); request.put("path", "/repositories/1"); @@ -150,20 +166,23 @@ void normal() { request.put("type", "ipv4"); request.put("protocolName", "http"); request.put("protocolVersion", "2.0"); + request.put("serverSocketAddress", "1.2.3.4"); + request.put("serverSocketPort", "42"); - Map response = new HashMap<>(); + Map response = new HashMap<>(); response.put("statusCode", "202"); response.put("header.content-length", "20"); response.put("header.custom-response-header", "654,321"); Function routeFromContext = ctx -> "/repositories/{repoId}"; - HttpServerAttributesExtractor, Map> extractor = + HttpServerAttributesExtractor, Map> extractor = new HttpServerAttributesExtractor<>( new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter(), singletonList("Custom-Request-Header"), singletonList("Custom-Response-Header"), + false, routeFromContext); AttributesBuilder startAttributes = Attributes.builder(); @@ -212,9 +231,8 @@ void skipNetworkTransportIfDefaultForProtocol( request.put("transport", observedTransport); AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create( - new HttpClientAttributesExtractorStableSemconvTest.TestHttpClientAttributesGetter(), - new HttpClientAttributesExtractorStableSemconvTest.TestNetClientAttributesGetter()); + HttpServerAttributesExtractor.create( + new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); @@ -243,4 +261,26 @@ public Stream provideArguments(ExtensionContext context) { arguments("http", "42", "tcp", "tcp")); } } + + @Test + void optInServerSocketAttributes() { + Map request = new HashMap<>(); + request.put("serverSocketAddress", "1.2.3.4"); + request.put("serverSocketPort", "42"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.builder( + new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + .setCaptureServerSocketAttributes(true) + .build(); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + assertThat(attributes.build()) + .containsOnly( + entry(NetworkAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.SERVER_SOCKET_PORT, 42L)); + } } 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 f676fbe503c7..61d508e45c3a 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 @@ -34,6 +34,8 @@ public final class AkkaHttpServerSingletons { httpAttributesGetter, new AkkaNetServerAttributesGetter()) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) + .setCaptureServerSocketAttributes( + CommonConfig.get().getCaptureHttpServerSocketAttributes()) .build()) .addOperationMetrics(HttpServerMetrics.get()) .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) 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 1064701270b8..414b14b207bf 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 @@ -35,6 +35,8 @@ public final class GrizzlySingletons { HttpServerAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) + .setCaptureServerSocketAttributes( + CommonConfig.get().getCaptureHttpServerSocketAttributes()) .build()) .addOperationMetrics(HttpServerMetrics.get()) .addContextCustomizer( 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 d96eefc1bf83..3326e77e1a5b 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 @@ -35,6 +35,8 @@ public final class LibertyDispatcherSingletons { HttpServerAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) + .setCaptureServerSocketAttributes( + CommonConfig.get().getCaptureHttpServerSocketAttributes()) .build()) .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .addOperationMetrics(HttpServerMetrics.get()) 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 cc99eb009d7c..2ccb634653d8 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 @@ -36,6 +36,8 @@ final class NettyServerSingletons { httpServerAttributesGetter, new NettyNetServerAttributesGetter()) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) + .setCaptureServerSocketAttributes( + CommonConfig.get().getCaptureHttpServerSocketAttributes()) .build()) .addOperationMetrics(HttpServerMetrics.get()) .addContextCustomizer( 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 2dc9c3446837..34ae8047fdac 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 @@ -27,7 +27,8 @@ public static Instrumenter create( OpenTelemetry openTelemetry, String instrumentationName, List capturedRequestHeaders, - List capturedResponseHeaders) { + List capturedResponseHeaders, + boolean captureServerSocketAttributes) { NettyHttpServerAttributesGetter httpAttributesGetter = new NettyHttpServerAttributesGetter(); @@ -39,6 +40,7 @@ public static Instrumenter create( httpAttributesGetter, new NettyNetServerAttributesGetter()) .setCapturedRequestHeaders(capturedRequestHeaders) .setCapturedResponseHeaders(capturedResponseHeaders) + .setCaptureServerSocketAttributes(captureServerSocketAttributes) .build()) .addOperationMetrics(HttpServerMetrics.get()) .addContextCustomizer((context, request, attributes) -> NettyErrorHolder.init(context)) diff --git a/instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/server/NettyServerSingletons.java b/instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/server/NettyServerSingletons.java index 6af51fad8b4d..a253f1da3f04 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/server/NettyServerSingletons.java +++ b/instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/server/NettyServerSingletons.java @@ -19,7 +19,8 @@ public final class NettyServerSingletons { GlobalOpenTelemetry.get(), "io.opentelemetry.netty-4.0", CommonConfig.get().getServerRequestHeaders(), - CommonConfig.get().getServerResponseHeaders()); + CommonConfig.get().getServerResponseHeaders(), + CommonConfig.get().getCaptureHttpServerSocketAttributes()); public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyServerSingletons.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyServerSingletons.java index c4239f6b0d40..c51c0d78b3f0 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyServerSingletons.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyServerSingletons.java @@ -19,7 +19,8 @@ public final class NettyServerSingletons { GlobalOpenTelemetry.get(), "io.opentelemetry.netty-4.1", CommonConfig.get().getServerRequestHeaders(), - CommonConfig.get().getServerResponseHeaders()); + CommonConfig.get().getServerResponseHeaders(), + CommonConfig.get().getCaptureHttpServerSocketAttributes()); public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java index 9e802cfae9c2..688c169c369d 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java @@ -17,6 +17,7 @@ public final class NettyServerTelemetryBuilder { private final OpenTelemetry openTelemetry; private List capturedRequestHeaders = Collections.emptyList(); private List capturedResponseHeaders = Collections.emptyList(); + boolean captureServerSocketAttributes = false; NettyServerTelemetryBuilder(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; @@ -46,6 +47,20 @@ public NettyServerTelemetryBuilder setCapturedResponseHeaders( return this; } + /** + * Configures the instrumentation to capture the optional {@code server.socket.address} and {@code + * server.socket.port} attributes, which are not collected by default. + * + * @param captureServerSocketAttributes {@code true} if the optional {@code server.socket.address} + * and {@code server.socket.port} attributes should be collected. + */ + @CanIgnoreReturnValue + public NettyServerTelemetryBuilder setCaptureServerSocketAttributes( + boolean captureServerSocketAttributes) { + this.captureServerSocketAttributes = captureServerSocketAttributes; + return this; + } + /** Returns a new {@link NettyServerTelemetry} with the given configuration. */ public NettyServerTelemetry build() { return new NettyServerTelemetry( @@ -53,6 +68,7 @@ public NettyServerTelemetry build() { openTelemetry, "io.opentelemetry.netty-4.1", capturedRequestHeaders, - capturedResponseHeaders)); + capturedResponseHeaders, + captureServerSocketAttributes)); } } diff --git a/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java b/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java index 76ae94863e9d..b1fe3ee0446e 100644 --- a/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java +++ b/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java @@ -20,6 +20,8 @@ public final class RestletSingletons { RestletTelemetry.builder(GlobalOpenTelemetry.get()) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) + .setCaptureServerSocketAttributes( + CommonConfig.get().getCaptureHttpServerSocketAttributes()) .build() .getServerInstrumenter(); 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 45f34ac8de23..07bbb4eb671b 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 @@ -70,6 +70,20 @@ public RestletTelemetryBuilder setCapturedResponseHeaders(List responseH return this; } + /** + * Configures the instrumentation to capture the optional {@code server.socket.address} and {@code + * server.socket.port} attributes, which are not collected by default. + * + * @param captureServerSocketAttributes {@code true} if the optional {@code server.socket.address} + * and {@code server.socket.port} attributes should be collected. + */ + @CanIgnoreReturnValue + public RestletTelemetryBuilder setCaptureServerSocketAttributes( + boolean captureServerSocketAttributes) { + httpAttributesExtractorBuilder.setCaptureServerSocketAttributes(captureServerSocketAttributes); + return this; + } + /** * Returns a new {@link RestletTelemetry} with the settings of this {@link * RestletTelemetryBuilder}. 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 1526fd2a5b2a..d9883dfbfb67 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 @@ -27,6 +27,8 @@ public final class RestletSingletons { RestletHttpAttributesGetter.INSTANCE, new RestletNetAttributesGetter()) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) + .setCaptureServerSocketAttributes( + CommonConfig.get().getCaptureHttpServerSocketAttributes()) .build(), Collections.emptyList()); 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 434ad3a6262e..41d4899b1841 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 @@ -63,6 +63,8 @@ public Instrumenter, ServletResponseContext Instrumenter create( HttpServerAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) + .setCaptureServerSocketAttributes( + CommonConfig.get().getCaptureHttpServerSocketAttributes()) .build()) .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .addContextCustomizer( 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 7f2f786b1c37..31b1ed73f8b5 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 @@ -36,6 +36,8 @@ public final class UndertowSingletons { HttpServerAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) + .setCaptureServerSocketAttributes( + CommonConfig.get().getCaptureHttpServerSocketAttributes()) .build()) .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .addContextCustomizer( diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/CommonConfig.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/CommonConfig.java index 7072f64809c9..16ec8b7c58a1 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/CommonConfig.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/CommonConfig.java @@ -28,19 +28,36 @@ public static CommonConfig get() { private final List clientResponseHeaders; private final List serverRequestHeaders; private final List serverResponseHeaders; + private final boolean captureHttpServerSocketAttributes; private final boolean statementSanitizationEnabled; CommonConfig(InstrumentationConfig config) { peerServiceMapping = config.getMap("otel.instrumentation.common.peer-service-mapping", emptyMap()); + // TODO (mateusz): remove the old config names in 2.0 clientRequestHeaders = - config.getList("otel.instrumentation.http.capture-headers.client.request", emptyList()); + config.getList( + "otel.instrumentation.http.client.capture-request-headers", + config.getList( + "otel.instrumentation.http.capture-headers.client.request", emptyList())); clientResponseHeaders = - config.getList("otel.instrumentation.http.capture-headers.client.response", emptyList()); + config.getList( + "otel.instrumentation.http.client.capture-response-headers", + config.getList( + "otel.instrumentation.http.capture-headers.client.response", emptyList())); serverRequestHeaders = - config.getList("otel.instrumentation.http.capture-headers.server.request", emptyList()); + config.getList( + "otel.instrumentation.http.server.capture-request-headers", + config.getList( + "otel.instrumentation.http.capture-headers.server.request", emptyList())); serverResponseHeaders = - config.getList("otel.instrumentation.http.capture-headers.server.response", emptyList()); + config.getList( + "otel.instrumentation.http.server.capture-response-headers", + config.getList( + "otel.instrumentation.http.capture-headers.server.response", emptyList())); + captureHttpServerSocketAttributes = + config.getBoolean( + "otel.instrumentation.http.server.capture-server-socket-attributes", false); statementSanitizationEnabled = config.getBoolean("otel.instrumentation.common.db-statement-sanitizer.enabled", true); } @@ -65,6 +82,10 @@ public List getServerResponseHeaders() { return serverResponseHeaders; } + public boolean getCaptureHttpServerSocketAttributes() { + return captureHttpServerSocketAttributes; + } + public boolean isStatementSanitizationEnabled() { return statementSanitizationEnabled; }