Remove deprecated code after release (#8738)

Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
This commit is contained in:
Mateusz Rzeszutek 2023-06-16 16:09:53 +02:00 committed by GitHub
parent ca24c38846
commit 2b58df1627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 36 additions and 669 deletions

View File

@ -17,19 +17,6 @@ import javax.annotation.Nullable;
public interface HttpClientAttributesGetter<REQUEST, RESPONSE>
extends HttpCommonAttributesGetter<REQUEST, RESPONSE> {
/**
* 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 <a
* href="https://www.rfc-editor.org/rfc/rfc3986">RFC3986</a>.
@ -37,7 +24,5 @@ public interface HttpClientAttributesGetter<REQUEST, RESPONSE>
* <p>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);
}

View File

@ -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<REQUEST, RESPONSE> {
/**
* Returns the HTTP request method.
*
* <p>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.
*
* <p>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.
*
* <p>Implementations of this method <b>must not</b> 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<String> 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<REQUEST, RESPONSE> {
* <p>Implementations of this method <b>must not</b> return a null value; an empty list should be
* returned instead.
*/
default List<String> getHttpRequestHeader(REQUEST request, String name) {
return getRequestHeader(request, name);
}
List<String> getHttpRequestHeader(REQUEST request, String name);
/**
* Extracts the {@code http.status_code} span attribute.
*
* <p>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 <a href="https://tools.ietf.org/html/rfc7231#section-6">HTTP response status
* code</a>.
@ -93,30 +40,8 @@ public interface HttpCommonAttributesGetter<REQUEST, RESPONSE> {
* {@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.
*
* <p>This is called from {@link Instrumenter#end(Context, Object, Object, Throwable)}, only when
* {@code response} is non-{@code null}.
*
* <p>Implementations of this method <b>must not</b> 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<String> 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<REQUEST, RESPONSE> {
* <p>Implementations of this method <b>must not</b> return a null value; an empty list should be
* returned instead.
*/
default List<String> getHttpResponseHeader(REQUEST request, RESPONSE response, String name) {
return getResponseHeader(request, response, name);
}
List<String> getHttpResponseHeader(REQUEST request, RESPONSE response, String name);
}

View File

@ -18,78 +18,20 @@ import javax.annotation.Nullable;
public interface HttpServerAttributesGetter<REQUEST, RESPONSE>
extends HttpCommonAttributesGetter<REQUEST, RESPONSE>, UrlAttributesGetter<REQUEST> {
/**
* 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).
*
* <p>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<REQUEST, RESPONSE>
*/
@Nullable
default String getHttpRoute(REQUEST request) {
return getRoute(request);
return null;
}
}

View File

@ -22,16 +22,6 @@ public interface MessagingAttributesGetter<REQUEST, RESPONSE> {
@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);

View File

@ -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 <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes">Network
* attributes</a> from a {@link InetSocketAddress}.
*
* @deprecated Use {@link NetClientAttributesGetter} and its {@link
* NetClientAttributesGetter#getPeerSocketAddress(Object, Object)} method instead.
*/
@Deprecated
public abstract class InetSocketAddressNetClientAttributesGetter<REQUEST, RESPONSE>
implements NetClientAttributesGetter<REQUEST, RESPONSE> {
@Nullable
@Override
public abstract InetSocketAddress getPeerSocketAddress(
REQUEST request, @Nullable RESPONSE response);
}

View File

@ -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 <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes">Network
* attributes</a> 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<REQUEST, RESPONSE>
implements NetServerAttributesGetter<REQUEST, RESPONSE> {
@Nullable
@Override
public abstract InetSocketAddress getPeerSocketAddress(REQUEST request);
// optional
@Nullable
@Override
public abstract InetSocketAddress getHostSocketAddress(REQUEST request);
}

View File

@ -19,8 +19,7 @@ import javax.annotation.Nullable;
/**
* Extractor of <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes">Network
* attributes</a>. It is common to have access to {@link java.net.InetSocketAddress}, in which case
* it is more convenient to use {@link InetSocketAddressNetClientAttributesGetter}.
* attributes</a>.
*
* <p>This class delegates to a type-specific {@link NetClientAttributesGetter} for individual
* attribute extraction from request/response objects.

View File

@ -27,117 +27,6 @@ public interface NetClientAttributesGetter<REQUEST, RESPONSE>
return null;
}
/**
* Returns the application protocol used.
*
* <p>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.
*
* <p>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.
*
* <p>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 <a
* href="https://man7.org/linux/man-pages/man7/address_families.7.html">address family</a> which
@ -146,95 +35,21 @@ public interface NetClientAttributesGetter<REQUEST, RESPONSE>
* <p>Examples: {@code inet}, {@code inet6}
*
* <p>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.
*
* <p>Examples: {@code 127.0.0.1}, {@code /tmp/mysql.sock}
*
* <p>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.
*
* <p>Examples: {@code proxy.example.com}
*
* <p>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.
*
* <p>Examples: {@code 16456}
*
* <p>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);
}
}

View File

@ -31,31 +31,23 @@ public interface NetServerAttributesGetter<REQUEST, RESPONSE>
}
/**
* Returns the application protocol used.
* Returns the protocol <a
* href="https://man7.org/linux/man-pages/man7/address_families.7.html">address family</a> which
* is used for communication.
*
* <p>Examples: `amqp`, `http`, `mqtt`.
* <p>Examples: `inet`, `inet6`.
*
* @deprecated This method is deprecated and will be removed in the following release. Implement
* {@link #getNetworkProtocolName(Object, Object)} instead.
* <p>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.
*
* <p>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<REQUEST, RESPONSE>
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 <a
* href="https://man7.org/linux/man-pages/man7/address_families.7.html">address family</a> which
* is used for communication.
*
* <p>Examples: `inet`, `inet6`.
*
* <p>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.
*
* <p>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.
*
* <p>Examples: `127.0.0.1`, `/tmp/mysql.sock`.
*
* <p>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.
*
* <p>Examples: `16456`.
*
* <p>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.
*
* <p>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.
*
* <p>Examples: `192.168.0.1`.
*
* <p>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.
*
* <p>Examples: `35555`.
*
* <p>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);
}
}

View File

@ -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<REQUEST, RESPONSE>
implements AttributesExtractor<REQUEST, RESPONSE> {
private final NetClientAttributesGetter<REQUEST, RESPONSE> attributesGetter;
private final ServerAttributesGetter<REQUEST, RESPONSE> attributesGetter;
private final Map<String, String> peerServiceMapping;
// visible for tests
PeerServiceAttributesExtractor(
NetClientAttributesGetter<REQUEST, RESPONSE> attributesGetter,
ServerAttributesGetter<REQUEST, RESPONSE> attributesGetter,
Map<String, String> peerServiceMapping) {
this.attributesGetter = attributesGetter;
this.peerServiceMapping = peerServiceMapping;
@ -36,7 +37,7 @@ public final class PeerServiceAttributesExtractor<REQUEST, RESPONSE>
* netAttributesExtractor} instance to determine the value of the {@code peer.service} attribute.
*/
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
NetClientAttributesGetter<REQUEST, RESPONSE> attributesGetter,
ServerAttributesGetter<REQUEST, RESPONSE> attributesGetter,
Map<String, String> peerServiceMapping) {
return new PeerServiceAttributesExtractor<>(attributesGetter, peerServiceMapping);
}

View File

@ -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<String, String> netAttributesExtractor;
@Mock ServerAttributesGetter<String, String> netAttributesExtractor;
@Test
void shouldNotSetAnyValueIfNetExtractorReturnsNulls() {