From 9f7378df08f820217b7658173c5c45c37318657d Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Mon, 21 Nov 2022 12:20:52 +0100 Subject: [PATCH 1/4] HTTP semconv: filter out default peer/host ports --- .../http/HttpClientAttributesExtractor.java | 85 ++++++++++- .../HttpClientAttributesExtractorBuilder.java | 13 +- .../http/HttpServerAttributesExtractor.java | 24 +++- .../net/NetClientAttributesExtractor.java | 43 +----- .../net/NetServerAttributesExtractor.java | 7 +- .../InternalNetClientAttributesExtractor.java | 73 ++++++++++ .../InternalNetServerAttributesExtractor.java | 21 +-- .../HttpClientAttributesExtractorTest.java | 132 +++++++++++++----- .../HttpServerAttributesExtractorTest.java | 35 +++++ .../instrumenter/InstrumenterBenchmark.java | 30 ++-- .../client/AkkaHttpClientSingletons.java | 4 +- .../ApacheHttpAsyncClientSingletons.java | 4 +- .../v2_0/ApacheHttpClientSingletons.java | 4 +- .../v4_0/ApacheHttpClientSingletons.java | 4 +- .../ApacheHttpClientTelemetryBuilder.java | 8 +- .../v5_0/ApacheHttpClientSingletons.java | 4 +- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 10 +- .../v1_9/AsyncHttpClientSingletons.java | 4 +- .../v2_0/AsyncHttpClientSingletons.java | 4 +- .../v1_11/AwsSdkInstrumenterFactory.java | 14 +- .../v2_2/AwsSdkInstrumenterFactory.java | 17 +-- .../GoogleHttpClientSingletons.java | 4 +- .../HttpUrlConnectionSingletons.java | 4 +- .../httpclient/JdkHttpClientSingletons.java | 4 +- .../v1_1/JaxRsClientSingletons.java | 4 +- .../JettyClientInstrumenterBuilder.java | 7 +- .../KubernetesClientSingletons.java | 13 +- .../v3_8/client/NettyClientSingletons.java | 19 ++- .../NettyClientInstrumenterFactory.java | 12 +- .../okhttp/v2_2/OkHttp2Singletons.java | 8 +- .../okhttp/v3_0/OkHttpTelemetryBuilder.java | 6 +- .../PlayWsClientInstrumenterFactory.java | 4 +- .../ratpack/RatpackTelemetryBuilder.java | 12 +- ... => RatpackNetClientAttributesGetter.java} | 2 +- ... => RatpackNetServerAttributesGetter.java} | 2 +- .../v1_0/ReactorNettySingletons.java | 4 +- .../spring/web/SpringWebTelemetryBuilder.java | 6 +- .../client/SpringWebfluxTelemetryBuilder.java | 6 +- .../client/Vertx3NetAttributesGetter.java | 54 +++++++ .../v3_0/client/VertxClientSingletons.java | 4 +- .../client/Vertx4NetAttributesGetter.java | 33 +++-- .../VertxClientInstrumenterFactory.java | 18 +-- .../junit/http/AbstractHttpClientTest.java | 26 ++-- .../junit/http/AbstractHttpServerTest.java | 1 + 44 files changed, 498 insertions(+), 295 deletions(-) create mode 100644 instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java rename instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/{RatpackHttpNetAttributesGetter.java => RatpackNetClientAttributesGetter.java} (95%) rename instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/{RatpackNetAttributesGetter.java => RatpackNetServerAttributesGetter.java} (93%) create mode 100644 instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/Vertx3NetAttributesGetter.java 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 e5053a40ee1e..290dee6d29e9 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 @@ -9,6 +9,8 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.internal.SpanKey; import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @@ -29,32 +31,78 @@ public final class HttpClientAttributesExtractor REQUEST, RESPONSE, HttpClientAttributesGetter> implements SpanKeyProvider { - /** Creates the HTTP client attributes extractor with default configuration. */ + /** + * Creates the HTTP client attributes extractor with default configuration. + * + * @deprecated Use {@link #create(HttpClientAttributesGetter, NetClientAttributesGetter)} instead. + */ + @Deprecated public static HttpClientAttributesExtractor create( HttpClientAttributesGetter getter) { return builder(getter).build(); } + /** Creates the HTTP client attributes extractor with default configuration. */ + public static HttpClientAttributesExtractor create( + HttpClientAttributesGetter httpAttributesGetter, + NetClientAttributesGetter netAttributesGetter) { + return builder(httpAttributesGetter, netAttributesGetter).build(); + } + /** * Returns a new {@link HttpClientAttributesExtractorBuilder} that can be used to configure the * HTTP client attributes extractor. + * + * @deprecated Use {@link #builder(HttpClientAttributesGetter, NetClientAttributesGetter)} + * instead. */ + @Deprecated public static HttpClientAttributesExtractorBuilder builder( - HttpClientAttributesGetter getter) { - return new HttpClientAttributesExtractorBuilder<>(getter); + HttpClientAttributesGetter httpAttributesGetter) { + return builder(httpAttributesGetter, new NoopNetClientAttributesGetter<>()); } + /** + * Returns a new {@link HttpClientAttributesExtractorBuilder} that can be used to configure the + * HTTP client attributes extractor. + */ + public static HttpClientAttributesExtractorBuilder builder( + HttpClientAttributesGetter httpAttributesGetter, + NetClientAttributesGetter netAttributesGetter) { + return new HttpClientAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter); + } + + private final InternalNetClientAttributesExtractor internalNetExtractor; + HttpClientAttributesExtractor( - HttpClientAttributesGetter getter, + HttpClientAttributesGetter httpAttributesGetter, + NetClientAttributesGetter netAttributesGetter, List capturedRequestHeaders, - List responseHeaders) { - super(getter, capturedRequestHeaders, responseHeaders); + List capturedResponseHeaders) { + super(httpAttributesGetter, capturedRequestHeaders, capturedResponseHeaders); + internalNetExtractor = + new InternalNetClientAttributesExtractor<>(netAttributesGetter, this::isValidNetPeerPort); } @Override public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { super.onStart(attributes, parentContext, request); + internalSet(attributes, SemanticAttributes.HTTP_URL, stripSensitiveData(getter.url(request))); + + internalNetExtractor.onStart(attributes, request); + } + + private boolean isValidNetPeerPort(int port, REQUEST request) { + String url = getter.url(request); + if (url == null) { + return true; + } + // according to spec: extract if not default (80 for http scheme, 443 for https). + if ((url.startsWith("http://") && port == 80) || (url.startsWith("https://") && port == 443)) { + return false; + } + return true; } @Nullable @@ -108,7 +156,10 @@ public void onEnd( @Nullable RESPONSE response, @Nullable Throwable error) { super.onEnd(attributes, context, request, response, error); + internalSet(attributes, SemanticAttributes.HTTP_FLAVOR, getter.flavor(request, response)); + + internalNetExtractor.onEnd(attributes, request, response); } /** @@ -119,4 +170,26 @@ public void onEnd( public SpanKey internalGetSpanKey() { return SpanKey.HTTP_CLIENT; } + + private static final class NoopNetClientAttributesGetter + implements NetClientAttributesGetter { + + @Nullable + @Override + public String transport(REQUEST request, @Nullable RESPONSE response) { + return null; + } + + @Nullable + @Override + public String peerName(REQUEST request) { + return null; + } + + @Nullable + @Override + public Integer peerPort(REQUEST request) { + return null; + } + } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java index 56bcab57708b..367fc1fd682d 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java @@ -8,17 +8,22 @@ import static java.util.Collections.emptyList; import com.google.errorprone.annotations.CanIgnoreReturnValue; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import java.util.List; /** A builder of {@link HttpClientAttributesExtractor}. */ public final class HttpClientAttributesExtractorBuilder { - final HttpClientAttributesGetter getter; + final HttpClientAttributesGetter httpAttributesGetter; + final NetClientAttributesGetter netAttributesGetter; List capturedRequestHeaders = emptyList(); List capturedResponseHeaders = emptyList(); - HttpClientAttributesExtractorBuilder(HttpClientAttributesGetter getter) { - this.getter = getter; + HttpClientAttributesExtractorBuilder( + HttpClientAttributesGetter httpAttributesGetter, + NetClientAttributesGetter netAttributesGetter) { + this.httpAttributesGetter = httpAttributesGetter; + this.netAttributesGetter = netAttributesGetter; } /** @@ -64,6 +69,6 @@ public HttpClientAttributesExtractorBuilder setCapturedRespon */ public HttpClientAttributesExtractor build() { return new HttpClientAttributesExtractor<>( - getter, capturedRequestHeaders, capturedResponseHeaders); + httpAttributesGetter, netAttributesGetter, capturedRequestHeaders, capturedResponseHeaders); } } 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 e319593fbafb..23e62a13f9da 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 @@ -77,7 +77,7 @@ public static HttpServerAttributesExtractorBuilder(httpAttributesGetter, netAttributesGetter); } - private final NetServerAttributesGetter netAttributesGetter; + private final InternalNetServerAttributesExtractor internalNetExtractor; private final Function httpRouteHolderGetter; HttpServerAttributesExtractor( @@ -98,10 +98,11 @@ public static HttpServerAttributesExtractorBuilder httpAttributesGetter, NetServerAttributesGetter netAttributesGetter, List capturedRequestHeaders, - List responseHeaders, + List capturedResponseHeaders, Function httpRouteHolderGetter) { - super(httpAttributesGetter, capturedRequestHeaders, responseHeaders); - this.netAttributesGetter = netAttributesGetter; + super(httpAttributesGetter, capturedRequestHeaders, capturedResponseHeaders); + internalNetExtractor = + new InternalNetServerAttributesExtractor<>(netAttributesGetter, this::isValidNetHostPort); this.httpRouteHolderGetter = httpRouteHolderGetter; } @@ -117,8 +118,19 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST internalSet(attributes, SemanticAttributes.HTTP_ROUTE, getter.route(request)); internalSet(attributes, SemanticAttributes.HTTP_CLIENT_IP, clientIp(request)); - InternalNetServerAttributesExtractor.onStart( - netAttributesGetter, attributes, request, host(request)); + internalNetExtractor.onStart(attributes, request, host(request)); + } + + private boolean isValidNetHostPort(int port, REQUEST request) { + String scheme = getter.scheme(request); + if (scheme == null) { + return true; + } + // according to spec: extract if not default (80 for http scheme, 443 for https). + if ((scheme.equals("http") && port == 80) || (scheme.equals("https") && port == 443)) { + return false; + } + return true; } @Override 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 aecb892553e7..7c5255bd7d77 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 @@ -5,12 +5,10 @@ package io.opentelemetry.instrumentation.api.instrumenter.net; -import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; - import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor; import javax.annotation.Nullable; /** @@ -25,7 +23,7 @@ public final class NetClientAttributesExtractor implements AttributesExtractor { - private final NetClientAttributesGetter getter; + private final InternalNetClientAttributesExtractor internalExtractor; public static NetClientAttributesExtractor create( NetClientAttributesGetter getter) { @@ -33,19 +31,12 @@ public static NetClientAttributesExtractor getter) { - this.getter = getter; + internalExtractor = new InternalNetClientAttributesExtractor<>(getter, (port, request) -> true); } @Override public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { - String peerName = getter.peerName(request); - Integer peerPort = getter.peerPort(request); - if (peerName != null) { - internalSet(attributes, SemanticAttributes.NET_PEER_NAME, peerName); - if (peerPort != null && peerPort > 0) { - internalSet(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort); - } - } + internalExtractor.onStart(attributes, request); } @Override @@ -55,30 +46,6 @@ public void onEnd( REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) { - - internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request, response)); - - String peerName = getter.peerName(request); - Integer peerPort = getter.peerPort(request); - - String sockPeerAddr = getter.sockPeerAddr(request, response); - if (sockPeerAddr != null && !sockPeerAddr.equals(peerName)) { - internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_ADDR, sockPeerAddr); - - Integer sockPeerPort = getter.sockPeerPort(request, response); - if (sockPeerPort != null && sockPeerPort > 0 && !sockPeerPort.equals(peerPort)) { - internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) sockPeerPort); - } - - String sockFamily = getter.sockFamily(request, response); - if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) { - internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily); - } - - String sockPeerName = getter.sockPeerName(request, response); - if (sockPeerName != null && !sockPeerName.equals(peerName)) { - internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_NAME, sockPeerName); - } - } + internalExtractor.onEnd(attributes, request, response); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java index 0a95d6dbdbd3..25095371998a 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java @@ -20,7 +20,7 @@ public final class NetServerAttributesExtractor implements AttributesExtractor { - private final NetServerAttributesGetter getter; + private final InternalNetServerAttributesExtractor internalExtractor; public static NetServerAttributesExtractor create( NetServerAttributesGetter getter) { @@ -28,12 +28,13 @@ public static NetServerAttributesExtractor getter) { - this.getter = getter; + internalExtractor = + new InternalNetServerAttributesExtractor<>(getter, (integer, request) -> true); } @Override public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { - InternalNetServerAttributesExtractor.onStart(getter, attributes, request, null); + internalExtractor.onStart(attributes, request, null); } @Override diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java new file mode 100644 index 000000000000..df487b564503 --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java @@ -0,0 +1,73 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.net.internal; + +import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; + +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.function.BiPredicate; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class InternalNetClientAttributesExtractor { + + private final NetClientAttributesGetter getter; + private final BiPredicate netPeerPortCondition; + + public InternalNetClientAttributesExtractor( + NetClientAttributesGetter getter, + BiPredicate netPeerPortCondition) { + this.getter = getter; + this.netPeerPortCondition = netPeerPortCondition; + } + + public void onStart(AttributesBuilder attributes, REQUEST request) { + String peerName = getter.peerName(request); + Integer peerPort = getter.peerPort(request); + + // TODO: add host header parsing + + if (peerName != null) { + internalSet(attributes, SemanticAttributes.NET_PEER_NAME, peerName); + if (peerPort != null && peerPort > 0 && netPeerPortCondition.test(peerPort, request)) { + internalSet(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort); + } + } + } + + public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) { + + internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request, response)); + + String peerName = getter.peerName(request); + Integer peerPort = getter.peerPort(request); + + String sockPeerAddr = getter.sockPeerAddr(request, response); + if (sockPeerAddr != null && !sockPeerAddr.equals(peerName)) { + internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_ADDR, sockPeerAddr); + + Integer sockPeerPort = getter.sockPeerPort(request, response); + if (sockPeerPort != null && sockPeerPort > 0 && !sockPeerPort.equals(peerPort)) { + internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) sockPeerPort); + } + + String sockFamily = getter.sockFamily(request, response); + if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) { + internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily); + } + + String sockPeerName = getter.sockPeerName(request, response); + if (sockPeerName != null && !sockPeerName.equals(peerName)) { + internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_NAME, sockPeerName); + } + } + } +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java index 5e1c22f9b738..f0464d9fd83f 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.function.BiPredicate; import java.util.logging.Logger; import javax.annotation.Nullable; @@ -18,16 +19,22 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class InternalNetServerAttributesExtractor { +public final class InternalNetServerAttributesExtractor { private static final Logger logger = Logger.getLogger(InternalNetServerAttributesExtractor.class.getName()); - public static void onStart( + private final NetServerAttributesGetter getter; + private final BiPredicate netHostPortCondition; + + public InternalNetServerAttributesExtractor( NetServerAttributesGetter getter, - AttributesBuilder attributes, - REQUEST request, - @Nullable String hostHeader) { + BiPredicate netHostPortCondition) { + this.getter = getter; + this.netHostPortCondition = netHostPortCondition; + } + + public void onStart(AttributesBuilder attributes, REQUEST request, @Nullable String hostHeader) { internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request)); boolean setSockFamily = false; @@ -66,7 +73,7 @@ public static void onStart( if (hostName != null) { internalSet(attributes, SemanticAttributes.NET_HOST_NAME, hostName); - if (hostPort != null && hostPort > 0) { + if (hostPort != null && hostPort > 0 && netHostPortCondition.test(hostPort, request)) { internalSet(attributes, SemanticAttributes.NET_HOST_PORT, (long) hostPort); } } @@ -90,6 +97,4 @@ public static void onStart( } } } - - private InternalNetServerAttributesExtractor() {} } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java index d99052a589e3..fba7ba9336f0 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -16,6 +17,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.List; @@ -23,9 +25,11 @@ import java.util.stream.Stream; import javax.annotation.Nullable; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; class HttpClientAttributesExtractorTest { @@ -67,6 +71,29 @@ public List responseHeader( } } + static class TestNetClientAttributesGetter + implements NetClientAttributesGetter, Map> { + + @Nullable + @Override + public String transport(Map request, @Nullable Map response) { + return response.get("transport"); + } + + @Nullable + @Override + public String peerName(Map request) { + return request.get("peerName"); + } + + @Nullable + @Override + public Integer peerPort(Map request) { + String statusCode = request.get("peerPort"); + return statusCode == null ? null : Integer.parseInt(statusCode); + } + } + @Test void normal() { Map request = new HashMap<>(); @@ -76,78 +103,82 @@ void normal() { request.put("flavor", "http/2"); request.put("header.user-agent", "okhttp 3.x"); request.put("header.custom-request-header", "123,456"); + request.put("peerName", "github.com"); + request.put("peerPort", "123"); Map response = new HashMap<>(); response.put("statusCode", "202"); response.put("header.content-length", "20"); response.put("header.custom-response-header", "654,321"); + response.put("transport", IP_TCP); HttpClientAttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()) + HttpClientAttributesExtractor.builder( + new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter()) .setCapturedRequestHeaders(singletonList("Custom-Request-Header")) .setCapturedResponseHeaders(singletonList("Custom-Response-Header")) .build(); - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - assertThat(attributes.build()) + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.HTTP_METHOD, "POST"), entry(SemanticAttributes.HTTP_URL, "http://github.com"), entry(SemanticAttributes.HTTP_USER_AGENT, "okhttp 3.x"), entry( AttributeKey.stringArrayKey("http.request.header.custom_request_header"), - asList("123", "456"))); + asList("123", "456")), + entry(SemanticAttributes.NET_PEER_NAME, "github.com"), + entry(SemanticAttributes.NET_PEER_PORT, 123L)); - extractor.onEnd(attributes, Context.root(), request, response, null); - assertThat(attributes.build()) + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) .containsOnly( - entry(SemanticAttributes.HTTP_METHOD, "POST"), - entry(SemanticAttributes.HTTP_URL, "http://github.com"), - entry(SemanticAttributes.HTTP_USER_AGENT, "okhttp 3.x"), - entry( - AttributeKey.stringArrayKey("http.request.header.custom_request_header"), - asList("123", "456")), entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L), entry(SemanticAttributes.HTTP_FLAVOR, "http/2"), entry(SemanticAttributes.HTTP_STATUS_CODE, 202L), entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L), entry( AttributeKey.stringArrayKey("http.response.header.custom_response_header"), - asList("654", "321"))); + asList("654", "321")), + entry(SemanticAttributes.NET_TRANSPORT, IP_TCP)); } @ParameterizedTest - @MethodSource("stripUrlArguments") + @ArgumentsSource(StripUrlArgumentSource.class) void stripBasicAuthTest(String url, String expectedResult) { Map request = new HashMap<>(); request.put("url", url); - stripRequestTest(request, expectedResult); - } - - private static Stream stripUrlArguments() { - return Stream.of( - arguments("https://user1:secret@github.com", "https://github.com"), - arguments("https://user1:secret@github.com/path/", "https://github.com/path/"), - arguments("https://user1:secret@github.com#test.html", "https://github.com#test.html"), - arguments("https://user1:secret@github.com?foo=b@r", "https://github.com?foo=b@r"), - arguments( - "https://user1:secret@github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"), - arguments("https://github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"), - arguments("https://github.com#t@st.html", "https://github.com#t@st.html"), - arguments("user1:secret@github.com", "user1:secret@github.com"), - arguments("https://github.com@", "https://github.com@")); - } - - private static void stripRequestTest(Map request, String expected) { HttpClientAttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()).build(); + HttpClientAttributesExtractor.builder( + new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter()) + .build(); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); - assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_URL, expected)); + assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_URL, expectedResult)); + } + + static final class StripUrlArgumentSource implements ArgumentsProvider { + + @Override + public Stream provideArguments(ExtensionContext context) { + return Stream.of( + arguments("https://user1:secret@github.com", "https://github.com"), + arguments("https://user1:secret@github.com/path/", "https://github.com/path/"), + arguments("https://user1:secret@github.com#test.html", "https://github.com#test.html"), + arguments("https://user1:secret@github.com?foo=b@r", "https://github.com?foo=b@r"), + arguments( + "https://user1:secret@github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"), + arguments("https://github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"), + arguments("https://github.com#t@st.html", "https://github.com#t@st.html"), + arguments("user1:secret@github.com", "user1:secret@github.com"), + arguments("https://github.com@", "https://github.com@")); + } } @Test @@ -158,7 +189,8 @@ void invalidStatusCode() { response.put("statusCode", "0"); HttpClientAttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()) + HttpClientAttributesExtractor.builder( + new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter()) .setCapturedRequestHeaders(emptyList()) .setCapturedResponseHeaders(emptyList()) .build(); @@ -170,4 +202,30 @@ void invalidStatusCode() { extractor.onEnd(attributes, Context.root(), request, response, null); assertThat(attributes.build()).isEmpty(); } + + @ParameterizedTest + @ArgumentsSource(DefaultPeerPortArgumentSource.class) + void defaultPeerPort(int peerPort, String url) { + Map request = new HashMap<>(); + request.put("url", url); + request.put("peerPort", String.valueOf(peerPort)); + + HttpClientAttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.builder( + new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter()) + .build(); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + + assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NET_PEER_PORT); + } + + static class DefaultPeerPortArgumentSource implements ArgumentsProvider { + + @Override + public Stream provideArguments(ExtensionContext context) { + return Stream.of(arguments(80, "http://github.com"), arguments(443, "https://github.com")); + } + } } 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 b101ce84217b..3100f3fd856e 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 @@ -10,6 +10,7 @@ import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.entry; +import static org.junit.jupiter.params.provider.Arguments.arguments; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; @@ -21,8 +22,14 @@ import java.util.List; import java.util.Map; import java.util.function.Function; +import java.util.stream.Stream; import javax.annotation.Nullable; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; class HttpServerAttributesExtractorTest { @@ -247,4 +254,32 @@ void extractNetHostAndPortFromNetAttributesGetter() { entry(SemanticAttributes.NET_HOST_NAME, "thehost"), entry(SemanticAttributes.NET_HOST_PORT, 777L)); } + + @ParameterizedTest + @ArgumentsSource(DefaultHostPortArgumentSource.class) + void defaultHostPort(int hostPort, String scheme) { + Map request = new HashMap<>(); + request.put("scheme", scheme); + request.put("hostPort", hostPort); + + HttpServerAttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.builder( + new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter()) + .setCapturedRequestHeaders(emptyList()) + .setCapturedResponseHeaders(emptyList()) + .build(); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + + assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NET_HOST_PORT); + } + + static class DefaultHostPortArgumentSource implements ArgumentsProvider { + + @Override + public Stream provideArguments(ExtensionContext context) { + return Stream.of(arguments(80, "http"), arguments(443, "https")); + } + } } diff --git a/instrumentation-api/src/jmh/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBenchmark.java b/instrumentation-api/src/jmh/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBenchmark.java index 4ea150d2011c..de1b7454ad39 100644 --- a/instrumentation-api/src/jmh/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBenchmark.java +++ b/instrumentation-api/src/jmh/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBenchmark.java @@ -10,8 +10,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import java.util.Collections; @@ -42,9 +41,8 @@ public class InstrumenterBenchmark { "benchmark", HttpSpanNameExtractor.create(ConstantHttpAttributesGetter.INSTANCE)) .addAttributesExtractor( - HttpClientAttributesExtractor.create(ConstantHttpAttributesGetter.INSTANCE)) - .addAttributesExtractor( - NetServerAttributesExtractor.create(new ConstantNetAttributesGetter())) + HttpClientAttributesExtractor.create( + ConstantHttpAttributesGetter.INSTANCE, new ConstantNetAttributesGetter())) .buildInstrumenter(); @Benchmark @@ -97,41 +95,33 @@ public List responseHeader(Void unused, Void unused2, String name) { } static class ConstantNetAttributesGetter - extends InetSocketAddressNetServerAttributesGetter { + extends InetSocketAddressNetClientAttributesGetter { private static final InetSocketAddress PEER_ADDRESS = InetSocketAddress.createUnresolved("localhost", 8080); - private static final InetSocketAddress HOST_ADDRESS = - InetSocketAddress.createUnresolved("localhost", 80); - @Override @Nullable - public String transport(Void unused) { + @Override + public String transport(Void request, @Nullable Void response) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Nullable @Override - public String hostName(Void unused) { + public String peerName(Void request) { return null; } @Nullable @Override - public Integer hostPort(Void unused) { + public Integer peerPort(Void request) { return null; } - @Override - @Nullable - protected InetSocketAddress getPeerSocketAddress(Void unused) { - return PEER_ADDRESS; - } - @Nullable @Override - protected InetSocketAddress getHostSocketAddress(Void unused) { - return HOST_ADDRESS; + protected InetSocketAddress getPeerSocketAddress(Void request, @Nullable Void response) { + return PEER_ADDRESS; } } } diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpClientSingletons.java b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpClientSingletons.java index b36fb5ec6219..e9d1b7611c52 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpClientSingletons.java +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpClientSingletons.java @@ -14,7 +14,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import io.opentelemetry.javaagent.instrumentation.akkahttp.AkkaHttpUtil; @@ -35,11 +34,10 @@ public class AkkaHttpClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientSingletons.java b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientSingletons.java index 27ff322420c6..152b9c7ca740 100644 --- a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientSingletons.java +++ b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import org.apache.http.HttpResponse; @@ -34,11 +33,10 @@ public final class ApacheHttpAsyncClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientSingletons.java b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientSingletons.java index 13b95a3a9da1..e78afadb23e3 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientSingletons.java +++ b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import org.apache.commons.httpclient.HttpMethod; @@ -34,11 +33,10 @@ public final class ApacheHttpClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientSingletons.java b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientSingletons.java index 28f56538e628..095f132776d6 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientSingletons.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import org.apache.http.HttpResponse; @@ -34,11 +33,10 @@ public final class ApacheHttpClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java index 9352006994e2..4f8737582e68 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java @@ -14,7 +14,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractorBuilder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; @@ -30,7 +29,9 @@ public final class ApacheHttpClientTelemetryBuilder { additionalExtractors = new ArrayList<>(); private final HttpClientAttributesExtractorBuilder httpAttributesExtractorBuilder = - HttpClientAttributesExtractor.builder(ApacheHttpClientHttpAttributesGetter.INSTANCE); + HttpClientAttributesExtractor.builder( + ApacheHttpClientHttpAttributesGetter.INSTANCE, + new ApacheHttpClientNetAttributesGetter()); ApacheHttpClientTelemetryBuilder(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; @@ -77,8 +78,6 @@ public ApacheHttpClientTelemetryBuilder setCapturedResponseHeaders(List public ApacheHttpClientTelemetry build() { ApacheHttpClientHttpAttributesGetter httpAttributesGetter = ApacheHttpClientHttpAttributesGetter.INSTANCE; - ApacheHttpClientNetAttributesGetter netAttributesGetter = - new ApacheHttpClientNetAttributesGetter(); Instrumenter instrumenter = Instrumenter.builder( @@ -87,7 +86,6 @@ public ApacheHttpClientTelemetry build() { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor(httpAttributesExtractorBuilder.build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractors(additionalExtractors) // We manually inject because we need to inject internal requests for redirects. .buildInstrumenter(SpanKindExtractor.alwaysClient()); diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientSingletons.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientSingletons.java index f06a4b0f5b62..ac2405b69754 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientSingletons.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import org.apache.hc.core5.http.HttpRequest; @@ -35,11 +34,10 @@ public final class ApacheHttpClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) 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 b1fbcbcb9a54..a122d3dd0c9e 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 @@ -24,7 +24,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.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaNetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.ArrayList; @@ -47,7 +46,8 @@ public final class ArmeriaTelemetryBuilder { private final HttpClientAttributesExtractorBuilder httpClientAttributesExtractorBuilder = - HttpClientAttributesExtractor.builder(ArmeriaHttpClientAttributesGetter.INSTANCE); + HttpClientAttributesExtractor.builder( + ArmeriaHttpClientAttributesGetter.INSTANCE, new ArmeriaNetClientAttributesGetter()); private final HttpServerAttributesExtractorBuilder httpServerAttributesExtractorBuilder = HttpServerAttributesExtractor.builder( @@ -166,16 +166,10 @@ public ArmeriaTelemetry build() { Stream.of(clientInstrumenterBuilder, serverInstrumenterBuilder) .forEach(instrumenter -> instrumenter.addAttributesExtractors(additionalExtractors)); - ArmeriaNetClientAttributesGetter netClientAttributesGetter = - new ArmeriaNetClientAttributesGetter(); - NetClientAttributesExtractor netClientAttributesExtractor = - NetClientAttributesExtractor.create(netClientAttributesGetter); - clientInstrumenterBuilder .setSpanStatusExtractor( statusExtractorTransformer.apply( HttpSpanStatusExtractor.create(clientAttributesGetter))) - .addAttributesExtractor(netClientAttributesExtractor) .addAttributesExtractor(httpClientAttributesExtractorBuilder.build()) .addAttributesExtractors(additionalClientExtractors) .addOperationMetrics(HttpClientMetrics.get()); diff --git a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientSingletons.java b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientSingletons.java index cf211cb24f43..afed3993ce37 100644 --- a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientSingletons.java +++ b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientSingletons.java @@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; @@ -35,11 +34,10 @@ public final class AsyncHttpClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientSingletons.java b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientSingletons.java index 3ca1f037b307..3ec5f219511b 100644 --- a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientSingletons.java +++ b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import org.asynchttpclient.Response; @@ -34,11 +33,10 @@ public final class AsyncHttpClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributeGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributeGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributeGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java index d2fba68e6ef2..49628e2ee372 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java @@ -12,7 +12,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor; import java.util.Arrays; import java.util.List; @@ -21,25 +20,20 @@ final class AwsSdkInstrumenterFactory { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aws-sdk-1.11"; private static final AttributesExtractor, Response> httpAttributesExtractor = - HttpClientAttributesExtractor.create(new AwsSdkHttpAttributesGetter()); + HttpClientAttributesExtractor.create( + new AwsSdkHttpAttributesGetter(), new AwsSdkNetAttributesGetter()); private static final AttributesExtractor, Response> rpcAttributesExtractor = RpcClientAttributesExtractor.create(AwsSdkRpcAttributesGetter.INSTANCE); - private static final AttributesExtractor, Response> netAttributesExtractor = - NetClientAttributesExtractor.create(new AwsSdkNetAttributesGetter()); private static final AwsSdkExperimentalAttributesExtractor experimentalAttributesExtractor = new AwsSdkExperimentalAttributesExtractor(); private static final AwsSdkSpanKindExtractor spanKindExtractor = new AwsSdkSpanKindExtractor(); private static final List, Response>> - defaultAttributesExtractors = - Arrays.asList(httpAttributesExtractor, rpcAttributesExtractor, netAttributesExtractor); + defaultAttributesExtractors = Arrays.asList(httpAttributesExtractor, rpcAttributesExtractor); private static final List, Response>> extendedAttributesExtractors = Arrays.asList( - httpAttributesExtractor, - rpcAttributesExtractor, - netAttributesExtractor, - experimentalAttributesExtractor); + httpAttributesExtractor, rpcAttributesExtractor, experimentalAttributesExtractor); private static final AwsSdkSpanNameExtractor spanName = new AwsSdkSpanNameExtractor(); static Instrumenter, Response> requestInstrumenter( diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkInstrumenterFactory.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkInstrumenterFactory.java index 1498a692a717..67ffcaf3ad86 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkInstrumenterFactory.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkInstrumenterFactory.java @@ -10,7 +10,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor; import java.util.Arrays; import java.util.List; @@ -22,29 +21,23 @@ final class AwsSdkInstrumenterFactory { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aws-sdk-2.2"; static final AwsSdkHttpAttributesGetter httpAttributesGetter = new AwsSdkHttpAttributesGetter(); + private static final AwsSdkNetAttributesGetter netAttributesGetter = + new AwsSdkNetAttributesGetter(); static final AttributesExtractor httpAttributesExtractor = - HttpClientAttributesExtractor.create(httpAttributesGetter); + HttpClientAttributesExtractor.create(httpAttributesGetter, netAttributesGetter); static final AttributesExtractor rpcAttributesExtractor = RpcClientAttributesExtractor.create(AwsSdkRpcAttributesGetter.INSTANCE); - private static final AwsSdkNetAttributesGetter netAttributesGetter = - new AwsSdkNetAttributesGetter(); - private static final NetClientAttributesExtractor - netAttributesExtractor = NetClientAttributesExtractor.create(netAttributesGetter); private static final AwsSdkExperimentalAttributesExtractor experimentalAttributesExtractor = new AwsSdkExperimentalAttributesExtractor(); private static final AwsSdkSpanKindExtractor spanKindExtractor = new AwsSdkSpanKindExtractor(); private static final List> - defaultAttributesExtractors = - Arrays.asList(httpAttributesExtractor, rpcAttributesExtractor, netAttributesExtractor); + defaultAttributesExtractors = Arrays.asList(httpAttributesExtractor, rpcAttributesExtractor); private static final List> extendedAttributesExtractors = Arrays.asList( - httpAttributesExtractor, - rpcAttributesExtractor, - netAttributesExtractor, - experimentalAttributesExtractor); + httpAttributesExtractor, rpcAttributesExtractor, experimentalAttributesExtractor); static Instrumenter requestInstrumenter( OpenTelemetry openTelemetry, boolean captureExperimentalSpanAttributes) { diff --git a/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientSingletons.java b/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientSingletons.java index ecb50d515fd1..514e22c03c60 100644 --- a/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientSingletons.java +++ b/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientSingletons.java @@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; @@ -35,11 +34,10 @@ public class GoogleHttpClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionSingletons.java b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionSingletons.java index 0017198e1dfa..8032ee912018 100644 --- a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionSingletons.java +++ b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import java.net.HttpURLConnection; @@ -31,11 +30,10 @@ public final class HttpUrlConnectionSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpClientSingletons.java b/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpClientSingletons.java index 86596d213a39..1bbb9675a7b1 100644 --- a/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpClientSingletons.java +++ b/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpClientSingletons.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import java.net.http.HttpRequest; @@ -35,11 +34,10 @@ public class JdkHttpClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientSingletons.java b/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientSingletons.java index b617dce1c2df..0e2e7518d3b9 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientSingletons.java +++ b/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientSingletons.java @@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; @@ -33,11 +32,10 @@ public class JaxRsClientSingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyClientInstrumenterBuilder.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyClientInstrumenterBuilder.java index 0f8cff69cfd8..f88269afb8c0 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyClientInstrumenterBuilder.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyClientInstrumenterBuilder.java @@ -14,7 +14,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import java.util.ArrayList; import java.util.List; import org.eclipse.jetty.client.api.Request; @@ -34,7 +33,8 @@ public final class JettyClientInstrumenterBuilder { new ArrayList<>(); private final HttpClientAttributesExtractorBuilder httpAttributesExtractorBuilder = - HttpClientAttributesExtractor.builder(JettyClientHttpAttributesGetter.INSTANCE); + HttpClientAttributesExtractor.builder( + JettyClientHttpAttributesGetter.INSTANCE, new JettyHttpClientNetAttributesGetter()); public JettyClientInstrumenterBuilder(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; @@ -61,8 +61,6 @@ public JettyClientInstrumenterBuilder setCapturedResponseHeaders(List re public Instrumenter build() { JettyClientHttpAttributesGetter httpAttributesGetter = JettyClientHttpAttributesGetter.INSTANCE; - JettyHttpClientNetAttributesGetter netAttributesGetter = - new JettyHttpClientNetAttributesGetter(); return Instrumenter.builder( this.openTelemetry, @@ -70,7 +68,6 @@ public Instrumenter build() { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor(httpAttributesExtractorBuilder.build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpClientMetrics.get()) .buildClientInstrumenter(HttpHeaderSetter.INSTANCE); diff --git a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java index 6e9c03c33f72..7bf4aaef9a31 100644 --- a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java +++ b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java @@ -13,10 +13,8 @@ import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; import okhttp3.Request; @@ -31,22 +29,19 @@ public class KubernetesClientSingletons { static { KubernetesHttpAttributesGetter httpAttributesGetter = new KubernetesHttpAttributesGetter(); - SpanNameExtractor spanNameExtractor = - request -> KubernetesRequestDigest.parse(request).toString(); + KubernetesNetAttributesGetter netAttributesGetter = new KubernetesNetAttributesGetter(); InstrumenterBuilder> instrumenterBuilder = Instrumenter.>builder( GlobalOpenTelemetry.get(), "io.opentelemetry.kubernetes-client-7.0", - spanNameExtractor) + request -> KubernetesRequestDigest.parse(request).toString()) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) - .build()) - .addAttributesExtractor( - NetClientAttributesExtractor.create(new KubernetesNetAttributesGetter())); + .build()); if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { instrumenterBuilder.addAttributesExtractor(new KubernetesExperimentalAttributesExtractor()); diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java index 05ef6144fb3b..3555fbbab390 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java @@ -30,25 +30,23 @@ public final class NettyClientSingletons { private static final Instrumenter CONNECTION_INSTRUMENTER; static { - NettyHttpClientAttributesGetter httpClientAttributesGetter = - new NettyHttpClientAttributesGetter(); - NettyNetClientAttributesGetter netClientAttributesGetter = new NettyNetClientAttributesGetter(); + NettyHttpClientAttributesGetter httpAttributesGetter = new NettyHttpClientAttributesGetter(); + NettyNetClientAttributesGetter netAttributesGetter = new NettyNetClientAttributesGetter(); INSTRUMENTER = Instrumenter.builder( GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, - HttpSpanNameExtractor.create(httpClientAttributesGetter)) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpClientAttributesGetter)) + HttpSpanNameExtractor.create(httpAttributesGetter)) + .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpClientAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netClientAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( - netClientAttributesGetter, CommonConfig.get().getPeerServiceMapping())) + netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) .addOperationMetrics(HttpClientMetrics.get()) .addContextCustomizer( (context, requestAndChannel, startAttributes) -> NettyErrorHolder.init(context)) @@ -56,12 +54,11 @@ public final class NettyClientSingletons { NettyConnectNetAttributesGetter nettyConnectAttributesGetter = new NettyConnectNetAttributesGetter(); - NetClientAttributesExtractor nettyConnectAttributesExtractor = - NetClientAttributesExtractor.create(nettyConnectAttributesGetter); CONNECTION_INSTRUMENTER = Instrumenter.builder( GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, NettyConnectionRequest::spanName) - .addAttributesExtractor(nettyConnectAttributesExtractor) + .addAttributesExtractor( + NetClientAttributesExtractor.create(nettyConnectAttributesGetter)) .addAttributesExtractor(HttpClientSpanKeyAttributesExtractor.INSTANCE) .addAttributesExtractor( PeerServiceAttributesExtractor.create( diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java index 2e250067bd89..990a0aa94f26 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java @@ -54,21 +54,17 @@ public Instrumenter createHttpInstrumenter( List capturedResponseHeaders, List> additionalHttpAttributeExtractors) { - NettyHttpClientAttributesGetter httpClientAttributesGetter = - new NettyHttpClientAttributesGetter(); + NettyHttpClientAttributesGetter httpAttributesGetter = new NettyHttpClientAttributesGetter(); NettyNetClientAttributesGetter netAttributesGetter = new NettyNetClientAttributesGetter(); return Instrumenter.builder( - openTelemetry, - instrumentationName, - HttpSpanNameExtractor.create(httpClientAttributesGetter)) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpClientAttributesGetter)) + openTelemetry, instrumentationName, HttpSpanNameExtractor.create(httpAttributesGetter)) + .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpClientAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(capturedRequestHeaders) .setCapturedResponseHeaders(capturedResponseHeaders) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create(netAttributesGetter, peerServiceMapping)) .addAttributesExtractors(additionalHttpAttributeExtractors) diff --git a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Singletons.java b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Singletons.java index 56f8f79c0ef7..4f4471acb480 100644 --- a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Singletons.java +++ b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Singletons.java @@ -17,7 +17,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; @@ -29,7 +28,7 @@ public final class OkHttp2Singletons { static { OkHttp2HttpAttributesGetter httpAttributesGetter = new OkHttp2HttpAttributesGetter(); - OkHttp2NetAttributesGetter netClientAttributesGetter = new OkHttp2NetAttributesGetter(); + OkHttp2NetAttributesGetter netAttributesGetter = new OkHttp2NetAttributesGetter(); OpenTelemetry openTelemetry = GlobalOpenTelemetry.get(); @@ -40,14 +39,13 @@ public final class OkHttp2Singletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netClientAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( - netClientAttributesGetter, CommonConfig.get().getPeerServiceMapping())) + netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) .addOperationMetrics(HttpClientMetrics.get()) .buildInstrumenter(alwaysClient()); diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java index a678c9436076..e97ceceabf0b 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java @@ -16,7 +16,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.okhttp.v3_0.internal.OkHttpNetAttributesGetter; import java.util.ArrayList; import java.util.List; @@ -32,7 +31,8 @@ public final class OkHttpTelemetryBuilder { new ArrayList<>(); private final HttpClientAttributesExtractorBuilder httpAttributesExtractorBuilder = - HttpClientAttributesExtractor.builder(OkHttpAttributesGetter.INSTANCE); + HttpClientAttributesExtractor.builder( + OkHttpAttributesGetter.INSTANCE, new OkHttpNetAttributesGetter()); OkHttpTelemetryBuilder(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; @@ -76,7 +76,6 @@ public OkHttpTelemetryBuilder setCapturedResponseHeaders(List responseHe */ public OkHttpTelemetry build() { OkHttpAttributesGetter httpAttributesGetter = OkHttpAttributesGetter.INSTANCE; - OkHttpNetAttributesGetter attributesGetter = new OkHttpNetAttributesGetter(); Instrumenter instrumenter = Instrumenter.builder( @@ -85,7 +84,6 @@ public OkHttpTelemetry build() { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor(httpAttributesExtractorBuilder.build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(attributesGetter)) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpClientMetrics.get()) .buildInstrumenter(alwaysClient()); diff --git a/instrumentation/play/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientInstrumenterFactory.java b/instrumentation/play/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientInstrumenterFactory.java index fd2b3f18d81c..a494f341a500 100644 --- a/instrumentation/play/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientInstrumenterFactory.java +++ b/instrumentation/play/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientInstrumenterFactory.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import play.shaded.ahc.org.asynchttpclient.Request; @@ -29,11 +28,10 @@ public static Instrumenter createInstrumenter(String instrume HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java index fcd1855ad27b..bd02f107cc7f 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java @@ -16,9 +16,8 @@ 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.api.instrumenter.net.NetClientAttributesExtractor; -import io.opentelemetry.instrumentation.ratpack.internal.RatpackHttpNetAttributesGetter; -import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetAttributesGetter; +import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetClientAttributesGetter; +import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetServerAttributesGetter; import java.util.ArrayList; import java.util.List; import ratpack.http.Request; @@ -37,11 +36,12 @@ public final class RatpackTelemetryBuilder { new ArrayList<>(); private final HttpClientAttributesExtractorBuilder httpClientAttributesExtractorBuilder = - HttpClientAttributesExtractor.builder(RatpackHttpClientAttributesGetter.INSTANCE); + HttpClientAttributesExtractor.builder( + RatpackHttpClientAttributesGetter.INSTANCE, new RatpackNetClientAttributesGetter()); private final HttpServerAttributesExtractorBuilder httpServerAttributesExtractorBuilder = HttpServerAttributesExtractor.builder( - RatpackHttpAttributesGetter.INSTANCE, new RatpackNetAttributesGetter()); + RatpackHttpAttributesGetter.INSTANCE, new RatpackNetServerAttributesGetter()); private final List> additionalHttpClientExtractors = new ArrayList<>(); @@ -129,13 +129,11 @@ public RatpackTelemetry build() { } private Instrumenter httpClientInstrumenter() { - RatpackHttpNetAttributesGetter netAttributes = new RatpackHttpNetAttributesGetter(); RatpackHttpClientAttributesGetter httpAttributes = RatpackHttpClientAttributesGetter.INSTANCE; return Instrumenter.builder( openTelemetry, INSTRUMENTATION_NAME, HttpSpanNameExtractor.create(httpAttributes)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributes)) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributes)) .addAttributesExtractor(httpClientAttributesExtractorBuilder.build()) .addAttributesExtractors(additionalHttpClientExtractors) .addOperationMetrics(HttpServerMetrics.get()) diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackHttpNetAttributesGetter.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetClientAttributesGetter.java similarity index 95% rename from instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackHttpNetAttributesGetter.java rename to instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetClientAttributesGetter.java index b10f3041d4ac..c6b67623f784 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackHttpNetAttributesGetter.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetClientAttributesGetter.java @@ -15,7 +15,7 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class RatpackHttpNetAttributesGetter +public final class RatpackNetClientAttributesGetter implements NetClientAttributesGetter { @Override diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesGetter.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetServerAttributesGetter.java similarity index 93% rename from instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesGetter.java rename to instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetServerAttributesGetter.java index d52e1ee15e66..2b8082e45220 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesGetter.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetServerAttributesGetter.java @@ -16,7 +16,7 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class RatpackNetAttributesGetter implements NetServerAttributesGetter { +public final class RatpackNetServerAttributesGetter implements NetServerAttributesGetter { @Override public String transport(Request request) { return SemanticAttributes.NetTransportValues.IP_TCP; diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettySingletons.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettySingletons.java index 37e6890d6448..badd746a1b86 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettySingletons.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettySingletons.java @@ -12,7 +12,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyConnectionInstrumenter; @@ -54,11 +53,10 @@ public final class ReactorNettySingletons { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebTelemetryBuilder.java b/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebTelemetryBuilder.java index 80c5d56e7b01..e34f3db0beb1 100644 --- a/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebTelemetryBuilder.java +++ b/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebTelemetryBuilder.java @@ -14,7 +14,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import java.util.ArrayList; import java.util.List; import org.springframework.http.HttpRequest; @@ -29,7 +28,8 @@ public final class SpringWebTelemetryBuilder { new ArrayList<>(); private final HttpClientAttributesExtractorBuilder httpAttributesExtractorBuilder = - HttpClientAttributesExtractor.builder(SpringWebHttpAttributesGetter.INSTANCE); + HttpClientAttributesExtractor.builder( + SpringWebHttpAttributesGetter.INSTANCE, new SpringWebNetAttributesGetter()); SpringWebTelemetryBuilder(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; @@ -74,7 +74,6 @@ public SpringWebTelemetryBuilder setCapturedResponseHeaders(List respons */ public SpringWebTelemetry build() { SpringWebHttpAttributesGetter httpAttributeGetter = SpringWebHttpAttributesGetter.INSTANCE; - SpringWebNetAttributesGetter netAttributesGetter = new SpringWebNetAttributesGetter(); Instrumenter instrumenter = Instrumenter.builder( @@ -83,7 +82,6 @@ public SpringWebTelemetry build() { HttpSpanNameExtractor.create(httpAttributeGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributeGetter)) .addAttributesExtractor(httpAttributesExtractorBuilder.build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpClientMetrics.get()) .buildClientInstrumenter(HttpRequestSetter.INSTANCE); diff --git a/instrumentation/spring/spring-webflux-5.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux-5.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxTelemetryBuilder.java index 2491c84ee8ca..489dfc20a98a 100644 --- a/instrumentation/spring/spring-webflux-5.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux-5.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/SpringWebfluxTelemetryBuilder.java @@ -17,7 +17,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.spring.webflux.client.internal.SpringWebfluxNetAttributesGetter; import java.util.ArrayList; import java.util.List; @@ -32,7 +31,8 @@ public final class SpringWebfluxTelemetryBuilder { new ArrayList<>(); private final HttpClientAttributesExtractorBuilder httpAttributesExtractorBuilder = - HttpClientAttributesExtractor.builder(SpringWebfluxHttpAttributesGetter.INSTANCE); + HttpClientAttributesExtractor.builder( + SpringWebfluxHttpAttributesGetter.INSTANCE, new SpringWebfluxNetAttributesGetter()); private boolean captureExperimentalSpanAttributes = false; @@ -92,7 +92,6 @@ public SpringWebfluxTelemetryBuilder setCaptureExperimentalSpanAttributes( public SpringWebfluxTelemetry build() { SpringWebfluxHttpAttributesGetter httpAttributesGetter = SpringWebfluxHttpAttributesGetter.INSTANCE; - SpringWebfluxNetAttributesGetter netAttributesGetter = new SpringWebfluxNetAttributesGetter(); InstrumenterBuilder builder = Instrumenter.builder( @@ -101,7 +100,6 @@ public SpringWebfluxTelemetry build() { HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor(httpAttributesExtractorBuilder.build()) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpClientMetrics.get()); diff --git a/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/Vertx3NetAttributesGetter.java b/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/Vertx3NetAttributesGetter.java new file mode 100644 index 000000000000..77e8565cc389 --- /dev/null +++ b/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/Vertx3NetAttributesGetter.java @@ -0,0 +1,54 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.vertx.v3_0.client; + +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.vertx.core.http.HttpClientRequest; +import io.vertx.core.http.HttpClientResponse; +import io.vertx.core.net.SocketAddress; +import javax.annotation.Nullable; + +enum Vertx3NetAttributesGetter + implements NetClientAttributesGetter { + INSTANCE; + + @Override + public String transport(HttpClientRequest request, @Nullable HttpClientResponse response) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } + + @Nullable + @Override + public String peerName(HttpClientRequest request) { + return null; + } + + @Override + public Integer peerPort(HttpClientRequest request) { + return null; + } + + @Nullable + @Override + public String sockPeerName(HttpClientRequest request, @Nullable HttpClientResponse response) { + if (response == null) { + return null; + } + SocketAddress socketAddress = response.netSocket().remoteAddress(); + return socketAddress == null ? null : socketAddress.host(); + } + + @Nullable + @Override + public Integer sockPeerPort(HttpClientRequest request, @Nullable HttpClientResponse response) { + if (response == null) { + return null; + } + SocketAddress socketAddress = response.netSocket().remoteAddress(); + return socketAddress == null ? null : socketAddress.port(); + } +} diff --git a/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/VertxClientSingletons.java b/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/VertxClientSingletons.java index f93fdba41b4a..d204fcaa3cc4 100644 --- a/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/VertxClientSingletons.java +++ b/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/VertxClientSingletons.java @@ -14,7 +14,9 @@ public final class VertxClientSingletons { private static final Instrumenter INSTRUMENTER = VertxClientInstrumenterFactory.create( - "io.opentelemetry.vertx-http-client-3.0", new Vertx3HttpAttributesGetter(), null); + "io.opentelemetry.vertx-http-client-3.0", + new Vertx3HttpAttributesGetter(), + Vertx3NetAttributesGetter.INSTANCE); public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/vertx/vertx-http-client/vertx-http-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client/Vertx4NetAttributesGetter.java b/instrumentation/vertx/vertx-http-client/vertx-http-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client/Vertx4NetAttributesGetter.java index bf5fccbb8e7b..1625958f3fa4 100644 --- a/instrumentation/vertx/vertx-http-client/vertx-http-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client/Vertx4NetAttributesGetter.java +++ b/instrumentation/vertx/vertx-http-client/vertx-http-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client/Vertx4NetAttributesGetter.java @@ -5,16 +5,15 @@ package io.opentelemetry.javaagent.instrumentation.vertx.v4_0.client; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.vertx.core.http.HttpClientRequest; import io.vertx.core.http.HttpClientResponse; import io.vertx.core.net.SocketAddress; -import java.net.InetSocketAddress; import javax.annotation.Nullable; final class Vertx4NetAttributesGetter - extends InetSocketAddressNetClientAttributesGetter { + implements NetClientAttributesGetter { @Override public String transport(HttpClientRequest request, @Nullable HttpClientResponse response) { @@ -34,15 +33,31 @@ public Integer peerPort(HttpClientRequest request) { @Nullable @Override - protected InetSocketAddress getPeerSocketAddress( - HttpClientRequest request, @Nullable HttpClientResponse response) { + public String sockPeerAddr(HttpClientRequest request, @Nullable HttpClientResponse response) { if (response == null) { return null; } - SocketAddress address = response.netSocket().remoteAddress(); - if (address instanceof InetSocketAddress) { - return (InetSocketAddress) address; + SocketAddress socketAddress = response.netSocket().remoteAddress(); + return socketAddress == null ? null : socketAddress.hostAddress(); + } + + @Nullable + @Override + public String sockPeerName(HttpClientRequest request, @Nullable HttpClientResponse response) { + if (response == null) { + return null; + } + SocketAddress socketAddress = response.netSocket().remoteAddress(); + return socketAddress == null ? null : socketAddress.host(); + } + + @Nullable + @Override + public Integer sockPeerPort(HttpClientRequest request, @Nullable HttpClientResponse response) { + if (response == null) { + return null; } - return null; + SocketAddress socketAddress = response.netSocket().remoteAddress(); + return socketAddress == null ? null : socketAddress.port(); } } diff --git a/instrumentation/vertx/vertx-http-client/vertx-http-client-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/client/VertxClientInstrumenterFactory.java b/instrumentation/vertx/vertx-http-client/vertx-http-client-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/client/VertxClientInstrumenterFactory.java index c3451fb126e8..3dc7e8afb442 100644 --- a/instrumentation/vertx/vertx-http-client/vertx-http-client-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/client/VertxClientInstrumenterFactory.java +++ b/instrumentation/vertx/vertx-http-client/vertx-http-client-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/client/VertxClientInstrumenterFactory.java @@ -12,21 +12,18 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import io.vertx.core.http.HttpClientRequest; import io.vertx.core.http.HttpClientResponse; -import javax.annotation.Nullable; public final class VertxClientInstrumenterFactory { public static Instrumenter create( String instrumentationName, AbstractVertxHttpAttributesGetter httpAttributesGetter, - @Nullable - NetClientAttributesGetter netAttributesGetter) { + NetClientAttributesGetter netAttributesGetter) { InstrumenterBuilder builder = Instrumenter.builder( @@ -35,20 +32,15 @@ public static Instrumenter create( HttpSpanNameExtractor.create(httpAttributesGetter)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) + HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter) .setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders()) .build()) + .addAttributesExtractor( + PeerServiceAttributesExtractor.create( + netAttributesGetter, CommonConfig.get().getPeerServiceMapping())) .addOperationMetrics(HttpClientMetrics.get()); - if (netAttributesGetter != null) { - builder - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) - .addAttributesExtractor( - PeerServiceAttributesExtractor.create( - netAttributesGetter, CommonConfig.get().getPeerServiceMapping())); - } - return builder.buildClientInstrumenter(new HttpRequestHeaderSetter()); } diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java index 6636918eb1e8..2bc4b14c042b 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java @@ -941,23 +941,9 @@ SpanDataAssert assertClientSpan( if (attrs.get(SemanticAttributes.NET_PEER_NAME) != null) { assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost()); } + // TODO: once httpClientAttributes test knob is used, verify default port values if (attrs.get(SemanticAttributes.NET_PEER_PORT) != null) { - if (uri.getPort() > 0) { - assertThat(attrs) - .containsEntry(SemanticAttributes.NET_PEER_PORT, (long) uri.getPort()); - } else { - // https://192.0.2.1/ where some instrumentation may have set this to 443, but - // not all. - assertThat(attrs) - .hasEntrySatisfying( - SemanticAttributes.NET_PEER_PORT, - port -> { - // Some instrumentation seem to set NET_PEER_PORT to -1 incorrectly. - if (port > 0) { - assertThat(port).isEqualTo(options.testHttps ? 443 : 80); - } - }); - } + assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_PORT, uri.getPort()); } // In these cases the peer connection is not established, so the HTTP client should @@ -974,7 +960,13 @@ SpanDataAssert assertClientSpan( assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost()); } if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_PORT)) { - assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_PORT, uri.getPort()); + int uriPort = uri.getPort(); + // default values are ignored + if (uriPort <= 0 || uriPort == 80 || uriPort == 443) { + assertThat(attrs).doesNotContainKey(SemanticAttributes.NET_PEER_PORT); + } else { + assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_PORT, uriPort); + } } // TODO: Move to test knob rather than always treating as optional diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java index 9593ca1ee13d..a22674e09ff9 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java @@ -554,6 +554,7 @@ protected SpanDataAssert assertServerSpan( assertThat(attrs).containsEntry(SemanticAttributes.NET_HOST_NAME, "localhost"); // TODO: Move to test knob rather than always treating as optional + // TODO: once httpAttributes test knob is used, verify default port values if (attrs.get(SemanticAttributes.NET_HOST_PORT) != null) { assertThat(attrs).containsEntry(SemanticAttributes.NET_HOST_PORT, port); } From ea6c144c0d756410d83c7626edbeb55349134fee Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Mon, 21 Nov 2022 12:59:24 +0100 Subject: [PATCH 2/4] fix twilio tests --- .../javaagent/src/test/groovy/test/TwilioClientTest.groovy | 5 ----- 1 file changed, 5 deletions(-) diff --git a/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy b/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy index 0ca0a47850b2..6980fdb9415e 100644 --- a/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy +++ b/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy @@ -250,7 +250,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification { attributes { "$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.NET_PEER_PORT.key" 443 "$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1 "$SemanticAttributes.HTTP_METHOD.key" "POST" "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" @@ -318,7 +317,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification { attributes { "$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.NET_PEER_PORT.key" 443 "$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1 "$SemanticAttributes.HTTP_METHOD.key" "POST" "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" @@ -332,7 +330,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification { attributes { "$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.NET_PEER_PORT.key" 443 "$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1 "$SemanticAttributes.HTTP_METHOD.key" "POST" "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" @@ -407,7 +404,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification { attributes { "$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.NET_PEER_PORT.key" 443 "$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1 "$SemanticAttributes.HTTP_METHOD.key" "POST" "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" @@ -421,7 +417,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification { attributes { "$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.NET_PEER_PORT.key" 443 "$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1 "$SemanticAttributes.HTTP_METHOD.key" "POST" "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" From 3b15b4518b7c1f5bed2930bf801892f3b6d41eae Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Mon, 21 Nov 2022 15:23:29 +0100 Subject: [PATCH 3/4] fix netty tests --- .../v3_8/client/NettyClientSingletons.java | 6 +-- .../NettyConnectHttpAttributesGetter.java | 54 +++++++++++++++++++ .../NettyClientInstrumenterFactory.java | 17 ++++-- .../NettyConnectHttpAttributesGetter.java | 54 +++++++++++++++++++ .../HttpClientSpanKeyAttributesExtractor.java | 45 ---------------- .../junit/http/AbstractHttpClientTest.java | 35 +++++------- 6 files changed, 135 insertions(+), 76 deletions(-) create mode 100644 instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectHttpAttributesGetter.java create mode 100644 instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyConnectHttpAttributesGetter.java delete mode 100644 instrumentation/netty/netty-common/library/src/main/java/io/opentelemetry/instrumentation/netty/common/internal/HttpClientSpanKeyAttributesExtractor.java diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java index 3555fbbab390..c5049b1e2d7d 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java @@ -12,9 +12,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; -import io.opentelemetry.instrumentation.netty.common.internal.HttpClientSpanKeyAttributesExtractor; import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest; import io.opentelemetry.instrumentation.netty.common.internal.NettyErrorHolder; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; @@ -58,8 +56,8 @@ public final class NettyClientSingletons { Instrumenter.builder( GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, NettyConnectionRequest::spanName) .addAttributesExtractor( - NetClientAttributesExtractor.create(nettyConnectAttributesGetter)) - .addAttributesExtractor(HttpClientSpanKeyAttributesExtractor.INSTANCE) + HttpClientAttributesExtractor.create( + NettyConnectHttpAttributesGetter.INSTANCE, nettyConnectAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( nettyConnectAttributesGetter, CommonConfig.get().getPeerServiceMapping())) diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectHttpAttributesGetter.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectHttpAttributesGetter.java new file mode 100644 index 000000000000..2f03e7b6ddd9 --- /dev/null +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectHttpAttributesGetter.java @@ -0,0 +1,54 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.netty.v3_8.client; + +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter; +import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest; +import java.util.Collections; +import java.util.List; +import javax.annotation.Nullable; +import org.jboss.netty.channel.Channel; + +enum NettyConnectHttpAttributesGetter + implements HttpClientAttributesGetter { + INSTANCE; + + @Nullable + @Override + public String url(NettyConnectionRequest nettyConnectionRequest) { + return null; + } + + @Nullable + @Override + public String flavor(NettyConnectionRequest nettyConnectionRequest, @Nullable Channel channel) { + return null; + } + + @Nullable + @Override + public String method(NettyConnectionRequest nettyConnectionRequest) { + return null; + } + + @Override + public List requestHeader(NettyConnectionRequest nettyConnectionRequest, String name) { + return Collections.emptyList(); + } + + @Nullable + @Override + public Integer statusCode( + NettyConnectionRequest nettyConnectionRequest, Channel channel, @Nullable Throwable error) { + return null; + } + + @Override + public List responseHeader( + NettyConnectionRequest nettyConnectionRequest, Channel channel, String name) { + return Collections.emptyList(); + } +} diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java index 990a0aa94f26..3c1e2a46dba1 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java @@ -18,7 +18,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; -import io.opentelemetry.instrumentation.netty.common.internal.HttpClientSpanKeyAttributesExtractor; import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest; import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; import java.util.List; @@ -78,10 +77,18 @@ public NettyConnectionInstrumenter createConnectionInstrumenter() { InstrumenterBuilder instrumenterBuilder = Instrumenter.builder( openTelemetry, instrumentationName, NettyConnectionRequest::spanName) - .addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create(netAttributesGetter, peerServiceMapping)); - if (!connectionTelemetryEnabled) { + + if (connectionTelemetryEnabled) { + // when the connection telemetry is enabled, we do noty want these CONNECT spans to be + // suppressed by higher-level HTTP spans - this would happen in the reactor-netty + // instrumentation + // the solution for this is to deliberately avoid using the HTTP extractor and use the plain + // net attributes extractor instead + instrumenterBuilder.addAttributesExtractor( + NetClientAttributesExtractor.create(netAttributesGetter)); + } else { // when the connection telemetry is not enabled, netty creates CONNECT spans whenever a // connection error occurs - because there is no HTTP span in that scenario, if raw netty // connection occurs before an HTTP message is even formed @@ -89,7 +96,9 @@ public NettyConnectionInstrumenter createConnectionInstrumenter() { // client) is used, the connection phase is a part of the HTTP span for these // for that to happen, the CONNECT span will "pretend" to be a full HTTP span when connection // telemetry is off - instrumenterBuilder.addAttributesExtractor(HttpClientSpanKeyAttributesExtractor.INSTANCE); + instrumenterBuilder.addAttributesExtractor( + HttpClientAttributesExtractor.create( + NettyConnectHttpAttributesGetter.INSTANCE, netAttributesGetter)); } Instrumenter instrumenter = diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyConnectHttpAttributesGetter.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyConnectHttpAttributesGetter.java new file mode 100644 index 000000000000..09823ca3fe19 --- /dev/null +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyConnectHttpAttributesGetter.java @@ -0,0 +1,54 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.netty.v4.common.internal.client; + +import io.netty.channel.Channel; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter; +import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest; +import java.util.Collections; +import java.util.List; +import javax.annotation.Nullable; + +enum NettyConnectHttpAttributesGetter + implements HttpClientAttributesGetter { + INSTANCE; + + @Nullable + @Override + public String url(NettyConnectionRequest nettyConnectionRequest) { + return null; + } + + @Nullable + @Override + public String flavor(NettyConnectionRequest nettyConnectionRequest, @Nullable Channel channel) { + return null; + } + + @Nullable + @Override + public String method(NettyConnectionRequest nettyConnectionRequest) { + return null; + } + + @Override + public List requestHeader(NettyConnectionRequest nettyConnectionRequest, String name) { + return Collections.emptyList(); + } + + @Nullable + @Override + public Integer statusCode( + NettyConnectionRequest nettyConnectionRequest, Channel channel, @Nullable Throwable error) { + return null; + } + + @Override + public List responseHeader( + NettyConnectionRequest nettyConnectionRequest, Channel channel, String name) { + return Collections.emptyList(); + } +} diff --git a/instrumentation/netty/netty-common/library/src/main/java/io/opentelemetry/instrumentation/netty/common/internal/HttpClientSpanKeyAttributesExtractor.java b/instrumentation/netty/netty-common/library/src/main/java/io/opentelemetry/instrumentation/netty/common/internal/HttpClientSpanKeyAttributesExtractor.java deleted file mode 100644 index e1025af94ca8..000000000000 --- a/instrumentation/netty/netty-common/library/src/main/java/io/opentelemetry/instrumentation/netty/common/internal/HttpClientSpanKeyAttributesExtractor.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.netty.common.internal; - -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.internal.SpanKey; -import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; -import javax.annotation.Nullable; - -/** - * Attributes extractor that pretends it's a {@link HttpClientAttributesExtractor} so that error - * only CONNECT spans can be suppressed by higher level HTTP clients based on netty. - * - *

This class is internal and is hence not for public use. Its APIs are unstable and can change - * at any time. - */ -public enum HttpClientSpanKeyAttributesExtractor - implements AttributesExtractor, SpanKeyProvider { - INSTANCE; - - @Override - public void onStart( - AttributesBuilder attributes, - Context parentContext, - NettyConnectionRequest nettyConnectionRequest) {} - - @Override - public void onEnd( - AttributesBuilder attributes, - Context context, - NettyConnectionRequest nettyConnectionRequest, - @Nullable Object channel, - @Nullable Throwable error) {} - - @Override - public SpanKey internalGetSpanKey() { - return SpanKey.HTTP_CLIENT; - } -} diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java index 2bc4b14c042b..bb1a85dbda06 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java @@ -934,18 +934,20 @@ SpanDataAssert assertClientSpan( if (attrs.get(SemanticAttributes.NET_TRANSPORT) != null) { assertThat(attrs).containsEntry(SemanticAttributes.NET_TRANSPORT, IP_TCP); } - - if (uri.getPort() == PortUtils.UNUSABLE_PORT || uri.getHost().equals("192.0.2.1")) { - // TODO: net.peer.name and net.peer.port should always be populated from the URI or - // the Host header, verify these assertions below - if (attrs.get(SemanticAttributes.NET_PEER_NAME) != null) { - assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost()); - } - // TODO: once httpClientAttributes test knob is used, verify default port values - if (attrs.get(SemanticAttributes.NET_PEER_PORT) != null) { - assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_PORT, uri.getPort()); + if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_NAME)) { + assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost()); + } + if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_PORT)) { + int uriPort = uri.getPort(); + // default values are ignored + if (uriPort <= 0 || uriPort == 80 || uriPort == 443) { + assertThat(attrs).doesNotContainKey(SemanticAttributes.NET_PEER_PORT); + } else { + assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_PORT, uriPort); } + } + if (uri.getPort() == PortUtils.UNUSABLE_PORT || uri.getHost().equals("192.0.2.1")) { // In these cases the peer connection is not established, so the HTTP client should // not report any socket-level attributes assertThat(attrs) @@ -956,19 +958,6 @@ SpanDataAssert assertClientSpan( .doesNotContainKey("net.sock.peer.port"); } else { - if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_NAME)) { - assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost()); - } - if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_PORT)) { - int uriPort = uri.getPort(); - // default values are ignored - if (uriPort <= 0 || uriPort == 80 || uriPort == 443) { - assertThat(attrs).doesNotContainKey(SemanticAttributes.NET_PEER_PORT); - } else { - assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_PORT, uriPort); - } - } - // TODO: Move to test knob rather than always treating as optional if (attrs.get(SemanticAttributes.NET_SOCK_PEER_ADDR) != null) { assertThat(attrs) From c9cac48f53cfe82f07fbcdf2c143113a9c81b1e1 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Tue, 22 Nov 2022 15:31:36 +0100 Subject: [PATCH 4/4] code review comments --- .../instrumenter/http/HttpClientAttributesExtractor.java | 5 +++-- .../instrumenter/http/HttpServerAttributesExtractor.java | 5 +++-- .../internal/InternalNetClientAttributesExtractor.java | 8 ++++---- .../internal/InternalNetServerAttributesExtractor.java | 8 ++++---- .../internal/client/NettyClientInstrumenterFactory.java | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) 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 290dee6d29e9..c35719504360 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 @@ -81,7 +81,8 @@ public static HttpClientAttributesExtractorBuilder capturedResponseHeaders) { super(httpAttributesGetter, capturedRequestHeaders, capturedResponseHeaders); internalNetExtractor = - new InternalNetClientAttributesExtractor<>(netAttributesGetter, this::isValidNetPeerPort); + new InternalNetClientAttributesExtractor<>( + netAttributesGetter, this::shouldCapturePeerPort); } @Override @@ -93,7 +94,7 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST internalNetExtractor.onStart(attributes, request); } - private boolean isValidNetPeerPort(int port, REQUEST request) { + private boolean shouldCapturePeerPort(int port, REQUEST request) { String url = getter.url(request); if (url == null) { return true; 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 23e62a13f9da..908778cf9eaa 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 @@ -102,7 +102,8 @@ public static HttpServerAttributesExtractorBuilder httpRouteHolderGetter) { super(httpAttributesGetter, capturedRequestHeaders, capturedResponseHeaders); internalNetExtractor = - new InternalNetServerAttributesExtractor<>(netAttributesGetter, this::isValidNetHostPort); + new InternalNetServerAttributesExtractor<>( + netAttributesGetter, this::shouldCaptureHostPort); this.httpRouteHolderGetter = httpRouteHolderGetter; } @@ -121,7 +122,7 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST internalNetExtractor.onStart(attributes, request, host(request)); } - private boolean isValidNetHostPort(int port, REQUEST request) { + private boolean shouldCaptureHostPort(int port, REQUEST request) { String scheme = getter.scheme(request); if (scheme == null) { return true; diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java index df487b564503..55d7f7c44a6e 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java @@ -20,13 +20,13 @@ public final class InternalNetClientAttributesExtractor { private final NetClientAttributesGetter getter; - private final BiPredicate netPeerPortCondition; + private final BiPredicate capturePeerPortCondition; public InternalNetClientAttributesExtractor( NetClientAttributesGetter getter, - BiPredicate netPeerPortCondition) { + BiPredicate capturePeerPortCondition) { this.getter = getter; - this.netPeerPortCondition = netPeerPortCondition; + this.capturePeerPortCondition = capturePeerPortCondition; } public void onStart(AttributesBuilder attributes, REQUEST request) { @@ -37,7 +37,7 @@ public void onStart(AttributesBuilder attributes, REQUEST request) { if (peerName != null) { internalSet(attributes, SemanticAttributes.NET_PEER_NAME, peerName); - if (peerPort != null && peerPort > 0 && netPeerPortCondition.test(peerPort, request)) { + if (peerPort != null && peerPort > 0 && capturePeerPortCondition.test(peerPort, request)) { internalSet(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java index f0464d9fd83f..ae68af195dba 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java @@ -25,13 +25,13 @@ public final class InternalNetServerAttributesExtractor { Logger.getLogger(InternalNetServerAttributesExtractor.class.getName()); private final NetServerAttributesGetter getter; - private final BiPredicate netHostPortCondition; + private final BiPredicate captureHostPortCondition; public InternalNetServerAttributesExtractor( NetServerAttributesGetter getter, - BiPredicate netHostPortCondition) { + BiPredicate captureHostPortCondition) { this.getter = getter; - this.netHostPortCondition = netHostPortCondition; + this.captureHostPortCondition = captureHostPortCondition; } public void onStart(AttributesBuilder attributes, REQUEST request, @Nullable String hostHeader) { @@ -73,7 +73,7 @@ public void onStart(AttributesBuilder attributes, REQUEST request, @Nullable Str if (hostName != null) { internalSet(attributes, SemanticAttributes.NET_HOST_NAME, hostName); - if (hostPort != null && hostPort > 0 && netHostPortCondition.test(hostPort, request)) { + if (hostPort != null && hostPort > 0 && captureHostPortCondition.test(hostPort, request)) { internalSet(attributes, SemanticAttributes.NET_HOST_PORT, (long) hostPort); } } diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java index 3c1e2a46dba1..7ba58222abc9 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java @@ -81,7 +81,7 @@ public NettyConnectionInstrumenter createConnectionInstrumenter() { PeerServiceAttributesExtractor.create(netAttributesGetter, peerServiceMapping)); if (connectionTelemetryEnabled) { - // when the connection telemetry is enabled, we do noty want these CONNECT spans to be + // when the connection telemetry is enabled, we do not want these CONNECT spans to be // suppressed by higher-level HTTP spans - this would happen in the reactor-netty // instrumentation // the solution for this is to deliberately avoid using the HTTP extractor and use the plain