diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesGetter.java index 2dd30892b3..169a6181ab 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesGetter.java @@ -17,19 +17,6 @@ import javax.annotation.Nullable; public interface HttpClientAttributesGetter extends HttpCommonAttributesGetter { - /** - * Returns the full request URL. - * - * @deprecated This method is deprecated and will be removed in a future release. Implement {@link - * #getUrlFull(Object)} instead. - */ - @Deprecated - @Nullable - default String getUrl(REQUEST request) { - return null; - } - - // TODO: make this required to implement /** * Returns the absolute URL describing a network resource according to RFC3986. @@ -37,7 +24,5 @@ public interface HttpClientAttributesGetter *

Examples: {@code https://www.foo.bar/search?q=OpenTelemetry#SemConv}; {@code //localhost} */ @Nullable - default String getUrlFull(REQUEST request) { - return getUrl(request); - } + String getUrlFull(REQUEST request); } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesGetter.java index 7306554231..320f1cfde5 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesGetter.java @@ -5,8 +5,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import static java.util.Collections.emptyList; - import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import java.util.List; @@ -15,47 +13,14 @@ import javax.annotation.Nullable; /** An interface for getting HTTP attributes common to clients and servers. */ public interface HttpCommonAttributesGetter { - /** - * Returns the HTTP request method. - * - *

Examples: {@code GET}, {@code POST}, {@code HEAD} - * - * @deprecated This method is deprecated and will be removed in a future release. Implement {@link - * #getHttpRequestMethod(Object)} instead. - */ - @Deprecated - @Nullable - default String getMethod(REQUEST request) { - return null; - } - - // TODO: make this required to implement /** * Returns the HTTP request method. * *

Examples: {@code GET}, {@code POST}, {@code HEAD} */ @Nullable - default String getHttpRequestMethod(REQUEST request) { - return getMethod(request); - } + String getHttpRequestMethod(REQUEST request); - /** - * Extracts all values of header named {@code name} from the request, or an empty list if there - * were none. - * - *

Implementations of this method must not return a null value; an empty list should be - * returned instead. - * - * @deprecated This method is deprecated and will be removed in a future release. Implement {@link - * #getHttpRequestHeader(Object, String)} instead. - */ - @Deprecated - default List getRequestHeader(REQUEST request, String name) { - return emptyList(); - } - - // TODO: make this required to implement /** * Returns all values of header named {@code name} from the request, or an empty list if there * were none. @@ -63,26 +28,8 @@ public interface HttpCommonAttributesGetter { *

Implementations of this method must not return a null value; an empty list should be * returned instead. */ - default List getHttpRequestHeader(REQUEST request, String name) { - return getRequestHeader(request, name); - } + List getHttpRequestHeader(REQUEST request, String name); - /** - * Extracts the {@code http.status_code} span attribute. - * - *

This is called from {@link Instrumenter#end(Context, Object, Object, Throwable)}, only when - * {@code response} is non-{@code null}. - * - * @deprecated This method is deprecated and will be removed in a future release. Implement {@link - * #getHttpResponseStatusCode(Object, Object, Throwable)} instead. - */ - @Deprecated - @Nullable - default Integer getStatusCode(REQUEST request, RESPONSE response, @Nullable Throwable error) { - return null; - } - - // TODO: make this required to implement /** * Returns the HTTP response status * code. @@ -93,30 +40,8 @@ public interface HttpCommonAttributesGetter { * {@code response} is non-{@code null}. */ @Nullable - default Integer getHttpResponseStatusCode( - REQUEST request, RESPONSE response, @Nullable Throwable error) { - return getStatusCode(request, response, error); - } + Integer getHttpResponseStatusCode(REQUEST request, RESPONSE response, @Nullable Throwable error); - /** - * Extracts all values of header named {@code name} from the response, or an empty list if there - * were none. - * - *

This is called from {@link Instrumenter#end(Context, Object, Object, Throwable)}, only when - * {@code response} is non-{@code null}. - * - *

Implementations of this method must not return a null value; an empty list should be - * returned instead. - * - * @deprecated This method is deprecated and will be removed in a future release. Implement {@link - * #getHttpResponseHeader(Object, Object, String)} instead. - */ - @Deprecated - default List getResponseHeader(REQUEST request, RESPONSE response, String name) { - return emptyList(); - } - - // TODO: make this required to implement /** * Returns all values of header named {@code name} from the response, or an empty list if there * were none. @@ -127,7 +52,5 @@ public interface HttpCommonAttributesGetter { *

Implementations of this method must not return a null value; an empty list should be * returned instead. */ - default List getHttpResponseHeader(REQUEST request, RESPONSE response, String name) { - return getResponseHeader(request, response, name); - } + List getHttpResponseHeader(REQUEST request, RESPONSE response, String name); } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesGetter.java index 041019e69b..b377f5b441 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesGetter.java @@ -18,78 +18,20 @@ import javax.annotation.Nullable; public interface HttpServerAttributesGetter extends HttpCommonAttributesGetter, UrlAttributesGetter { - /** - * Returns the URI scheme. - * - * @deprecated This method is deprecated and will be removed in a future release. Implement {@link - * #getUrlScheme(Object)} instead. - */ - @Deprecated - @Nullable - default String getScheme(REQUEST request) { - return null; - } - - // TODO: make this required to implement /** {@inheritDoc} */ @Nullable @Override - default String getUrlScheme(REQUEST request) { - return getScheme(request); - } + String getUrlScheme(REQUEST request); - /** - * Returns the path and query pieces of the URL, joined by the {@code ?} character. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getUrlPath(Object)} and {@link #getUrlQuery(Object)} instead. - */ - @Deprecated - @Nullable - default String getTarget(REQUEST request) { - return null; - } - - // TODO: make this required to implement /** {@inheritDoc} */ @Nullable @Override - default String getUrlPath(REQUEST request) { - String target = getTarget(request); - if (target == null) { - return null; - } - int separatorPos = target.indexOf('?'); - return separatorPos == -1 ? target : target.substring(0, separatorPos); - } + String getUrlPath(REQUEST request); - // TODO: make this required to implement /** {@inheritDoc} */ @Nullable @Override - default String getUrlQuery(REQUEST request) { - String target = getTarget(request); - if (target == null) { - return null; - } - int separatorPos = target.indexOf('?'); - return separatorPos == -1 ? null : target.substring(separatorPos + 1); - } - - /** - * Returns the matched route (path template in the format used by the respective server - * framework). - * - *

Examples: {@code /users/:userID?}, {@code {controller}/{action}/{id?}} - * - * @deprecated This method is deprecated and will be removed in a future release. Implement {@link - * #getHttpRoute(Object)} instead. - */ - @Deprecated - @Nullable - default String getRoute(REQUEST request) { - return null; - } + String getUrlQuery(REQUEST request); /** * Returns the matched route (path template in the format used by the respective server @@ -99,6 +41,6 @@ public interface HttpServerAttributesGetter */ @Nullable default String getHttpRoute(REQUEST request) { - return getRoute(request); + return null; } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesGetter.java index 71ffc8a3a0..18d1899a08 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesGetter.java @@ -22,16 +22,6 @@ public interface MessagingAttributesGetter { @Nullable String getSystem(REQUEST request); - /** - * @deprecated This method is deprecated and will be removed in a future release. There is no - * replacement for this concept. - */ - @Nullable - @Deprecated - default String getDestinationKind(REQUEST request) { - return null; - } - @Nullable String getDestination(REQUEST request); diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetter.java deleted file mode 100644 index ee6c430959..0000000000 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetter.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.net; - -import java.net.InetSocketAddress; -import javax.annotation.Nullable; - -/** - * Extractor of Network - * attributes from a {@link InetSocketAddress}. - * - * @deprecated Use {@link NetClientAttributesGetter} and its {@link - * NetClientAttributesGetter#getPeerSocketAddress(Object, Object)} method instead. - */ -@Deprecated -public abstract class InetSocketAddressNetClientAttributesGetter - implements NetClientAttributesGetter { - - @Nullable - @Override - public abstract InetSocketAddress getPeerSocketAddress( - REQUEST request, @Nullable RESPONSE response); -} 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 deleted file mode 100644 index 7ce7783df6..0000000000 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetter.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.net; - -import java.net.InetSocketAddress; -import javax.annotation.Nullable; - -/** - * Extractor of Network - * attributes from a {@link InetSocketAddress}. - * - * @deprecated Use {@link NetServerAttributesGetter} and its {@link - * NetServerAttributesGetter#getPeerSocketAddress(Object)} {@link - * NetServerAttributesGetter#getHostSocketAddress(Object)} methods instead. - */ -@Deprecated -public abstract class InetSocketAddressNetServerAttributesGetter - implements NetServerAttributesGetter { - - @Nullable - @Override - public abstract InetSocketAddress getPeerSocketAddress(REQUEST request); - - // optional - @Nullable - @Override - public abstract InetSocketAddress getHostSocketAddress(REQUEST request); -} 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 5fc580f04b..016ca5e24d 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 @@ -19,8 +19,7 @@ import javax.annotation.Nullable; /** * Extractor of Network - * attributes. It is common to have access to {@link java.net.InetSocketAddress}, in which case - * it is more convenient to use {@link InetSocketAddressNetClientAttributesGetter}. + * attributes. * *

This class delegates to a type-specific {@link NetClientAttributesGetter} for individual * attribute extraction from request/response objects. 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 6bb1b5993b..aa3ffbf852 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 @@ -27,117 +27,6 @@ public interface NetClientAttributesGetter return null; } - /** - * 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; - } - - /** - * 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); - } - - /** - * Returns the logical peer name. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerAddress(Object)} instead. - */ - @Deprecated - @Nullable - default String getPeerName(REQUEST request) { - return null; - } - - /** - * Returns the logical peer port. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerPort(Object)} instead. - */ - @Deprecated - @Nullable - default Integer getPeerPort(REQUEST request) { - return null; - } - - /** {@inheritDoc} */ - @Nullable - @Override - default String getServerAddress(REQUEST request) { - return getPeerName(request); - } - - /** {@inheritDoc} */ - @Nullable - @Override - default Integer getServerPort(REQUEST request) { - return getPeerPort(request); - } - - /** - * Returns an {@link InetSocketAddress} object representing the peer socket address. - * - *

Implementing this method is equivalent to implementing all four of {@link - * #getSockFamily(Object, Object)}, {@link #getSockPeerAddr(Object, Object)}, {@link - * #getSockPeerName(Object, Object)} and {@link #getSockPeerPort(Object, Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerInetSocketAddress(Object, Object)} instead. - */ - @Deprecated - @Nullable - default InetSocketAddress getPeerSocketAddress(REQUEST request, @Nullable RESPONSE response) { - return null; - } - - /** {@inheritDoc} */ - @Nullable - @Override - default InetSocketAddress getServerInetSocketAddress( - REQUEST request, @Nullable RESPONSE response) { - return getPeerSocketAddress(request, response); - } - /** * Returns the protocol address family which @@ -146,95 +35,21 @@ public interface NetClientAttributesGetter *

Examples: {@code inet}, {@code inet6} * *

By default, this method attempts to retrieve the address family using the {@link - * #getPeerSocketAddress(Object, Object)} method. If it is not implemented, it will simply return - * {@code null}. If the instrumented library does not expose {@link InetSocketAddress} in its API, - * you might want to implement this method instead of {@link #getPeerSocketAddress(Object, - * Object)}. + * #getServerInetSocketAddress(Object, Object)} method. If it is not implemented, it will simply + * return {@code null}. If the instrumented library does not expose {@link InetSocketAddress} in + * its API, you might want to implement this method instead of {@link + * #getServerSocketAddress(Object, Object)}. */ @Nullable default String getSockFamily(REQUEST request, @Nullable RESPONSE response) { return InetSocketAddressUtil.getSockFamily(getServerInetSocketAddress(request, response), null); } - /** - * Returns the remote socket peer address: IPv4 or IPv6 for internet protocols, path for local - * communication, etc. - * - *

Examples: {@code 127.0.0.1}, {@code /tmp/mysql.sock} - * - *

By default, this method attempts to retrieve the peer address using the {@link - * #getPeerSocketAddress(Object, Object)} method. If this method is not implemented, it will - * simply return {@code null}. If the instrumented library does not expose {@link - * InetSocketAddress} in its API, you might want to implement this method instead of {@link - * #getPeerSocketAddress(Object, Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerSocketAddress(Object, Object)} instead. - */ - @Deprecated - @Nullable - default String getSockPeerAddr(REQUEST request, @Nullable RESPONSE response) { - return InetSocketAddressUtil.getIpAddress(getServerInetSocketAddress(request, response)); - } - - /** - * Returns the domain name of an immediate peer. - * - *

Examples: {@code proxy.example.com} - * - *

By default, this method attempts to retrieve the peer host name using the {@link - * #getPeerSocketAddress(Object, Object)} method. If this method is not implemented, it will - * simply return {@code null}. If the instrumented library does not expose {@link - * InetSocketAddress} in its API, you might want to implement this method instead of {@link - * #getPeerSocketAddress(Object, Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerSocketDomain(Object, Object)} instead. - */ - @Deprecated - @Nullable - default String getSockPeerName(REQUEST request, @Nullable RESPONSE response) { - return InetSocketAddressUtil.getDomainName(getServerInetSocketAddress(request, response)); - } - - /** - * Returns the remote socket peer port. - * - *

Examples: {@code 16456} - * - *

By default, this method attempts to retrieve the peer port using the {@link - * #getPeerSocketAddress(Object, Object)} method. If this method is not implemented, it will - * simply return {@code null}. If the instrumented library does not expose {@link - * InetSocketAddress} in its API, you might want to implement this method instead of {@link - * #getPeerSocketAddress(Object, Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerSocketPort(Object, Object)} instead. - */ - @Deprecated - @Nullable - default Integer getSockPeerPort(REQUEST request, @Nullable RESPONSE response) { - return InetSocketAddressUtil.getPort(getServerInetSocketAddress(request, response)); - } - /** {@inheritDoc} */ @Nullable @Override - default String getServerSocketDomain(REQUEST request, @Nullable RESPONSE response) { - return getSockPeerName(request, response); - } - - /** {@inheritDoc} */ - @Nullable - @Override - default String getServerSocketAddress(REQUEST request, @Nullable RESPONSE response) { - return getSockPeerAddr(request, response); - } - - /** {@inheritDoc} */ - @Nullable - @Override - default Integer getServerSocketPort(REQUEST request, @Nullable RESPONSE response) { - return getSockPeerPort(request, response); + default String getNetworkType(REQUEST request, @Nullable RESPONSE response) { + return InetSocketAddressUtil.getNetworkType( + getServerInetSocketAddress(request, response), null); } } 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 791e98bc3c..fe42893752 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 @@ -31,31 +31,23 @@ public interface NetServerAttributesGetter } /** - * Returns the application protocol used. + * Returns the protocol address family which + * is used for communication. * - *

Examples: `amqp`, `http`, `mqtt`. + *

Examples: `inet`, `inet6`. * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getNetworkProtocolName(Object, Object)} instead. + *

By default, this method attempts to retrieve the address family using one of the {@link + * #getClientInetSocketAddress(Object, Object)} and {@link #getServerInetSocketAddress(Object, + * Object)} methods. If neither of these methods is implemented, it will simply return {@code + * null}. If the instrumented library does not expose {@link InetSocketAddress} in its API, you + * might want to implement this method instead of {@link #getClientInetSocketAddress(Object, + * Object)} and {@link #getServerInetSocketAddress(Object, Object)}. */ - @Deprecated @Nullable - default String getProtocolName(REQUEST request) { - return null; - } - - /** - * 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; + default String getSockFamily(REQUEST request) { + return InetSocketAddressUtil.getSockFamily( + getClientInetSocketAddress(request, null), getServerInetSocketAddress(request, null)); } /** {@inheritDoc} */ @@ -66,226 +58,4 @@ public interface NetServerAttributesGetter getClientInetSocketAddress(request, response), getServerInetSocketAddress(request, response)); } - - /** {@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); - } - - /** - * Returns the logical host name. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerAddress(Object)} instead. - */ - @Deprecated - @Nullable - default String getHostName(REQUEST request) { - return null; - } - - /** - * Returns the logical host port. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerPort(Object)} instead. - */ - @Deprecated - @Nullable - default Integer getHostPort(REQUEST request) { - return null; - } - - /** {@inheritDoc} */ - @Nullable - @Override - default String getServerAddress(REQUEST request) { - return getHostName(request); - } - - /** {@inheritDoc} */ - @Nullable - @Override - default Integer getServerPort(REQUEST request) { - return getHostPort(request); - } - - /** - * Returns the protocol address family which - * is used for communication. - * - *

Examples: `inet`, `inet6`. - * - *

By default, this method attempts to retrieve the address family using one of the {@link - * #getPeerSocketAddress(Object)} and {@link #getHostSocketAddress(Object)} methods. If neither of - * these methods is implemented, it will simply return {@code null}. If the instrumented library - * does not expose {@link InetSocketAddress} in its API, you might want to implement this method - * instead of {@link #getPeerSocketAddress(Object)} and {@link #getHostSocketAddress(Object)}. - */ - @Nullable - default String getSockFamily(REQUEST request) { - return InetSocketAddressUtil.getSockFamily( - getClientInetSocketAddress(request, null), getServerInetSocketAddress(request, null)); - } - - /** - * Returns an {@link InetSocketAddress} object representing the peer socket address. - * - *

Implementing this method is equivalent to implementing all three of {@link - * #getSockFamily(Object)}, {@link #getSockPeerAddr(Object)} and {@link #getSockPeerPort(Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getClientInetSocketAddress(Object, Object)} instead. - */ - @Deprecated - @Nullable - default InetSocketAddress getPeerSocketAddress(REQUEST request) { - return null; - } - - /** {@inheritDoc} */ - @Nullable - @Override - default InetSocketAddress getClientInetSocketAddress( - REQUEST request, @Nullable RESPONSE response) { - return getPeerSocketAddress(request); - } - - /** - * Returns the remote socket peer address: IPv4 or IPv6 for internet protocols, path for local - * communication, etc. - * - *

Examples: `127.0.0.1`, `/tmp/mysql.sock`. - * - *

By default, this method attempts to retrieve the peer address using the {@link - * #getPeerSocketAddress(Object)} method. If this method is not implemented, it will simply return - * {@code null}. If the instrumented library does not expose {@link InetSocketAddress} in its API, - * you might want to implement this method instead of {@link #getPeerSocketAddress(Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getClientSocketAddress(Object, Object)} instead. - */ - @Deprecated - @Nullable - default String getSockPeerAddr(REQUEST request) { - return InetSocketAddressUtil.getIpAddress(getClientInetSocketAddress(request, null)); - } - - /** - * Returns the remote socket peer port. - * - *

Examples: `16456`. - * - *

By default, this method attempts to retrieve the peer port using the {@link - * #getPeerSocketAddress(Object)} method. If this method is not implemented, it will simply return - * {@code null}. If the instrumented library does not expose {@link InetSocketAddress} in its API, - * you might want to implement this method instead of {@link #getPeerSocketAddress(Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getClientSocketPort(Object, Object)} instead. - */ - @Deprecated - @Nullable - default Integer getSockPeerPort(REQUEST request) { - return InetSocketAddressUtil.getPort(getClientInetSocketAddress(request, null)); - } - - /** {@inheritDoc} */ - @Nullable - @Override - default String getClientSocketAddress(REQUEST request, @Nullable RESPONSE response) { - return getSockPeerAddr(request); - } - - /** {@inheritDoc} */ - @Nullable - @Override - default Integer getClientSocketPort(REQUEST request, @Nullable RESPONSE response) { - return getSockPeerPort(request); - } - - /** - * Returns an {@link InetSocketAddress} object representing the host socket address. - * - *

Implementing this method is equivalent to implementing all three of {@link - * #getSockFamily(Object)}, {@link #getSockHostAddr(Object)} and {@link #getSockHostPort(Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerInetSocketAddress(Object, Object)} instead. - */ - @Deprecated - @Nullable - default InetSocketAddress getHostSocketAddress(REQUEST request) { - return null; - } - - /** {@inheritDoc} */ - @Nullable - @Override - default InetSocketAddress getServerInetSocketAddress( - REQUEST request, @Nullable RESPONSE response) { - return getHostSocketAddress(request); - } - - /** - * Returns the local socket address. Useful in case of a multi-IP host. - * - *

Examples: `192.168.0.1`. - * - *

By default, this method attempts to retrieve the host address using the {@link - * #getHostSocketAddress(Object)} method. If this method is not implemented, it will simply return - * {@code null}. If the instrumented library does not expose {@link InetSocketAddress} in its API, - * you might want to implement this method instead of {@link #getHostSocketAddress(Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerSocketAddress(Object, Object)} instead. - */ - @Deprecated - @Nullable - default String getSockHostAddr(REQUEST request) { - return InetSocketAddressUtil.getIpAddress(getServerInetSocketAddress(request, null)); - } - - /** - * Returns the local socket port number. - * - *

Examples: `35555`. - * - *

By default, this method attempts to retrieve the host port using the {@link - * #getHostSocketAddress(Object)} method. If this method is not implemented, it will simply return - * {@code null}. If the instrumented library does not expose {@link InetSocketAddress} in its API, - * you might want to implement this method instead of {@link #getHostSocketAddress(Object)}. - * - * @deprecated This method is deprecated and will be removed in the following release. Implement - * {@link #getServerSocketPort(Object, Object)} instead. - */ - @Deprecated - @Nullable - default Integer getSockHostPort(REQUEST request) { - return InetSocketAddressUtil.getPort(getServerInetSocketAddress(request, null)); - } - - /** {@inheritDoc} */ - @Nullable - @Override - default String getServerSocketAddress(REQUEST request, @Nullable RESPONSE response) { - return getSockHostAddr(request); - } - - /** {@inheritDoc} */ - @Nullable - @Override - default Integer getServerSocketPort(REQUEST request, @Nullable RESPONSE response) { - return getSockHostPort(request); - } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index c6238c116a..8744b5f184 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.net; 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.ServerAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.Map; import javax.annotation.Nullable; @@ -20,12 +21,12 @@ import javax.annotation.Nullable; public final class PeerServiceAttributesExtractor implements AttributesExtractor { - private final NetClientAttributesGetter attributesGetter; + private final ServerAttributesGetter attributesGetter; private final Map peerServiceMapping; // visible for tests PeerServiceAttributesExtractor( - NetClientAttributesGetter attributesGetter, + ServerAttributesGetter attributesGetter, Map peerServiceMapping) { this.attributesGetter = attributesGetter; this.peerServiceMapping = peerServiceMapping; @@ -36,7 +37,7 @@ public final class PeerServiceAttributesExtractor * netAttributesExtractor} instance to determine the value of the {@code peer.service} attribute. */ public static AttributesExtractor create( - NetClientAttributesGetter attributesGetter, + ServerAttributesGetter attributesGetter, Map peerServiceMapping) { return new PeerServiceAttributesExtractor<>(attributesGetter, peerServiceMapping); } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java index 4df7d3c240..9ed76b89b5 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java @@ -17,6 +17,7 @@ import static org.mockito.Mockito.when; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -27,7 +28,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class PeerServiceAttributesExtractorTest { - @Mock NetClientAttributesGetter netAttributesExtractor; + @Mock ServerAttributesGetter netAttributesExtractor; @Test void shouldNotSetAnyValueIfNetExtractorReturnsNulls() {