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 b74ba20231..01cfaa4f59 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 @@ -12,6 +12,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.api.internal.SpanKey; @@ -53,6 +54,7 @@ public final class HttpClientAttributesExtractor } private final InternalNetClientAttributesExtractor internalNetExtractor; + private final InternalNetworkAttributesExtractor internalNetworkExtractor; private final ToIntFunction resendCountIncrementer; HttpClientAttributesExtractor( @@ -80,7 +82,14 @@ public final class HttpClientAttributesExtractor new InternalNetClientAttributesExtractor<>( netAttributesGetter, this::shouldCapturePeerPort, - new HttpNetNamePortGetter<>(httpAttributesGetter)); + new HttpNetNamePortGetter<>(httpAttributesGetter), + SemconvStability.emitOldHttpSemconv()); + internalNetworkExtractor = + new InternalNetworkAttributesExtractor<>( + netAttributesGetter, + HttpNetworkTransportFilter.INSTANCE, + SemconvStability.emitStableHttpSemconv(), + SemconvStability.emitOldHttpSemconv()); this.resendCountIncrementer = resendCountIncrementer; } @@ -121,6 +130,7 @@ public final class HttpClientAttributesExtractor super.onEnd(attributes, context, request, response, error); internalNetExtractor.onEnd(attributes, request, response); + internalNetworkExtractor.onEnd(attributes, request, response); int resendCount = resendCountIncrementer.applyAsInt(context); if (resendCount > 0) { diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpNetworkTransportFilter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpNetworkTransportFilter.java new file mode 100644 index 0000000000..8df6989fcd --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpNetworkTransportFilter.java @@ -0,0 +1,35 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.http; + +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter; +import javax.annotation.Nullable; + +enum HttpNetworkTransportFilter implements NetworkTransportFilter { + INSTANCE; + + @Override + public boolean shouldAddNetworkTransport( + @Nullable String protocolName, + @Nullable String protocolVersion, + @Nullable String proposedTransport) { + // tcp is the default transport for http/1* and http/2*, we're skipping it + if ("http".equals(protocolName) + && protocolVersion != null + && (protocolVersion.startsWith("1") || protocolVersion.startsWith("2")) + && "tcp".equals(proposedTransport)) { + return false; + } + // udp is the default transport for http/3*, we're skipping it + if ("http".equals(protocolName) + && protocolVersion != null + && protocolVersion.startsWith("3") + && "udp".equals(proposedTransport)) { + return false; + } + 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 0dedf22963..338afb46f2 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 @@ -16,6 +16,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.InternalUrlAttributesExtractor; import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; import io.opentelemetry.instrumentation.api.internal.SemconvStability; @@ -43,7 +44,7 @@ public final class HttpServerAttributesExtractor /** Creates the HTTP server attributes extractor with default configuration. */ public static AttributesExtractor create( HttpServerAttributesGetter httpAttributesGetter, - NetServerAttributesGetter netAttributesGetter) { + NetServerAttributesGetter netAttributesGetter) { return builder(httpAttributesGetter, netAttributesGetter).build(); } @@ -53,7 +54,7 @@ public final class HttpServerAttributesExtractor */ public static HttpServerAttributesExtractorBuilder builder( HttpServerAttributesGetter httpAttributesGetter, - NetServerAttributesGetter netAttributesGetter) { + NetServerAttributesGetter netAttributesGetter) { return new HttpServerAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter); } @@ -64,12 +65,13 @@ public final class HttpServerAttributesExtractor "otel.instrumentation.http.prefer-forwarded-url-scheme", false); private final InternalUrlAttributesExtractor internalUrlExtractor; - private final InternalNetServerAttributesExtractor internalNetExtractor; + private final InternalNetServerAttributesExtractor internalNetExtractor; + private final InternalNetworkAttributesExtractor internalNetworkExtractor; private final Function httpRouteHolderGetter; HttpServerAttributesExtractor( HttpServerAttributesGetter httpAttributesGetter, - NetServerAttributesGetter netAttributesGetter, + NetServerAttributesGetter netAttributesGetter, List capturedRequestHeaders, List capturedResponseHeaders) { this( @@ -83,7 +85,7 @@ public final class HttpServerAttributesExtractor // visible for tests HttpServerAttributesExtractor( HttpServerAttributesGetter httpAttributesGetter, - NetServerAttributesGetter netAttributesGetter, + NetServerAttributesGetter netAttributesGetter, List capturedRequestHeaders, List capturedResponseHeaders, Function httpRouteHolderGetter) { @@ -98,7 +100,14 @@ public final class HttpServerAttributesExtractor new InternalNetServerAttributesExtractor<>( netAttributesGetter, this::shouldCaptureHostPort, - new HttpNetNamePortGetter<>(httpAttributesGetter)); + new HttpNetNamePortGetter<>(httpAttributesGetter), + SemconvStability.emitOldHttpSemconv()); + internalNetworkExtractor = + new InternalNetworkAttributesExtractor<>( + netAttributesGetter, + HttpNetworkTransportFilter.INSTANCE, + SemconvStability.emitStableHttpSemconv(), + SemconvStability.emitOldHttpSemconv()); this.httpRouteHolderGetter = httpRouteHolderGetter; } @@ -134,6 +143,9 @@ public final class HttpServerAttributesExtractor @Nullable Throwable error) { super.onEnd(attributes, context, request, response, error); + + internalNetworkExtractor.onEnd(attributes, request, response); + internalSet(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteHolderGetter.apply(context)); } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java index 8e9d853661..eccb8ba081 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java @@ -16,13 +16,13 @@ import java.util.List; public final class HttpServerAttributesExtractorBuilder { final HttpServerAttributesGetter httpAttributesGetter; - final NetServerAttributesGetter netAttributesGetter; + final NetServerAttributesGetter netAttributesGetter; List capturedRequestHeaders = emptyList(); List capturedResponseHeaders = emptyList(); HttpServerAttributesExtractorBuilder( HttpServerAttributesGetter httpAttributesGetter, - NetServerAttributesGetter netAttributesGetter) { + NetServerAttributesGetter netAttributesGetter) { this.httpAttributesGetter = httpAttributesGetter; this.netAttributesGetter = netAttributesGetter; } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetter.java index b8f9a34305..7ce7783df6 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetter.java @@ -18,8 +18,8 @@ import javax.annotation.Nullable; * NetServerAttributesGetter#getHostSocketAddress(Object)} methods instead. */ @Deprecated -public abstract class InetSocketAddressNetServerAttributesGetter - implements NetServerAttributesGetter { +public abstract class InetSocketAddressNetServerAttributesGetter + implements NetServerAttributesGetter { @Nullable @Override diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressUtil.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressUtil.java index 1ca432383b..e172ff9e1a 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressUtil.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressUtil.java @@ -28,6 +28,19 @@ final class InetSocketAddressUtil { return null; } + @Nullable + static String getNetworkType( + @Nullable InetSocketAddress address, @Nullable InetSocketAddress otherAddress) { + if (address == null) { + address = otherAddress; + } + if (address == null) { + return null; + } + InetAddress remoteAddress = address.getAddress(); + return remoteAddress instanceof Inet6Address ? "ipv6" : "ipv4"; + } + @Nullable static String getHostName(@Nullable InetSocketAddress address) { if (address == null) { diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java index 4cfd9186d5..eb784237c2 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 @@ -10,6 +10,9 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.FallbackNamePortGetter; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter; +import io.opentelemetry.instrumentation.api.internal.SemconvStability; import javax.annotation.Nullable; /** @@ -25,6 +28,7 @@ public final class NetClientAttributesExtractor implements AttributesExtractor { private final InternalNetClientAttributesExtractor internalExtractor; + private final InternalNetworkAttributesExtractor internalNetworkExtractor; public static AttributesExtractor create( NetClientAttributesGetter getter) { @@ -34,7 +38,16 @@ public final class NetClientAttributesExtractor private NetClientAttributesExtractor(NetClientAttributesGetter getter) { internalExtractor = new InternalNetClientAttributesExtractor<>( - getter, (port, request) -> true, FallbackNamePortGetter.noop()); + getter, + (port, request) -> true, + FallbackNamePortGetter.noop(), + SemconvStability.emitOldHttpSemconv()); + internalNetworkExtractor = + new InternalNetworkAttributesExtractor<>( + getter, + NetworkTransportFilter.alwaysTrue(), + SemconvStability.emitStableHttpSemconv(), + SemconvStability.emitOldHttpSemconv()); } @Override @@ -50,5 +63,6 @@ public final class NetClientAttributesExtractor @Nullable RESPONSE response, @Nullable Throwable error) { internalExtractor.onEnd(attributes, request, response); + internalNetworkExtractor.onEnd(attributes, request, response); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesGetter.java index c819136422..0a83bff2b2 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesGetter.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.net; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import java.net.InetSocketAddress; import javax.annotation.Nullable; @@ -16,7 +17,8 @@ import javax.annotation.Nullable; * library/framework. It will be used by the NetClientAttributesExtractor to obtain the various * network attributes in a type-generic way. */ -public interface NetClientAttributesGetter { +public interface NetClientAttributesGetter + extends NetworkAttributesGetter { @Nullable default String getTransport(REQUEST request, @Nullable RESPONSE response) { @@ -27,7 +29,11 @@ public interface NetClientAttributesGetter { * Returns the application protocol used. * *

Examples: `amqp`, `http`, `mqtt`. + * + * @deprecated This method is deprecated and will be removed in the following release. Implement + * {@link #getNetworkProtocolName(Object, Object)} instead. */ + @Deprecated @Nullable default String getProtocolName(REQUEST request, @Nullable RESPONSE response) { return null; @@ -37,12 +43,37 @@ public interface NetClientAttributesGetter { * Returns the version of the application protocol used. * *

Examples: `3.1.1`. + * + * @deprecated This method is deprecated and will be removed in the following release. Implement + * {@link #getNetworkProtocolVersion(Object, Object)} instead. */ + @Deprecated @Nullable default String getProtocolVersion(REQUEST request, @Nullable RESPONSE response) { return null; } + /** {@inheritDoc} */ + @Nullable + @Override + default String getNetworkType(REQUEST request, @Nullable RESPONSE response) { + return InetSocketAddressUtil.getNetworkType(getPeerSocketAddress(request, response), null); + } + + /** {@inheritDoc} */ + @Nullable + @Override + default String getNetworkProtocolName(REQUEST request, @Nullable RESPONSE response) { + return getProtocolName(request, response); + } + + /** {@inheritDoc} */ + @Nullable + @Override + default String getNetworkProtocolVersion(REQUEST request, @Nullable RESPONSE response) { + return getProtocolVersion(request, response); + } + @Nullable String getPeerName(REQUEST request); 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 528259448f..e9de6fe859 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 @@ -10,6 +10,9 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.FallbackNamePortGetter; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter; +import io.opentelemetry.instrumentation.api.internal.SemconvStability; import javax.annotation.Nullable; /** @@ -20,17 +23,27 @@ import javax.annotation.Nullable; public final class NetServerAttributesExtractor implements AttributesExtractor { - private final InternalNetServerAttributesExtractor internalExtractor; - public static AttributesExtractor create( - NetServerAttributesGetter getter) { + NetServerAttributesGetter getter) { return new NetServerAttributesExtractor<>(getter); } - private NetServerAttributesExtractor(NetServerAttributesGetter getter) { + private final InternalNetServerAttributesExtractor internalExtractor; + private final InternalNetworkAttributesExtractor internalNetworkExtractor; + + private NetServerAttributesExtractor(NetServerAttributesGetter getter) { internalExtractor = new InternalNetServerAttributesExtractor<>( - getter, (integer, request) -> true, FallbackNamePortGetter.noop()); + getter, + (integer, request) -> true, + FallbackNamePortGetter.noop(), + SemconvStability.emitOldHttpSemconv()); + internalNetworkExtractor = + new InternalNetworkAttributesExtractor<>( + getter, + NetworkTransportFilter.alwaysTrue(), + SemconvStability.emitStableHttpSemconv(), + SemconvStability.emitOldHttpSemconv()); } @Override @@ -44,5 +57,7 @@ public final class NetServerAttributesExtractor Context context, REQUEST request, @Nullable RESPONSE response, - @Nullable Throwable error) {} + @Nullable Throwable error) { + internalNetworkExtractor.onEnd(attributes, request, response); + } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java index 6e42c78db7..b087028128 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.net; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import java.net.InetSocketAddress; import javax.annotation.Nullable; @@ -16,7 +17,8 @@ import javax.annotation.Nullable; * server library/framework. It will be used by the {@link NetServerAttributesExtractor} to obtain * the various network attributes in a type-generic way. */ -public interface NetServerAttributesGetter { +public interface NetServerAttributesGetter + extends NetworkAttributesGetter { @Nullable default String getTransport(REQUEST request) { @@ -27,7 +29,11 @@ public interface NetServerAttributesGetter { * Returns the application protocol used. * *

Examples: `amqp`, `http`, `mqtt`. + * + * @deprecated This method is deprecated and will be removed in the following release. Implement + * {@link #getNetworkProtocolName(Object, Object)} instead. */ + @Deprecated @Nullable default String getProtocolName(REQUEST request) { return null; @@ -37,12 +43,38 @@ public interface NetServerAttributesGetter { * Returns the version of the application protocol used. * *

Examples: `3.1.1`. + * + * @deprecated This method is deprecated and will be removed in the following release. Implement + * {@link #getNetworkProtocolVersion(Object, Object)} instead. */ + @Deprecated @Nullable default String getProtocolVersion(REQUEST request) { return null; } + /** {@inheritDoc} */ + @Nullable + @Override + default String getNetworkType(REQUEST request, @Nullable RESPONSE response) { + return InetSocketAddressUtil.getNetworkType( + getPeerSocketAddress(request), getHostSocketAddress(request)); + } + + /** {@inheritDoc} */ + @Nullable + @Override + default String getNetworkProtocolName(REQUEST request, @Nullable RESPONSE response) { + return getProtocolName(request); + } + + /** {@inheritDoc} */ + @Nullable + @Override + default String getNetworkProtocolVersion(REQUEST request, @Nullable RESPONSE response) { + return getProtocolVersion(request); + } + @Nullable String getHostName(REQUEST request); 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 12df123044..8d6c5a7fd9 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 @@ -10,7 +10,6 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorU import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import java.util.Locale; import java.util.function.BiPredicate; import javax.annotation.Nullable; @@ -23,14 +22,17 @@ public final class InternalNetClientAttributesExtractor { private final NetClientAttributesGetter getter; private final BiPredicate capturePeerPortCondition; private final FallbackNamePortGetter fallbackNamePortGetter; + private final boolean emitOldHttpAttributes; public InternalNetClientAttributesExtractor( NetClientAttributesGetter getter, BiPredicate capturePeerPortCondition, - FallbackNamePortGetter fallbackNamePortGetter) { + FallbackNamePortGetter fallbackNamePortGetter, + boolean emitOldHttpAttributes) { this.getter = getter; this.capturePeerPortCondition = capturePeerPortCondition; this.fallbackNamePortGetter = fallbackNamePortGetter; + this.emitOldHttpAttributes = emitOldHttpAttributes; } public void onStart(AttributesBuilder attributes, REQUEST request) { @@ -48,17 +50,10 @@ public final class InternalNetClientAttributesExtractor { public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) { - internalSet( - attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request, response)); - String protocolName = getter.getProtocolName(request, response); - if (protocolName != null) { + if (emitOldHttpAttributes) { internalSet( - attributes, NetAttributes.NET_PROTOCOL_NAME, protocolName.toLowerCase(Locale.ROOT)); + attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request, response)); } - internalSet( - attributes, - NetAttributes.NET_PROTOCOL_VERSION, - getter.getProtocolVersion(request, response)); String peerName = extractPeerName(request); @@ -72,9 +67,11 @@ public final class InternalNetClientAttributesExtractor { internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) sockPeerPort); } - String sockFamily = getter.getSockFamily(request, response); - if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) { - internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily); + if (emitOldHttpAttributes) { + String sockFamily = getter.getSockFamily(request, response); + if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) { + internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily); + } } String sockPeerName = getter.getSockPeerName(request, response); 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 82655a0f99..f4da0a3c80 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 @@ -10,37 +10,35 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorU import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import java.util.Locale; import java.util.function.BiPredicate; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class InternalNetServerAttributesExtractor { +public final class InternalNetServerAttributesExtractor { - private final NetServerAttributesGetter getter; + private final NetServerAttributesGetter getter; private final BiPredicate captureHostPortCondition; private final FallbackNamePortGetter fallbackNamePortGetter; + private final boolean emitOldHttpAttributes; public InternalNetServerAttributesExtractor( - NetServerAttributesGetter getter, + NetServerAttributesGetter getter, BiPredicate captureHostPortCondition, - FallbackNamePortGetter fallbackNamePortGetter) { + FallbackNamePortGetter fallbackNamePortGetter, + boolean emitOldHttpAttributes) { this.getter = getter; this.captureHostPortCondition = captureHostPortCondition; this.fallbackNamePortGetter = fallbackNamePortGetter; + this.emitOldHttpAttributes = emitOldHttpAttributes; } public void onStart(AttributesBuilder attributes, REQUEST request) { - internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request)); - String protocolName = getter.getProtocolName(request); - if (protocolName != null) { - internalSet( - attributes, NetAttributes.NET_PROTOCOL_NAME, protocolName.toLowerCase(Locale.ROOT)); + if (emitOldHttpAttributes) { + internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request)); } - internalSet(attributes, NetAttributes.NET_PROTOCOL_VERSION, getter.getProtocolVersion(request)); boolean setSockFamily = false; @@ -79,7 +77,7 @@ public final class InternalNetServerAttributesExtractor { } } - if (setSockFamily) { + if (emitOldHttpAttributes && setSockFamily) { String sockFamily = getter.getSockFamily(request); if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) { internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily); diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java new file mode 100644 index 0000000000..ed3de6712d --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java @@ -0,0 +1,56 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network; + +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter; +import javax.annotation.Nullable; + +/** + * Extractor of network + * attributes. + */ +public final class NetworkAttributesExtractor + implements AttributesExtractor { + + /** + * Returns a new {@link NetworkAttributesExtractor} that will use the passed {@link + * NetworkAttributesGetter}. + */ + public static NetworkAttributesExtractor create( + NetworkAttributesGetter getter) { + return new NetworkAttributesExtractor<>(getter); + } + + private final InternalNetworkAttributesExtractor internalExtractor; + + NetworkAttributesExtractor(NetworkAttributesGetter getter) { + // the NetworkAttributesExtractor will always emit new semconv + internalExtractor = + new InternalNetworkAttributesExtractor<>( + getter, + NetworkTransportFilter.alwaysTrue(), + /* emitStableUrlAttributes= */ true, + /* emitOldHttpAttributes= */ false); + } + + @Override + public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {} + + @Override + public void onEnd( + AttributesBuilder attributes, + Context context, + REQUEST request, + @Nullable RESPONSE response, + @Nullable Throwable error) { + internalExtractor.onEnd(attributes, request, response); + } +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesGetter.java new file mode 100644 index 0000000000..0c172d253e --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesGetter.java @@ -0,0 +1,62 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network; + +import javax.annotation.Nullable; + +/** + * An interface for getting network attributes. + * + *

Instrumentation authors will create implementations of this interface for their specific + * library/framework. It will be used by the {@link NetworkAttributesExtractor} (or other convention + * specific extractors) to obtain the various network attributes in a type-generic way. + */ +public interface NetworkAttributesGetter { + + /** + * Returns the OSI Transport Layer or Inter-process Communication + * method. + * + *

Examples: {@code tcp}, {@code udp} + */ + @Nullable + default String getNetworkTransport(REQUEST request, @Nullable RESPONSE response) { + return null; + } + + /** + * Returns the OSI Network Layer or non-OSI + * equivalent. + * + *

Examples: {@code ipv4}, {@code ipv6} + */ + @Nullable + default String getNetworkType(REQUEST request, @Nullable RESPONSE response) { + return null; + } + + /** + * Returns the OSI Application Layer or + * non-OSI equivalent. + * + *

Examples: {@code ampq}, {@code http}, {@code mqtt} + */ + @Nullable + default String getNetworkProtocolName(REQUEST request, @Nullable RESPONSE response) { + return null; + } + + /** + * Returns the version of the application layer protocol used. + * + *

Examples: {@code 3.1.1} + */ + @Nullable + default String getNetworkProtocolVersion(REQUEST request, @Nullable RESPONSE response) { + return null; + } +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java new file mode 100644 index 0000000000..957f0b75ec --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java @@ -0,0 +1,67 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network.internal; + +import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; + +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; +import java.util.Locale; +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 InternalNetworkAttributesExtractor { + + private final NetworkAttributesGetter getter; + private final NetworkTransportFilter networkTransportFilter; + private final boolean emitStableUrlAttributes; + private final boolean emitOldHttpAttributes; + + public InternalNetworkAttributesExtractor( + NetworkAttributesGetter getter, + NetworkTransportFilter networkTransportFilter, + boolean emitStableUrlAttributes, + boolean emitOldHttpAttributes) { + this.getter = getter; + this.networkTransportFilter = networkTransportFilter; + this.emitStableUrlAttributes = emitStableUrlAttributes; + this.emitOldHttpAttributes = emitOldHttpAttributes; + } + + public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) { + String protocolName = lowercase(getter.getNetworkProtocolName(request, response)); + String protocolVersion = lowercase(getter.getNetworkProtocolVersion(request, response)); + + if (emitStableUrlAttributes) { + String transport = lowercase(getter.getNetworkTransport(request, response)); + if (networkTransportFilter.shouldAddNetworkTransport( + protocolName, protocolVersion, transport)) { + internalSet(attributes, NetworkAttributes.NETWORK_TRANSPORT, transport); + } + internalSet( + attributes, + NetworkAttributes.NETWORK_TYPE, + lowercase(getter.getNetworkType(request, response))); + internalSet(attributes, NetworkAttributes.NETWORK_PROTOCOL_NAME, protocolName); + internalSet(attributes, NetworkAttributes.NETWORK_PROTOCOL_VERSION, protocolVersion); + } + if (emitOldHttpAttributes) { + // net.transport and net.sock.family are not 1:1 convertible with network.transport and + // network.type; they must be handled separately in the old net.* extractors + internalSet(attributes, NetAttributes.NET_PROTOCOL_NAME, protocolName); + internalSet(attributes, NetAttributes.NET_PROTOCOL_VERSION, protocolVersion); + } + } + + @Nullable + private static String lowercase(@Nullable String str) { + return str == null ? null : str.toLowerCase(Locale.ROOT); + } +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkAttributes.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkAttributes.java new file mode 100644 index 0000000000..a1a893e0be --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkAttributes.java @@ -0,0 +1,32 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network.internal; + +import static io.opentelemetry.api.common.AttributeKey.stringKey; + +import io.opentelemetry.api.common.AttributeKey; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class NetworkAttributes { + + // FIXME: remove this class and replace its usages with SemanticAttributes once schema 1.20 is + // released + + public static final AttributeKey NETWORK_TRANSPORT = stringKey("network.transport"); + + public static final AttributeKey NETWORK_TYPE = stringKey("network.type"); + + public static final AttributeKey NETWORK_PROTOCOL_NAME = + stringKey("network.protocol.name"); + + public static final AttributeKey NETWORK_PROTOCOL_VERSION = + stringKey("network.protocol.version"); + + private NetworkAttributes() {} +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkTransportFilter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkTransportFilter.java new file mode 100644 index 0000000000..87b32c9dc1 --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkTransportFilter.java @@ -0,0 +1,25 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network.internal; + +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. + */ +@FunctionalInterface +public interface NetworkTransportFilter { + + boolean shouldAddNetworkTransport( + @Nullable String protocolName, + @Nullable String protocolVersion, + @Nullable String proposedTransport); + + static NetworkTransportFilter alwaysTrue() { + return (protocolName, protocolVersion, proposedTransport) -> true; + } +} 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 c5ac160ce0..c7c425209a 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 @@ -73,14 +73,28 @@ class HttpClientAttributesExtractorTest { @Nullable @Override - public String getProtocolName( + public String getNetworkTransport( + Map request, @Nullable Map response) { + return request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType( + Map request, @Nullable Map response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName( Map request, @Nullable Map response) { return request.get("protocolName"); } @Nullable @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( Map request, @Nullable Map response) { return request.get("protocolVersion"); } @@ -107,6 +121,8 @@ class HttpClientAttributesExtractorTest { request.put("header.content-length", "10"); request.put("header.user-agent", "okhttp 3.x"); request.put("header.custom-request-header", "123,456"); + request.put("transport", "tcp"); + request.put("type", "ipv4"); request.put("protocolName", "http"); request.put("protocolVersion", "1.1"); request.put("peerName", "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 dd44d695aa..0c1b4be4f6 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 @@ -87,17 +87,33 @@ class HttpServerAttributesExtractorTest { } static class TestNetServerAttributesGetter - implements NetServerAttributesGetter> { + implements NetServerAttributesGetter, Map> { @Nullable @Override - public String getProtocolName(Map request) { + public String getNetworkTransport( + Map request, @Nullable Map response) { + return (String) request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType( + Map request, @Nullable Map response) { + return (String) request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName( + Map request, Map response) { return (String) request.get("protocolName"); } @Nullable @Override - public String getProtocolVersion(Map request) { + public String getNetworkProtocolVersion( + Map request, Map response) { return (String) request.get("protocolVersion"); } @@ -128,6 +144,8 @@ class HttpServerAttributesExtractorTest { request.put("header.host", "github.com"); request.put("header.forwarded", "for=1.1.1.1;proto=https"); request.put("header.custom-request-header", "123,456"); + request.put("transport", "tcp"); + request.put("type", "ipv4"); request.put("protocolName", "http"); request.put("protocolVersion", "2.0"); @@ -151,8 +169,6 @@ class HttpServerAttributesExtractorTest { assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.NET_HOST_NAME, "github.com"), - entry(NetAttributes.NET_PROTOCOL_NAME, "http"), - entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"), entry(SemanticAttributes.HTTP_METHOD, "POST"), entry(SemanticAttributes.HTTP_SCHEME, "https"), entry(SemanticAttributes.HTTP_TARGET, "/repositories/1?details=true"), @@ -167,6 +183,8 @@ class HttpServerAttributesExtractorTest { extractor.onEnd(endAttributes, Context.root(), request, response, null); assertThat(endAttributes.build()) .containsOnly( + entry(NetAttributes.NET_PROTOCOL_NAME, "http"), + entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"), entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"), entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L), entry(SemanticAttributes.HTTP_STATUS_CODE, 202L), diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java index 3e3c7c7208..a819b14431 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java @@ -21,7 +21,8 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class InetSocketAddressNetServerAttributesGetterTest { - static class TestNetServerAttributesGetter implements NetServerAttributesGetter { + static class TestNetServerAttributesGetter + implements NetServerAttributesGetter { @Override public String getHostName(Addresses request) { diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java index 424f3f4fe6..bf6b4b9809 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java @@ -29,19 +29,33 @@ class NetClientAttributesExtractorTest { @Override public String getTransport(Map request, Map response) { - return response.get("transport"); + return response.get("netTransport"); } @Nullable @Override - public String getProtocolName( + public String getNetworkTransport( + Map request, @Nullable Map response) { + return request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType( + Map request, @Nullable Map response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName( Map request, @Nullable Map response) { return request.get("protocolName"); } @Nullable @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( Map request, @Nullable Map response) { return request.get("protocolVersion"); } @@ -86,7 +100,9 @@ class NetClientAttributesExtractorTest { void normal() { // given Map map = new HashMap<>(); - map.put("transport", IP_TCP); + map.put("netTransport", IP_TCP); + map.put("transport", "tcp"); + map.put("type", "ipv6"); map.put("protocolName", "http"); map.put("protocolVersion", "1.1"); map.put("peerName", "opentelemetry.io"); @@ -144,7 +160,7 @@ class NetClientAttributesExtractorTest { void doesNotSetDuplicates1() { // given Map map = new HashMap<>(); - map.put("transport", IP_TCP); + map.put("netTransport", IP_TCP); map.put("peerName", "1:2:3:4::"); map.put("peerPort", "42"); map.put("sockFamily", "inet6"); @@ -176,7 +192,7 @@ class NetClientAttributesExtractorTest { void doesNotSetDuplicates2() { // given Map map = new HashMap<>(); - map.put("transport", IP_TCP); + map.put("netTransport", IP_TCP); map.put("peerName", "opentelemetry.io"); map.put("peerPort", "42"); map.put("sockFamily", "inet6"); diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java index 5f8030b51f..cb6f056e52 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java @@ -25,22 +25,34 @@ import org.junit.jupiter.api.Test; class NetServerAttributesExtractorTest { static class TestNetServerAttributesGetter - implements NetServerAttributesGetter> { + implements NetServerAttributesGetter, Void> { @Override public String getTransport(Map request) { + return request.get("netTransport"); + } + + @Nullable + @Override + public String getNetworkTransport(Map request, @Nullable Void response) { return request.get("transport"); } @Nullable @Override - public String getProtocolName(Map request) { + public String getNetworkType(Map request, @Nullable Void response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName(Map request, Void response) { return request.get("protocolName"); } @Nullable @Override - public String getProtocolVersion(Map request) { + public String getNetworkProtocolVersion(Map request, Void response) { return request.get("protocolVersion"); } @@ -88,14 +100,16 @@ class NetServerAttributesExtractorTest { } } - AttributesExtractor, Map> extractor = + AttributesExtractor, Void> extractor = NetServerAttributesExtractor.create(new TestNetServerAttributesGetter()); @Test void normal() { // given Map map = new HashMap<>(); - map.put("transport", IP_TCP); + map.put("netTransport", IP_TCP); + map.put("transport", "tcp"); + map.put("type", "ipv6"); map.put("protocolName", "http"); map.put("protocolVersion", "1.1"); map.put("hostName", "opentelemetry.io"); @@ -113,14 +127,12 @@ class NetServerAttributesExtractorTest { extractor.onStart(startAttributes, context, map); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); + extractor.onEnd(endAttributes, context, map, null, null); // then assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), - entry(NetAttributes.NET_PROTOCOL_NAME, "http"), - entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"), entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"), entry(SemanticAttributes.NET_HOST_PORT, 80L), entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"), @@ -129,7 +141,10 @@ class NetServerAttributesExtractorTest { entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"), entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L)); - assertThat(endAttributes.build()).isEmpty(); + assertThat(endAttributes.build()) + .containsOnly( + entry(NetAttributes.NET_PROTOCOL_NAME, "http"), + entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1")); } @Test @@ -142,7 +157,7 @@ class NetServerAttributesExtractorTest { extractor.onStart(startAttributes, context, emptyMap()); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, emptyMap(), emptyMap(), null); + extractor.onEnd(endAttributes, context, emptyMap(), null, null); // then assertThat(startAttributes.build()).isEmpty(); @@ -155,7 +170,7 @@ class NetServerAttributesExtractorTest { void doesNotSetDuplicates1() { // given Map map = new HashMap<>(); - map.put("transport", IP_TCP); + map.put("netTransport", IP_TCP); map.put("hostName", "4:3:2:1::"); map.put("hostPort", "80"); map.put("sockFamily", "inet6"); @@ -169,7 +184,7 @@ class NetServerAttributesExtractorTest { extractor.onStart(startAttributes, context, map); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); + extractor.onEnd(endAttributes, context, map, null, null); // then assertThat(startAttributes.build()) @@ -187,7 +202,7 @@ class NetServerAttributesExtractorTest { void doesNotSetDuplicates2() { // given Map map = new HashMap<>(); - map.put("transport", IP_TCP); + map.put("netTransport", IP_TCP); map.put("hostName", "opentelemetry.io"); map.put("hostPort", "80"); map.put("sockFamily", "inet6"); @@ -201,7 +216,7 @@ class NetServerAttributesExtractorTest { extractor.onStart(startAttributes, context, map); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); + extractor.onEnd(endAttributes, context, map, null, null); // then assertThat(startAttributes.build()) @@ -233,7 +248,7 @@ class NetServerAttributesExtractorTest { extractor.onStart(startAttributes, context, map); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); + extractor.onEnd(endAttributes, context, map, null, null); // then assertThat(startAttributes.build()) @@ -260,7 +275,7 @@ class NetServerAttributesExtractorTest { extractor.onStart(startAttributes, context, map); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); + extractor.onEnd(endAttributes, context, map, null, null); // then assertThat(startAttributes.build()) diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java new file mode 100644 index 0000000000..9370314066 --- /dev/null +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java @@ -0,0 +1,90 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static java.util.Collections.emptyMap; +import static org.assertj.core.api.Assertions.entry; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; +import org.junit.jupiter.api.Test; + +class NetworkAttributesExtractorTest { + + static class TestNetworkAttributesGetter + implements NetworkAttributesGetter, Void> { + + @Nullable + @Override + public String getNetworkTransport(Map request, @Nullable Void response) { + return request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType(Map request, @Nullable Void response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName(Map request, @Nullable Void response) { + return request.get("protocolName"); + } + + @Nullable + @Override + public String getNetworkProtocolVersion(Map request, @Nullable Void response) { + return request.get("protocolVersion"); + } + } + + @Test + void allAttributes() { + Map request = new HashMap<>(); + request.put("transport", "TcP"); + request.put("type", "IPv4"); + request.put("protocolName", "Http"); + request.put("protocolVersion", "1.1"); + + AttributesExtractor, Void> extractor = + NetworkAttributesExtractor.create(new TestNetworkAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()).isEmpty(); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, null, null); + assertThat(endAttributes.build()) + .containsOnly( + entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), + entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), + entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); + } + + @Test + void noAttributes() { + AttributesExtractor, Void> extractor = + NetworkAttributesExtractor.create(new TestNetworkAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), emptyMap()); + assertThat(startAttributes.build()).isEmpty(); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null); + assertThat(endAttributes.build()).isEmpty(); + } +} diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBothSemconvTest.java index ca9c6c6365..767feda1b2 100644 --- a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBothSemconvTest.java +++ b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBothSemconvTest.java @@ -18,6 +18,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; @@ -67,14 +68,28 @@ class HttpClientAttributesExtractorBothSemconvTest { @Nullable @Override - public String getProtocolName( + public String getNetworkTransport( + Map request, @Nullable Map response) { + return request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType( + Map request, @Nullable Map response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName( Map request, @Nullable Map response) { return request.get("protocolName"); } @Nullable @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( Map request, @Nullable Map response) { return request.get("protocolVersion"); } @@ -101,6 +116,8 @@ class HttpClientAttributesExtractorBothSemconvTest { request.put("header.content-length", "10"); request.put("header.user-agent", "okhttp 3.x"); request.put("header.custom-request-header", "123,456"); + request.put("transport", "udp"); + request.put("type", "ipv4"); request.put("protocolName", "http"); request.put("protocolVersion", "1.1"); request.put("peerName", "github.com"); @@ -151,6 +168,10 @@ class HttpClientAttributesExtractorBothSemconvTest { AttributeKey.stringArrayKey("http.response.header.custom_response_header"), asList("654", "321")), entry(NetAttributes.NET_PROTOCOL_NAME, "http"), - entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1")); + entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"), + entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"), + entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), + entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); } } diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java index 6c5a21ddc5..5f511cebcb 100644 --- a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java +++ b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java @@ -17,6 +17,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; @@ -80,17 +81,33 @@ class HttpServerAttributesExtractorBothSemconvTest { } static class TestNetServerAttributesGetter - implements NetServerAttributesGetter> { + implements NetServerAttributesGetter, Map> { @Nullable @Override - public String getProtocolName(Map request) { + public String getNetworkTransport( + Map request, @Nullable Map response) { + return (String) request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType( + Map request, @Nullable Map response) { + return (String) request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName( + Map request, Map response) { return (String) request.get("protocolName"); } @Nullable @Override - public String getProtocolVersion(Map request) { + public String getNetworkProtocolVersion( + Map request, Map response) { return (String) request.get("protocolVersion"); } @@ -121,6 +138,8 @@ class HttpServerAttributesExtractorBothSemconvTest { request.put("header.host", "github.com"); request.put("header.forwarded", "for=1.1.1.1;proto=https"); request.put("header.custom-request-header", "123,456"); + request.put("transport", "udp"); + request.put("type", "ipv4"); request.put("protocolName", "http"); request.put("protocolVersion", "2.0"); @@ -144,8 +163,6 @@ class HttpServerAttributesExtractorBothSemconvTest { assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.NET_HOST_NAME, "github.com"), - entry(NetAttributes.NET_PROTOCOL_NAME, "http"), - entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"), entry(SemanticAttributes.HTTP_METHOD, "POST"), entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"), entry(SemanticAttributes.HTTP_SCHEME, "http"), @@ -164,6 +181,12 @@ class HttpServerAttributesExtractorBothSemconvTest { extractor.onEnd(endAttributes, Context.root(), request, response, null); assertThat(endAttributes.build()) .containsOnly( + entry(NetAttributes.NET_PROTOCOL_NAME, "http"), + entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"), + entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"), + entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), + entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"), entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L), entry(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 10L), diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java new file mode 100644 index 0000000000..96f2c5ffea --- /dev/null +++ b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java @@ -0,0 +1,143 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.net; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; +import static org.assertj.core.api.Assertions.entry; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; +import org.junit.jupiter.api.Test; + +class NetClientAttributesExtractorBothSemconvTest { + + static class TestNetClientAttributesGetter + implements NetClientAttributesGetter, Map> { + + @Override + public String getTransport(Map request, Map response) { + return response.get("netTransport"); + } + + @Nullable + @Override + public String getNetworkTransport( + Map request, @Nullable Map response) { + return request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType( + Map request, @Nullable Map response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName( + Map request, @Nullable Map response) { + return request.get("protocolName"); + } + + @Nullable + @Override + public String getNetworkProtocolVersion( + Map request, @Nullable Map response) { + return request.get("protocolVersion"); + } + + @Override + public String getPeerName(Map request) { + return request.get("peerName"); + } + + @Override + public Integer getPeerPort(Map request) { + String peerPort = request.get("peerPort"); + return peerPort == null ? null : Integer.valueOf(peerPort); + } + + @Override + public String getSockFamily(Map request, Map response) { + return response.get("sockFamily"); + } + + @Override + public String getSockPeerAddr(Map request, Map response) { + return response.get("sockPeerAddr"); + } + + @Override + public String getSockPeerName(Map request, Map response) { + return response.get("sockPeerName"); + } + + @Override + public Integer getSockPeerPort(Map request, Map response) { + String sockPeerPort = response.get("sockPeerPort"); + return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort); + } + } + + private final AttributesExtractor, Map> extractor = + NetClientAttributesExtractor.create(new TestNetClientAttributesGetter()); + + @Test + void normal() { + // given + Map map = new HashMap<>(); + map.put("netTransport", IP_TCP); + map.put("transport", "tcp"); + map.put("type", "ipv6"); + map.put("protocolName", "http"); + map.put("protocolVersion", "1.1"); + map.put("peerName", "opentelemetry.io"); + map.put("peerPort", "42"); + map.put("sockFamily", "inet6"); + map.put("sockPeerAddr", "1:2:3:4::"); + map.put("sockPeerName", "proxy.opentelemetry.io"); + map.put("sockPeerPort", "123"); + + Context context = Context.root(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, context, map); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, context, map, map, null); + + // then + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"), + entry(SemanticAttributes.NET_PEER_PORT, 42L)); + + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), + entry(NetAttributes.NET_PROTOCOL_NAME, "http"), + entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"), + entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), + entry(NetworkAttributes.NETWORK_TYPE, "ipv6"), + entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"), + entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), + entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"), + entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L)); + } +} diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java new file mode 100644 index 0000000000..9009d6f258 --- /dev/null +++ b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java @@ -0,0 +1,152 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.net; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; +import static org.assertj.core.api.Assertions.entry; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; +import org.junit.jupiter.api.Test; + +class NetServerAttributesExtractorBothSemconvTest { + + static class TestNetServerAttributesGetter + implements NetServerAttributesGetter, Void> { + + @Override + public String getTransport(Map request) { + return request.get("netTransport"); + } + + @Nullable + @Override + public String getNetworkTransport(Map request, @Nullable Void response) { + return request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType(Map request, @Nullable Void response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName(Map request, Void response) { + return request.get("protocolName"); + } + + @Nullable + @Override + public String getNetworkProtocolVersion(Map request, Void response) { + return request.get("protocolVersion"); + } + + @Nullable + @Override + public String getHostName(Map request) { + return request.get("hostName"); + } + + @Nullable + @Override + public Integer getHostPort(Map request) { + String hostPort = request.get("hostPort"); + return hostPort == null ? null : Integer.valueOf(hostPort); + } + + @Nullable + @Override + public String getSockFamily(Map request) { + return request.get("sockFamily"); + } + + @Override + public String getSockPeerAddr(Map request) { + return request.get("sockPeerAddr"); + } + + @Override + public Integer getSockPeerPort(Map request) { + String sockPeerPort = request.get("sockPeerPort"); + return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort); + } + + @Nullable + @Override + public String getSockHostAddr(Map request) { + return request.get("sockHostAddr"); + } + + @Nullable + @Override + public Integer getSockHostPort(Map request) { + String sockHostPort = request.get("sockHostPort"); + return sockHostPort == null ? null : Integer.valueOf(sockHostPort); + } + } + + AttributesExtractor, Void> extractor = + NetServerAttributesExtractor.create(new TestNetServerAttributesGetter()); + + @Test + void normal() { + // given + Map map = new HashMap<>(); + map.put("netTransport", IP_TCP); + map.put("transport", "tcp"); + map.put("type", "ipv6"); + map.put("protocolName", "http"); + map.put("protocolVersion", "1.1"); + map.put("hostName", "opentelemetry.io"); + map.put("hostPort", "80"); + map.put("sockFamily", "inet6"); + map.put("sockPeerAddr", "1:2:3:4::"); + map.put("sockPeerPort", "42"); + map.put("sockHostAddr", "4:3:2:1::"); + map.put("sockHostPort", "8080"); + + Context context = Context.root(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, context, map); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, context, map, null, null); + + // then + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), + entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"), + entry(SemanticAttributes.NET_HOST_PORT, 80L), + entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"), + entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), + entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L), + entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"), + entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L)); + + assertThat(endAttributes.build()) + .containsOnly( + entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), + entry(NetworkAttributes.NETWORK_TYPE, "ipv6"), + entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + entry(NetAttributes.NET_PROTOCOL_NAME, "http"), + entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1")); + } +} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java index b1d4d058ea..22c87df0c6 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java @@ -8,8 +8,10 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; 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; @@ -17,15 +19,21 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; -import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.ToIntFunction; +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 HttpClientAttributesExtractorStableSemconvTest { @@ -51,7 +59,8 @@ class HttpClientAttributesExtractorStableSemconvTest { @Override public Integer getHttpResponseStatusCode( Map request, Map response, @Nullable Throwable error) { - return Integer.parseInt(response.get("statusCode")); + String value = response.get("statusCode"); + return value == null ? null : Integer.parseInt(value); } @Override @@ -67,14 +76,28 @@ class HttpClientAttributesExtractorStableSemconvTest { @Nullable @Override - public String getProtocolName( + public String getNetworkTransport( + Map request, @Nullable Map response) { + return request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType( + Map request, @Nullable Map response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName( Map request, @Nullable Map response) { return request.get("protocolName"); } @Nullable @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( Map request, @Nullable Map response) { return request.get("protocolVersion"); } @@ -88,8 +111,8 @@ class HttpClientAttributesExtractorStableSemconvTest { @Nullable @Override public Integer getPeerPort(Map request) { - String statusCode = request.get("peerPort"); - return statusCode == null ? null : Integer.parseInt(statusCode); + String value = request.get("peerPort"); + return value == null ? null : Integer.parseInt(value); } } @@ -101,6 +124,8 @@ class HttpClientAttributesExtractorStableSemconvTest { request.put("header.content-length", "10"); request.put("header.user-agent", "okhttp 3.x"); request.put("header.custom-request-header", "123,456"); + request.put("transport", "udp"); + request.put("type", "ipv4"); request.put("protocolName", "http"); request.put("protocolVersion", "1.1"); request.put("peerName", "github.com"); @@ -145,7 +170,53 @@ class HttpClientAttributesExtractorStableSemconvTest { entry( AttributeKey.stringArrayKey("http.response.header.custom_response_header"), asList("654", "321")), - entry(NetAttributes.NET_PROTOCOL_NAME, "http"), - entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1")); + entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"), + entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), + entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); + } + + @ParameterizedTest + @ArgumentsSource(NetworkTransportAndProtocolProvider.class) + void skipNetworkTransportIfDefaultForProtocol( + String observedProtocolName, + String observedProtocolVersion, + String observedTransport, + @Nullable String extractedTransport) { + Map request = new HashMap<>(); + request.put("protocolName", observedProtocolName); + request.put("protocolVersion", observedProtocolVersion); + request.put("transport", observedTransport); + + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.create( + new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + if (extractedTransport != null) { + assertThat(attributes.build()) + .containsEntry(NetworkAttributes.NETWORK_TRANSPORT, extractedTransport); + } else { + assertThat(attributes.build()).doesNotContainKey(NetworkAttributes.NETWORK_TRANSPORT); + } + } + + static final class NetworkTransportAndProtocolProvider implements ArgumentsProvider { + + @Override + public Stream provideArguments(ExtensionContext context) { + return Stream.of( + arguments("http", "1.0", "tcp", null), + arguments("http", "1.1", "tcp", null), + arguments("http", "2.0", "tcp", null), + arguments("http", "3.0", "udp", null), + arguments("http", "1.1", "udp", "udp"), + arguments("ftp", "2.0", "tcp", "tcp"), + arguments("http", "3.0", "tcp", "tcp"), + arguments("http", "42", "tcp", "tcp")); + } } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java index 4c90a0976c..a8d8314524 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java @@ -8,23 +8,32 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; 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; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; -import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; 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 HttpServerAttributesExtractorStableSemconvTest { @@ -80,17 +89,33 @@ class HttpServerAttributesExtractorStableSemconvTest { } static class TestNetServerAttributesGetter - implements NetServerAttributesGetter> { + implements NetServerAttributesGetter, Map> { @Nullable @Override - public String getProtocolName(Map request) { + public String getNetworkTransport( + Map request, @Nullable Map response) { + return (String) request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType( + Map request, @Nullable Map response) { + return (String) request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName( + Map request, Map response) { return (String) request.get("protocolName"); } @Nullable @Override - public String getProtocolVersion(Map request) { + public String getNetworkProtocolVersion( + Map request, Map response) { return (String) request.get("protocolVersion"); } @@ -121,6 +146,8 @@ class HttpServerAttributesExtractorStableSemconvTest { request.put("header.host", "github.com"); request.put("header.forwarded", "for=1.1.1.1;proto=https"); request.put("header.custom-request-header", "123,456"); + request.put("transport", "udp"); + request.put("type", "ipv4"); request.put("protocolName", "http"); request.put("protocolVersion", "2.0"); @@ -144,8 +171,6 @@ class HttpServerAttributesExtractorStableSemconvTest { assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.NET_HOST_NAME, "github.com"), - entry(NetAttributes.NET_PROTOCOL_NAME, "http"), - entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"), entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"), entry(UrlAttributes.URL_SCHEME, "http"), entry(UrlAttributes.URL_PATH, "/repositories/1"), @@ -161,6 +186,10 @@ class HttpServerAttributesExtractorStableSemconvTest { extractor.onEnd(endAttributes, Context.root(), request, response, null); assertThat(endAttributes.build()) .containsOnly( + entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"), + entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), + entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"), entry(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 10L), entry(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), @@ -169,4 +198,49 @@ class HttpServerAttributesExtractorStableSemconvTest { AttributeKey.stringArrayKey("http.response.header.custom_response_header"), asList("654", "321"))); } + + @ParameterizedTest + @ArgumentsSource(NetworkTransportAndProtocolProvider.class) + void skipNetworkTransportIfDefaultForProtocol( + String observedProtocolName, + String observedProtocolVersion, + String observedTransport, + @Nullable String extractedTransport) { + Map request = new HashMap<>(); + request.put("protocolName", observedProtocolName); + request.put("protocolVersion", observedProtocolVersion); + request.put("transport", observedTransport); + + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.create( + new HttpClientAttributesExtractorStableSemconvTest.TestHttpClientAttributesGetter(), + new HttpClientAttributesExtractorStableSemconvTest.TestNetClientAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + if (extractedTransport != null) { + assertThat(attributes.build()) + .containsEntry(NetworkAttributes.NETWORK_TRANSPORT, extractedTransport); + } else { + assertThat(attributes.build()).doesNotContainKey(NetworkAttributes.NETWORK_TRANSPORT); + } + } + + static final class NetworkTransportAndProtocolProvider implements ArgumentsProvider { + + @Override + public Stream provideArguments(ExtensionContext context) { + return Stream.of( + arguments("http", "1.0", "tcp", null), + arguments("http", "1.1", "tcp", null), + arguments("http", "2.0", "tcp", null), + arguments("http", "3.0", "udp", null), + arguments("http", "1.1", "udp", "udp"), + arguments("ftp", "2.0", "tcp", "tcp"), + arguments("http", "3.0", "tcp", "tcp"), + arguments("http", "42", "tcp", "tcp")); + } + } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java new file mode 100644 index 0000000000..9ef1350801 --- /dev/null +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java @@ -0,0 +1,138 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.net; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; +import static org.assertj.core.api.Assertions.entry; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; +import org.junit.jupiter.api.Test; + +class NetClientAttributesExtractorStableSemconvTest { + + static class TestNetClientAttributesGetter + implements NetClientAttributesGetter, Map> { + + @Override + public String getTransport(Map request, Map response) { + return response.get("netTransport"); + } + + @Nullable + @Override + public String getNetworkTransport( + Map request, @Nullable Map response) { + return request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType( + Map request, @Nullable Map response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName( + Map request, @Nullable Map response) { + return request.get("protocolName"); + } + + @Nullable + @Override + public String getNetworkProtocolVersion( + Map request, @Nullable Map response) { + return request.get("protocolVersion"); + } + + @Override + public String getPeerName(Map request) { + return request.get("peerName"); + } + + @Override + public Integer getPeerPort(Map request) { + String peerPort = request.get("peerPort"); + return peerPort == null ? null : Integer.valueOf(peerPort); + } + + @Override + public String getSockFamily(Map request, Map response) { + return response.get("sockFamily"); + } + + @Override + public String getSockPeerAddr(Map request, Map response) { + return response.get("sockPeerAddr"); + } + + @Override + public String getSockPeerName(Map request, Map response) { + return response.get("sockPeerName"); + } + + @Override + public Integer getSockPeerPort(Map request, Map response) { + String sockPeerPort = response.get("sockPeerPort"); + return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort); + } + } + + private final AttributesExtractor, Map> extractor = + NetClientAttributesExtractor.create(new TestNetClientAttributesGetter()); + + @Test + void normal() { + // given + Map map = new HashMap<>(); + map.put("netTransport", IP_TCP); + map.put("transport", "tcp"); + map.put("type", "ipv6"); + map.put("protocolName", "http"); + map.put("protocolVersion", "1.1"); + map.put("peerName", "opentelemetry.io"); + map.put("peerPort", "42"); + map.put("sockFamily", "inet6"); + map.put("sockPeerAddr", "1:2:3:4::"); + map.put("sockPeerName", "proxy.opentelemetry.io"); + map.put("sockPeerPort", "123"); + + Context context = Context.root(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, context, map); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, context, map, map, null); + + // then + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"), + entry(SemanticAttributes.NET_PEER_PORT, 42L)); + + assertThat(endAttributes.build()) + .containsOnly( + entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), + entry(NetworkAttributes.NETWORK_TYPE, "ipv6"), + entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), + entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"), + entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L)); + } +} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java new file mode 100644 index 0000000000..b2e3f8b435 --- /dev/null +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java @@ -0,0 +1,147 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.net; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; +import static org.assertj.core.api.Assertions.entry; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; +import org.junit.jupiter.api.Test; + +class NetServerAttributesExtractorStableSemconvTest { + + static class TestNetServerAttributesGetter + implements NetServerAttributesGetter, Void> { + + @Override + public String getTransport(Map request) { + return request.get("netTransport"); + } + + @Nullable + @Override + public String getNetworkTransport(Map request, @Nullable Void response) { + return request.get("transport"); + } + + @Nullable + @Override + public String getNetworkType(Map request, @Nullable Void response) { + return request.get("type"); + } + + @Nullable + @Override + public String getNetworkProtocolName(Map request, Void response) { + return request.get("protocolName"); + } + + @Nullable + @Override + public String getNetworkProtocolVersion(Map request, Void response) { + return request.get("protocolVersion"); + } + + @Nullable + @Override + public String getHostName(Map request) { + return request.get("hostName"); + } + + @Nullable + @Override + public Integer getHostPort(Map request) { + String hostPort = request.get("hostPort"); + return hostPort == null ? null : Integer.valueOf(hostPort); + } + + @Nullable + @Override + public String getSockFamily(Map request) { + return request.get("sockFamily"); + } + + @Override + public String getSockPeerAddr(Map request) { + return request.get("sockPeerAddr"); + } + + @Override + public Integer getSockPeerPort(Map request) { + String sockPeerPort = request.get("sockPeerPort"); + return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort); + } + + @Nullable + @Override + public String getSockHostAddr(Map request) { + return request.get("sockHostAddr"); + } + + @Nullable + @Override + public Integer getSockHostPort(Map request) { + String sockHostPort = request.get("sockHostPort"); + return sockHostPort == null ? null : Integer.valueOf(sockHostPort); + } + } + + AttributesExtractor, Void> extractor = + NetServerAttributesExtractor.create(new TestNetServerAttributesGetter()); + + @Test + void normal() { + // given + Map map = new HashMap<>(); + map.put("netTransport", IP_TCP); + map.put("transport", "tcp"); + map.put("type", "ipv6"); + map.put("protocolName", "http"); + map.put("protocolVersion", "1.1"); + map.put("hostName", "opentelemetry.io"); + map.put("hostPort", "80"); + map.put("sockFamily", "inet6"); + map.put("sockPeerAddr", "1:2:3:4::"); + map.put("sockPeerPort", "42"); + map.put("sockHostAddr", "4:3:2:1::"); + map.put("sockHostPort", "8080"); + + Context context = Context.root(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, context, map); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, context, map, null, null); + + // then + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"), + entry(SemanticAttributes.NET_HOST_PORT, 80L), + entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), + entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L), + entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"), + entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L)); + + assertThat(endAttributes.build()) + .containsOnly( + entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), + entry(NetworkAttributes.NETWORK_TYPE, "ipv6"), + entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); + } +} 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 f228ea7a73..89d7e9c865 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 @@ -95,13 +95,13 @@ public class InstrumenterBenchmark { @Nullable @Override - public String getProtocolName(Void unused, @Nullable Void unused2) { + public String getNetworkProtocolName(Void unused, @Nullable Void unused2) { return "http"; } @Nullable @Override - public String getProtocolVersion(Void unused, @Nullable Void unused2) { + public String getNetworkProtocolVersion(Void unused, @Nullable Void unused2) { return "2.0"; } diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpNetAttributesGetter.java b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpNetAttributesGetter.java index 5bbf5c5943..079b0f7336 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpNetAttributesGetter.java +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/client/AkkaHttpNetAttributesGetter.java @@ -15,13 +15,15 @@ class AkkaHttpNetAttributesGetter implements NetClientAttributesGetter { +class AkkaNetServerAttributesGetter + implements NetServerAttributesGetter { @Nullable @Override - public String getProtocolName(HttpRequest request) { + public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse httpResponse) { return AkkaHttpUtil.protocolName(request); } @Nullable @Override - public String getProtocolVersion(HttpRequest request) { + public String getNetworkProtocolVersion( + HttpRequest request, @Nullable HttpResponse httpResponse) { return AkkaHttpUtil.protocolVersion(request); } @Nullable @Override public String getHostName(HttpRequest request) { - return null; + Uri.Host host = request.uri().authority().host(); + return host.isEmpty() ? null : host.address(); } - @Nullable @Override public Integer getHostPort(HttpRequest request) { - return null; + return request.uri().authority().port(); } } diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesGetter.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesGetter.java index 23a14a1d0f..79247ef555 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesGetter.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesGetter.java @@ -9,13 +9,14 @@ import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import java.net.InetSocketAddress; import javax.annotation.Nullable; +import org.apache.dubbo.rpc.Result; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ public final class DubboNetServerAttributesGetter - implements NetServerAttributesGetter { + implements NetServerAttributesGetter { @Nullable @Override diff --git a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesGetter.java b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesGetter.java index 4ddfa61c5f..639f4c75de 100644 --- a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesGetter.java +++ b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesGetter.java @@ -14,12 +14,13 @@ final class ApacheHttpAsyncClientNetAttributesGetter implements NetClientAttributesGetter { @Override - public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) { + public String getNetworkProtocolName( + ApacheHttpClientRequest request, @Nullable HttpResponse response) { return request.getProtocolName(); } @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( ApacheHttpClientRequest request, @Nullable HttpResponse response) { return request.getProtocolVersion(); } diff --git a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesGetter.java b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesGetter.java index c84a58a85a..e20dc604fe 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesGetter.java +++ b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesGetter.java @@ -15,13 +15,13 @@ final class ApacheHttpClientNetAttributesGetter implements NetClientAttributesGetter { @Override - public String getProtocolName(HttpMethod request, @Nullable HttpMethod response) { + public String getNetworkProtocolName(HttpMethod request, @Nullable HttpMethod response) { return "http"; } @Nullable @Override - public String getProtocolVersion(HttpMethod request, @Nullable HttpMethod response) { + public String getNetworkProtocolVersion(HttpMethod request, @Nullable HttpMethod response) { if (request instanceof HttpMethodBase) { return ((HttpMethodBase) request).isHttp11() ? "1.1" : "1.0"; } diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesGetter.java b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesGetter.java index 77fb7adf03..7a04aab2ef 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesGetter.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesGetter.java @@ -13,12 +13,13 @@ final class ApacheHttpClientNetAttributesGetter implements NetClientAttributesGetter { @Override - public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) { + public String getNetworkProtocolName( + ApacheHttpClientRequest request, @Nullable HttpResponse response) { return request.getProtocolName(); } @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( ApacheHttpClientRequest request, @Nullable HttpResponse response) { return request.getProtocolVersion(); } diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesGetter.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesGetter.java index 04d66a5bb4..19f66bf3fd 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesGetter.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesGetter.java @@ -14,12 +14,13 @@ final class ApacheHttpClientNetAttributesGetter implements NetClientAttributesGetter { @Override - public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) { + public String getNetworkProtocolName( + ApacheHttpClientRequest request, @Nullable HttpResponse response) { return request.getProtocolName(); } @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( ApacheHttpClientRequest request, @Nullable HttpResponse response) { return request.getProtocolVersion(); } diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesGetter.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesGetter.java index 5977024bea..ce49bc7f00 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesGetter.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesGetter.java @@ -16,7 +16,7 @@ final class ApacheHttpClientNetAttributesGetter @Nullable @Override - public String getProtocolName(HttpRequest request, @Nullable HttpResponse response) { + public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse response) { ProtocolVersion protocolVersion = getVersion(request, response); if (protocolVersion == null) { return null; @@ -26,7 +26,7 @@ final class ApacheHttpClientNetAttributesGetter @Nullable @Override - public String getProtocolVersion(HttpRequest request, @Nullable HttpResponse response) { + public String getNetworkProtocolVersion(HttpRequest request, @Nullable HttpResponse response) { ProtocolVersion protocolVersion = getVersion(request, response); if (protocolVersion == null) { return null; diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java index 90784771d3..4ee334cc69 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetServerAttributesGetter.java @@ -7,20 +7,22 @@ package io.opentelemetry.instrumentation.armeria.v1_3; import com.linecorp.armeria.common.RequestContext; import com.linecorp.armeria.common.SessionProtocol; +import com.linecorp.armeria.common.logging.RequestLog; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; -final class ArmeriaNetServerAttributesGetter implements NetServerAttributesGetter { +final class ArmeriaNetServerAttributesGetter + implements NetServerAttributesGetter { @Override - public String getProtocolName(RequestContext ctx) { + public String getNetworkProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) { return "http"; } @Override - public String getProtocolVersion(RequestContext ctx) { + public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) { SessionProtocol protocol = ctx.sessionProtocol(); return protocol.isMultiplex() ? "2.0" : "1.1"; } diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesGetter.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesGetter.java index 2e86e6ecc1..1f3c19310b 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesGetter.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesGetter.java @@ -22,12 +22,12 @@ public final class ArmeriaNetClientAttributesGetter implements NetClientAttributesGetter { @Override - public String getProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) { + public String getNetworkProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) { return "http"; } @Override - public String getProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) { + public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) { SessionProtocol protocol = ctx.sessionProtocol(); return protocol.isMultiplex() ? "2.0" : "1.1"; } diff --git a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesGetter.java b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesGetter.java index 2d9caaedf2..05ec885f4c 100644 --- a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesGetter.java +++ b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesGetter.java @@ -15,13 +15,13 @@ final class AsyncHttpClientNetAttributesGetter @Nullable @Override - public String getProtocolName(Request request, @Nullable Response response) { + public String getNetworkProtocolName(Request request, @Nullable Response response) { return null; } @Nullable @Override - public String getProtocolVersion(Request request, @Nullable Response response) { + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { return null; } diff --git a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesGetter.java b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesGetter.java index d6fc4638da..1553478b14 100644 --- a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesGetter.java +++ b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesGetter.java @@ -18,7 +18,7 @@ final class AsyncHttpClientNetAttributesGetter @Nullable @Override - public String getProtocolName(RequestContext request, @Nullable Response response) { + public String getNetworkProtocolName(RequestContext request, @Nullable Response response) { HttpVersion httpVersion = getHttpVersion(request); if (httpVersion == null) { return null; @@ -28,7 +28,7 @@ final class AsyncHttpClientNetAttributesGetter @Nullable @Override - public String getProtocolVersion(RequestContext request, @Nullable Response response) { + public String getNetworkProtocolVersion(RequestContext request, @Nullable Response response) { HttpVersion httpVersion = getHttpVersion(request); if (httpVersion == null) { return null; diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkNetAttributesGetter.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkNetAttributesGetter.java index d764a3acc6..db5053e0a0 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkNetAttributesGetter.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkNetAttributesGetter.java @@ -17,7 +17,7 @@ class AwsSdkNetAttributesGetter implements NetClientAttributesGetter, @Nullable @Override - public String getProtocolName(Request request, @Nullable Response response) { + public String getNetworkProtocolName(Request request, @Nullable Response response) { ProtocolVersion protocolVersion = getProtocolVersion(response); if (protocolVersion == null) { return null; @@ -27,7 +27,7 @@ class AwsSdkNetAttributesGetter implements NetClientAttributesGetter, @Nullable @Override - public String getProtocolVersion(Request request, @Nullable Response response) { + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { ProtocolVersion protocolVersion = getProtocolVersion(response); if (protocolVersion == null) { return null; diff --git a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java b/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java index 5cd59dc8bc..0adb5e5adf 100644 --- a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java +++ b/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyNetAttributesGetter.java @@ -12,17 +12,20 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes import javax.annotation.Nullable; import org.glassfish.grizzly.Transport; import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.http.HttpResponsePacket; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.UDPNIOTransport; -final class GrizzlyNetAttributesGetter implements NetServerAttributesGetter { +final class GrizzlyNetAttributesGetter + implements NetServerAttributesGetter { @Override public String getTransport(HttpRequestPacket request) { Transport transport = request.getConnection().getTransport(); if (transport instanceof TCPNIOTransport) { return IP_TCP; - } else if (transport instanceof UDPNIOTransport) { + } + if (transport instanceof UDPNIOTransport) { return IP_UDP; } return null; @@ -30,7 +33,21 @@ final class GrizzlyNetAttributesGetter implements NetServerAttributesGetter { +public final class GrpcNetServerAttributesGetter + implements NetServerAttributesGetter { @Nullable @Override diff --git a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesGetter.java b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesGetter.java index 746ffc3c93..ff6c8c5027 100644 --- a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesGetter.java +++ b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesGetter.java @@ -13,14 +13,14 @@ class HttpUrlNetAttributesGetter implements NetClientAttributesGetter response) { + public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse response) { return "http"; } @Nullable @Override - public String getProtocolVersion(HttpRequest request, @Nullable HttpResponse response) { + public String getNetworkProtocolVersion(HttpRequest request, @Nullable HttpResponse response) { HttpClient.Version version; if (response != null) { version = response.version(); diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesGetter.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesGetter.java index b792a7c606..a0dc832358 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesGetter.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesGetter.java @@ -20,13 +20,13 @@ public class JettyHttpClientNetAttributesGetter @Nullable @Override - public String getProtocolName(Request request, @Nullable Response response) { + public String getNetworkProtocolName(Request request, @Nullable Response response) { return "http"; } @Nullable @Override - public String getProtocolVersion(Request request, @Nullable Response response) { + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { HttpVersion httpVersion = null; if (response != null) { httpVersion = response.getVersion(); diff --git a/instrumentation/jodd-http-4.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/joddhttp/v4_2/JoddHttpNetAttributesGetter.java b/instrumentation/jodd-http-4.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/joddhttp/v4_2/JoddHttpNetAttributesGetter.java index 9f7b7536d1..9bdf68513d 100644 --- a/instrumentation/jodd-http-4.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/joddhttp/v4_2/JoddHttpNetAttributesGetter.java +++ b/instrumentation/jodd-http-4.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/joddhttp/v4_2/JoddHttpNetAttributesGetter.java @@ -14,13 +14,13 @@ final class JoddHttpNetAttributesGetter implements NetClientAttributesGetter { @Override - public String getProtocolName(HttpRequest request, @Nullable HttpResponse response) { + public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse response) { return "http"; } @Nullable @Override - public String getProtocolVersion(HttpRequest request, @Nullable HttpResponse response) { + public String getNetworkProtocolVersion(HttpRequest request, @Nullable HttpResponse response) { String httpVersion = request.httpVersion(); if (httpVersion == null && response != null) { httpVersion = response.httpVersion(); diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt index 7f35085363..1735d93cf7 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorNetServerAttributesGetter.kt @@ -6,15 +6,16 @@ package io.opentelemetry.instrumentation.ktor.v1_0 import io.ktor.request.* +import io.ktor.response.* import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter import io.opentelemetry.instrumentation.ktor.isIpAddress -internal class KtorNetServerAttributesGetter : NetServerAttributesGetter { +internal class KtorNetServerAttributesGetter : NetServerAttributesGetter { - override fun getProtocolName(request: ApplicationRequest): String? = + override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) "http" else null - override fun getProtocolVersion(request: ApplicationRequest): String? = + override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null override fun getSockPeerAddr(request: ApplicationRequest): String? { diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorNetClientAttributesGetter.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorNetClientAttributesGetter.kt index 716abcae76..694dfc7563 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorNetClientAttributesGetter.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorNetClientAttributesGetter.kt @@ -11,10 +11,10 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributes internal object KtorNetClientAttributesGetter : NetClientAttributesGetter { - override fun getProtocolName(request: HttpRequestData?, response: HttpResponse?): String? = + override fun getNetworkProtocolName(request: HttpRequestData?, response: HttpResponse?): String? = response?.version?.name - override fun getProtocolVersion(request: HttpRequestData?, response: HttpResponse?): String? { + override fun getNetworkProtocolVersion(request: HttpRequestData?, response: HttpResponse?): String? { val version = response?.version ?: return null return "${version.major}.${version.minor}" } diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorNetServerAttributesGetter.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorNetServerAttributesGetter.kt index 2530ba867d..c95ec653df 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorNetServerAttributesGetter.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorNetServerAttributesGetter.kt @@ -6,15 +6,16 @@ package io.opentelemetry.instrumentation.ktor.v2_0.server import io.ktor.server.request.* +import io.ktor.server.response.* import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter import io.opentelemetry.instrumentation.ktor.isIpAddress -internal class KtorNetServerAttributesGetter : NetServerAttributesGetter { +internal class KtorNetServerAttributesGetter : NetServerAttributesGetter { - override fun getProtocolName(request: ApplicationRequest): String? = + override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) "http" else null - override fun getProtocolVersion(request: ApplicationRequest): String? = + override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null override fun getHostName(request: ApplicationRequest): String { diff --git a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java index 1968ffdb24..8e8f9cf1ef 100644 --- a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java +++ b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesGetter.java @@ -9,11 +9,12 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes import javax.annotation.Nullable; public class LibertyDispatcherNetAttributesGetter - implements NetServerAttributesGetter { + implements NetServerAttributesGetter { @Nullable @Override - public String getProtocolName(LibertyRequest request) { + public String getNetworkProtocolName( + LibertyRequest request, @Nullable LibertyResponse libertyResponse) { String protocol = request.getProtocol(); if (protocol != null && protocol.startsWith("HTTP/")) { return "http"; @@ -23,7 +24,8 @@ public class LibertyDispatcherNetAttributesGetter @Nullable @Override - public String getProtocolVersion(LibertyRequest request) { + public String getNetworkProtocolVersion( + LibertyRequest request, @Nullable LibertyResponse libertyResponse) { String protocol = request.getProtocol(); if (protocol != null && protocol.startsWith("HTTP/")) { return protocol.substring("HTTP/".length()); diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectNetAttributesGetter.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectNetAttributesGetter.java index a06df542fc..4005739086 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectNetAttributesGetter.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyConnectNetAttributesGetter.java @@ -10,6 +10,7 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest; +import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.ChannelUtil; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; @@ -24,6 +25,11 @@ final class NettyConnectNetAttributesGetter return channel instanceof DatagramChannel ? IP_UDP : IP_TCP; } + @Override + public String getNetworkTransport(NettyConnectionRequest request, @Nullable Channel channel) { + return ChannelUtil.getNetworkTransport(channel); + } + @Nullable @Override public String getPeerName(NettyConnectionRequest request) { diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyNetClientAttributesGetter.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyNetClientAttributesGetter.java index 866b538e73..db6a050f83 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyNetClientAttributesGetter.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyNetClientAttributesGetter.java @@ -10,6 +10,7 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel; +import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.ChannelUtil; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; @@ -27,13 +28,19 @@ final class NettyNetClientAttributesGetter } @Override - public String getProtocolName( + public String getNetworkTransport( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + return ChannelUtil.getNetworkTransport(requestAndChannel.channel()); + } + + @Override + public String getNetworkProtocolName( HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) { return requestAndChannel.request().getProtocolVersion().getProtocolName(); } @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) { HttpVersion version = requestAndChannel.request().getProtocolVersion(); return version.getMajorVersion() + "." + version.getMinorVersion(); diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java index e049a691da..d2a57ec4d4 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyNetServerAttributesGetter.java @@ -10,14 +10,16 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel; +import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.ChannelUtil; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; import org.jboss.netty.channel.socket.DatagramChannel; +import org.jboss.netty.handler.codec.http.HttpResponse; import org.jboss.netty.handler.codec.http.HttpVersion; final class NettyNetServerAttributesGetter - implements NetServerAttributesGetter { + implements NetServerAttributesGetter { @Override public String getTransport(HttpRequestAndChannel requestAndChannel) { @@ -25,12 +27,20 @@ final class NettyNetServerAttributesGetter } @Override - public String getProtocolName(HttpRequestAndChannel requestAndChannel) { + public String getNetworkTransport( + HttpRequestAndChannel requestAndChannel, HttpResponse response) { + return ChannelUtil.getNetworkTransport(requestAndChannel.channel()); + } + + @Override + public String getNetworkProtocolName( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { return requestAndChannel.request().getProtocolVersion().getProtocolName(); } @Override - public String getProtocolVersion(HttpRequestAndChannel requestAndChannel) { + public String getNetworkProtocolVersion( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { HttpVersion version = requestAndChannel.request().getProtocolVersion(); return version.getMajorVersion() + "." + version.getMinorVersion(); } diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/util/ChannelUtil.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/util/ChannelUtil.java new file mode 100644 index 0000000000..3d9022568b --- /dev/null +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/util/ChannelUtil.java @@ -0,0 +1,22 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.netty.v3_8.util; + +import javax.annotation.Nullable; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.socket.DatagramChannel; + +public final class ChannelUtil { + + public static String getNetworkTransport(@Nullable Channel channel) { + if (channel == null) { + return null; + } + return channel instanceof DatagramChannel ? "udp" : "tcp"; + } + + private ChannelUtil() {} +} diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/ChannelUtil.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/ChannelUtil.java new file mode 100644 index 0000000000..3b92b647c5 --- /dev/null +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/ChannelUtil.java @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.netty.v4.common.internal; + +import io.netty.channel.Channel; +import io.netty.channel.socket.DatagramChannel; +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 ChannelUtil { + + public static String getNetworkTransport(@Nullable Channel channel) { + if (channel == null) { + return null; + } + return channel instanceof DatagramChannel ? "udp" : "tcp"; + } + + private ChannelUtil() {} +} diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyConnectNetAttributesGetter.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyConnectNetAttributesGetter.java index f20a453715..c32f4af5dd 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyConnectNetAttributesGetter.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyConnectNetAttributesGetter.java @@ -12,6 +12,7 @@ import io.netty.channel.Channel; import io.netty.channel.socket.DatagramChannel; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest; +import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; @@ -24,6 +25,11 @@ final class NettyConnectNetAttributesGetter return channel instanceof DatagramChannel ? IP_UDP : IP_TCP; } + @Override + public String getNetworkTransport(NettyConnectionRequest request, @Nullable Channel channel) { + return ChannelUtil.getNetworkTransport(channel); + } + @Nullable @Override public String getPeerName(NettyConnectionRequest request) { diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyNetClientAttributesGetter.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyNetClientAttributesGetter.java index 34a47cb5a6..7ba2d2a3f3 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyNetClientAttributesGetter.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyNetClientAttributesGetter.java @@ -13,6 +13,7 @@ import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpVersion; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; +import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; @@ -27,13 +28,19 @@ final class NettyNetClientAttributesGetter } @Override - public String getProtocolName( + public String getNetworkTransport( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { + return ChannelUtil.getNetworkTransport(requestAndChannel.channel()); + } + + @Override + public String getNetworkProtocolName( HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { return requestAndChannel.request().getProtocolVersion().protocolName(); } @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { HttpVersion version = requestAndChannel.request().getProtocolVersion(); return version.majorVersion() + "." + version.minorVersion(); diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettySslNetAttributesGetter.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettySslNetAttributesGetter.java index 692983c94d..410dcf851c 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettySslNetAttributesGetter.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettySslNetAttributesGetter.java @@ -10,6 +10,7 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr import io.netty.channel.socket.DatagramChannel; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; +import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil; import java.net.InetSocketAddress; import javax.annotation.Nullable; @@ -21,6 +22,11 @@ final class NettySslNetAttributesGetter return request.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP; } + @Override + public String getNetworkTransport(NettySslRequest request, @Nullable Void unused) { + return ChannelUtil.getNetworkTransport(request.channel()); + } + @Nullable @Override public String getPeerName(NettySslRequest nettySslRequest) { diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyNetServerAttributesGetter.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyNetServerAttributesGetter.java index 15dd0f08d3..efc47b4059 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyNetServerAttributesGetter.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyNetServerAttributesGetter.java @@ -9,15 +9,17 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP; import io.netty.channel.socket.DatagramChannel; +import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpVersion; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; +import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; final class NettyNetServerAttributesGetter - implements NetServerAttributesGetter { + implements NetServerAttributesGetter { @Override public String getTransport(HttpRequestAndChannel requestAndChannel) { @@ -25,12 +27,20 @@ final class NettyNetServerAttributesGetter } @Override - public String getProtocolName(HttpRequestAndChannel requestAndChannel) { + public String getNetworkTransport( + HttpRequestAndChannel requestAndChannel, HttpResponse response) { + return ChannelUtil.getNetworkTransport(requestAndChannel.channel()); + } + + @Override + public String getNetworkProtocolName( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { return requestAndChannel.request().getProtocolVersion().protocolName(); } @Override - public String getProtocolVersion(HttpRequestAndChannel requestAndChannel) { + public String getNetworkProtocolVersion( + HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) { HttpVersion version = requestAndChannel.request().getProtocolVersion(); return version.majorVersion() + "." + version.minorVersion(); } diff --git a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesGetter.java b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesGetter.java index 7fe7c6b8df..f9254cc32d 100644 --- a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesGetter.java +++ b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesGetter.java @@ -15,7 +15,7 @@ public final class OkHttp2NetAttributesGetter @Nullable @Override - public String getProtocolName(Request request, @Nullable Response response) { + public String getNetworkProtocolName(Request request, @Nullable Response response) { if (response == null) { return null; } @@ -32,7 +32,7 @@ public final class OkHttp2NetAttributesGetter @Nullable @Override - public String getProtocolVersion(Request request, @Nullable Response response) { + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { if (response == null) { return null; } diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesGetter.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesGetter.java index 04f8aa2d7c..618af25303 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesGetter.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesGetter.java @@ -19,7 +19,7 @@ public enum OkHttpNetAttributesGetter implements NetClientAttributesGetter { +enum MockNetServerAttributesGetter implements NetServerAttributesGetter { INSTANCE; @Nullable diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/RatpackNetServerAttributesGetter.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/RatpackNetServerAttributesGetter.java index cb371cc9a3..67967d55e4 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/RatpackNetServerAttributesGetter.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/RatpackNetServerAttributesGetter.java @@ -9,17 +9,19 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes import javax.annotation.Nullable; import ratpack.handling.Context; import ratpack.http.Request; +import ratpack.http.Response; import ratpack.server.PublicAddress; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class RatpackNetServerAttributesGetter implements NetServerAttributesGetter { +public final class RatpackNetServerAttributesGetter + implements NetServerAttributesGetter { @Nullable @Override - public String getProtocolName(Request request) { + public String getNetworkProtocolName(Request request, @Nullable Response response) { String protocol = request.getProtocol(); if (protocol.startsWith("HTTP/")) { return "http"; @@ -29,7 +31,7 @@ public final class RatpackNetServerAttributesGetter implements NetServerAttribut @Nullable @Override - public String getProtocolVersion(Request request) { + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { String protocol = request.getProtocol(); if (protocol.startsWith("HTTP/")) { return protocol.substring("HTTP/".length()); diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyNetClientAttributesGetter.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyNetClientAttributesGetter.java index 9eda3be62e..567fa5e66c 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyNetClientAttributesGetter.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyNetClientAttributesGetter.java @@ -19,7 +19,8 @@ final class ReactorNettyNetClientAttributesGetter @Nullable @Override - public String getProtocolName(HttpClientConfig request, @Nullable HttpClientResponse response) { + public String getNetworkProtocolName( + HttpClientConfig request, @Nullable HttpClientResponse response) { if (response == null) { return null; } @@ -28,7 +29,7 @@ final class ReactorNettyNetClientAttributesGetter @Nullable @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( HttpClientConfig request, @Nullable HttpClientResponse response) { if (response == null) { return null; diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletNetAttributesGetter.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletNetAttributesGetter.java index a38e10eb60..5145231566 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletNetAttributesGetter.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletNetAttributesGetter.java @@ -10,12 +10,13 @@ import com.noelios.restlet.http.HttpRequest; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import javax.annotation.Nullable; import org.restlet.data.Request; +import org.restlet.data.Response; -final class RestletNetAttributesGetter implements NetServerAttributesGetter { +final class RestletNetAttributesGetter implements NetServerAttributesGetter { @Nullable @Override - public String getProtocolName(Request request) { + public String getNetworkProtocolName(Request request, @Nullable Response response) { String protocol = getProtocolString(request); if (protocol.startsWith("HTTP/")) { return "http"; @@ -25,7 +26,7 @@ final class RestletNetAttributesGetter implements NetServerAttributesGetter { +public final class RestletNetAttributesGetter + implements NetServerAttributesGetter { private static final Class HTTP_REQUEST_CLASS; private static final MethodHandle GET_HTTP_CALL; @@ -79,13 +81,13 @@ public final class RestletNetAttributesGetter implements NetServerAttributesGett @Nullable @Override - public String getProtocolName(Request request) { + public String getNetworkProtocolName(Request request, @Nullable Response response) { return request.getProtocol().getSchemeName(); } @Nullable @Override - public String getProtocolVersion(Request request) { + public String getNetworkProtocolVersion(Request request, @Nullable Response response) { return request.getProtocol().getVersion(); } diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesGetter.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesGetter.java index 25149841bd..bc004fb24d 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesGetter.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesGetter.java @@ -9,7 +9,8 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes import javax.annotation.Nullable; public class ServletNetAttributesGetter - implements NetServerAttributesGetter> { + implements NetServerAttributesGetter< + ServletRequestContext, ServletResponseContext> { private final ServletAccessor accessor; @@ -19,7 +20,9 @@ public class ServletNetAttributesGetter @Nullable @Override - public String getProtocolName(ServletRequestContext requestContext) { + public String getNetworkProtocolName( + ServletRequestContext requestContext, + @Nullable ServletResponseContext responseContext) { String protocol = accessor.getRequestProtocol(requestContext.request()); if (protocol != null && protocol.startsWith("HTTP/")) { return "http"; @@ -29,7 +32,9 @@ public class ServletNetAttributesGetter @Nullable @Override - public String getProtocolVersion(ServletRequestContext requestContext) { + public String getNetworkProtocolVersion( + ServletRequestContext requestContext, + @Nullable ServletResponseContext responseContext) { String protocol = accessor.getRequestProtocol(requestContext.request()); if (protocol != null && protocol.startsWith("HTTP/")) { return protocol.substring("HTTP/".length()); diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerNetAttributesGetter.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerNetAttributesGetter.java index f00099e5ed..e8309f56b0 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerNetAttributesGetter.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerNetAttributesGetter.java @@ -11,7 +11,7 @@ import javax.annotation.Nullable; import org.springframework.web.server.ServerWebExchange; final class WebfluxServerNetAttributesGetter - implements NetServerAttributesGetter { + implements NetServerAttributesGetter { @Nullable @Override diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java index 4a4af584a1..e3072b997f 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcNetAttributesGetter.java @@ -8,13 +8,16 @@ package io.opentelemetry.instrumentation.spring.webmvc.v5_3; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import javax.annotation.Nullable; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; -enum SpringWebMvcNetAttributesGetter implements NetServerAttributesGetter { +enum SpringWebMvcNetAttributesGetter + implements NetServerAttributesGetter { INSTANCE; @Nullable @Override - public String getProtocolName(HttpServletRequest request) { + public String getNetworkProtocolName( + HttpServletRequest request, @Nullable HttpServletResponse response) { String protocol = request.getProtocol(); if (protocol != null && protocol.startsWith("HTTP/")) { return "http"; @@ -24,7 +27,8 @@ enum SpringWebMvcNetAttributesGetter implements NetServerAttributesGetter { +enum SpringWebMvcNetAttributesGetter + implements NetServerAttributesGetter { INSTANCE; @Nullable @Override - public String getProtocolName(HttpServletRequest request) { + public String getNetworkProtocolName( + HttpServletRequest request, @Nullable HttpServletResponse response) { String protocol = request.getProtocol(); if (protocol != null && protocol.startsWith("HTTP/")) { return "http"; @@ -24,7 +27,8 @@ enum SpringWebMvcNetAttributesGetter implements NetServerAttributesGetter { +public class TomcatNetAttributesGetter implements NetServerAttributesGetter { @Nullable @Override - public String getProtocolName(Request request) { + public String getNetworkProtocolName(Request request, @Nullable Response response) { String protocol = messageBytesToString(request.protocol()); if (protocol != null && protocol.startsWith("HTTP/")) { return "http"; @@ -26,7 +27,7 @@ public class TomcatNetAttributesGetter implements NetServerAttributesGetter { +public class UndertowNetAttributesGetter + implements NetServerAttributesGetter { @Nullable @Override - public String getProtocolName(HttpServerExchange exchange) { + public String getNetworkProtocolName( + HttpServerExchange exchange, @Nullable HttpServerExchange unused) { String protocol = exchange.getProtocol().toString(); if (protocol.startsWith("HTTP/")) { return "http"; @@ -24,7 +26,8 @@ public class UndertowNetAttributesGetter implements NetServerAttributesGetter { @Override - public String getProtocolName(HttpClientRequest request, @Nullable HttpClientResponse response) { + public String getNetworkProtocolName( + HttpClientRequest request, @Nullable HttpClientResponse response) { return "http"; } @Nullable @Override - public String getProtocolVersion( + public String getNetworkProtocolVersion( HttpClientRequest request, @Nullable HttpClientResponse response) { HttpVersion version = request.version(); if (version == null) { diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java index f1e5cc5910..5d19021950 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java @@ -182,7 +182,7 @@ final class TestInstrumenters { } } - private enum NetServerGetter implements NetServerAttributesGetter { + private enum NetServerGetter implements NetServerAttributesGetter { INSTANCE; @Nullable