Skip to content

Commit

Permalink
Deprecate old server/client socket getter methods (#9716)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored Oct 19, 2023
1 parent eb92c5e commit e9026cd
Show file tree
Hide file tree
Showing 50 changed files with 144 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceResolver;
import io.opentelemetry.instrumentation.api.instrumenter.url.UrlParser;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.SemanticAttributes;
import java.util.function.Supplier;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -47,6 +48,7 @@ HttpClientPeerServiceAttributesExtractor<REQUEST, RESPONSE> create(
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {}

@SuppressWarnings("deprecation") // old semconv
@Override
public void onEnd(
AttributesBuilder attributes,
Expand All @@ -64,7 +66,7 @@ public void onEnd(
Integer serverPort = attributesGetter.getServerPort(request);
Supplier<String> pathSupplier = () -> getUrlPath(attributesGetter, request);
String peerService = mapToPeerService(serverAddress, serverPort, pathSupplier);
if (peerService == null) {
if (peerService == null && SemconvStability.emitOldHttpSemconv()) {
String serverSocketDomain = attributesGetter.getServerSocketDomain(request, response);
Integer serverSocketPort = attributesGetter.getServerSocketPort(request, response);
peerService = mapToPeerService(serverSocketDomain, serverSocketPort, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ default String getNetworkType(REQUEST request, @Nullable RESPONSE response) {

@Nullable
@Override
default InetSocketAddress getNetworkPeerInetSocketAddress(
default InetSocketAddress getServerInetSocketAddress(
REQUEST request, @Nullable RESPONSE response) {
return getServerInetSocketAddress(request, response);
return getNetworkPeerInetSocketAddress(request, response);
}

@Nullable
@Override
default String getNetworkPeerAddress(REQUEST request, @Nullable RESPONSE response) {
return getServerSocketAddress(request, response);
default String getServerSocketAddress(REQUEST request, @Nullable RESPONSE response) {
return getNetworkPeerAddress(request, response);
}

@Nullable
@Override
default Integer getNetworkPeerPort(REQUEST request, @Nullable RESPONSE response) {
return getServerSocketPort(request, response);
default Integer getServerSocketPort(REQUEST request, @Nullable RESPONSE response) {
return getNetworkPeerPort(request, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,39 @@ default String getNetworkType(REQUEST request, @Nullable RESPONSE response) {

@Nullable
@Override
default InetSocketAddress getNetworkLocalInetSocketAddress(
default InetSocketAddress getServerInetSocketAddress(
REQUEST request, @Nullable RESPONSE response) {
return getServerInetSocketAddress(request, response);
return getNetworkLocalInetSocketAddress(request, response);
}

@Nullable
@Override
default String getNetworkLocalAddress(REQUEST request, @Nullable RESPONSE response) {
return getServerSocketAddress(request, response);
default String getServerSocketAddress(REQUEST request, @Nullable RESPONSE response) {
return getNetworkLocalAddress(request, response);
}

@Nullable
@Override
default Integer getNetworkLocalPort(REQUEST request, @Nullable RESPONSE response) {
return getServerSocketPort(request, response);
default Integer getServerSocketPort(REQUEST request, @Nullable RESPONSE response) {
return getNetworkLocalPort(request, response);
}

@Nullable
@Override
default InetSocketAddress getNetworkPeerInetSocketAddress(
default InetSocketAddress getClientInetSocketAddress(
REQUEST request, @Nullable RESPONSE response) {
return getClientInetSocketAddress(request, response);
return getNetworkPeerInetSocketAddress(request, response);
}

@Nullable
@Override
default String getNetworkPeerAddress(REQUEST request, @Nullable RESPONSE response) {
return getClientSocketAddress(request, response);
default String getClientSocketAddress(REQUEST request, @Nullable RESPONSE response) {
return getNetworkPeerAddress(request, response);
}

@Nullable
@Override
default Integer getNetworkPeerPort(REQUEST request, @Nullable RESPONSE response) {
return getClientSocketPort(request, response);
default Integer getClientSocketPort(REQUEST request, @Nullable RESPONSE response) {
return getNetworkPeerPort(request, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {}

@SuppressWarnings("deprecation") // old semconv
@Override
public void onEnd(
AttributesBuilder attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ default Integer getClientPort(REQUEST request) {
return null;
}

// TODO deprecate

/**
* Returns an {@link InetSocketAddress} object representing the immediate client socket address.
*
* <p>Implementing this method is equivalent to implementing all of {@link
* #getClientSocketAddress(Object, Object)} and {@link #getClientSocketPort(Object, Object)}.
*
* @deprecated Implement {@link NetworkAttributesGetter#getNetworkPeerInetSocketAddress(Object,
* Object)} instead.
*/
@Deprecated
@Nullable
default InetSocketAddress getClientInetSocketAddress(
REQUEST request, @Nullable RESPONSE response) {
Expand All @@ -62,7 +64,11 @@ default InetSocketAddress getClientInetSocketAddress(
* 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)}.
*
* @deprecated Implement {@link NetworkAttributesGetter#getNetworkPeerAddress(Object, Object)}
* instead.
*/
@Deprecated
@Nullable
default String getClientSocketAddress(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getIpAddress(getClientInetSocketAddress(request, response));
Expand All @@ -78,7 +84,11 @@ default String getClientSocketAddress(REQUEST request, @Nullable RESPONSE respon
* 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)}.
*
* @deprecated Implement {@link NetworkAttributesGetter#getNetworkPeerPort(Object, Object)}
* instead.
*/
@Deprecated
@Nullable
default Integer getClientSocketPort(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getPort(getClientInetSocketAddress(request, response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ default Integer getServerPort(REQUEST request) {
* <p>Implementing this method is equivalent to implementing all of {@link
* #getServerSocketDomain(Object, Object)}, {@link #getServerSocketAddress(Object, Object)} and
* {@link #getServerSocketPort(Object, Object)}.
*
* @deprecated Implement {@link NetworkAttributesGetter#getNetworkPeerInetSocketAddress(Object,
* Object)} or {@link NetworkAttributesGetter#getNetworkLocalInetSocketAddress(Object,
* Object)} instead.
*/
@Deprecated
@Nullable
default InetSocketAddress getServerInetSocketAddress(
REQUEST request, @Nullable RESPONSE response) {
Expand All @@ -64,7 +69,10 @@ default InetSocketAddress getServerInetSocketAddress(
* 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
* #getServerInetSocketAddress(Object, Object)}.
*
* @deprecated This method is deprecated and will be removed without replacement.
*/
@Deprecated
@Nullable
default String getServerSocketDomain(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getDomainName(getServerInetSocketAddress(request, response));
Expand All @@ -80,7 +88,11 @@ default String getServerSocketDomain(REQUEST request, @Nullable RESPONSE respons
* 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
* #getServerInetSocketAddress(Object, Object)}.
*
* @deprecated Implement {@link NetworkAttributesGetter#getNetworkPeerAddress(Object, Object)} or
* {@link NetworkAttributesGetter#getNetworkLocalAddress(Object, Object)} instead.
*/
@Deprecated
@Nullable
default String getServerSocketAddress(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getIpAddress(getServerInetSocketAddress(request, response));
Expand All @@ -96,7 +108,11 @@ default String getServerSocketAddress(REQUEST request, @Nullable RESPONSE respon
* 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
* #getServerInetSocketAddress(Object, Object)}.
*
* @deprecated Implement {@link NetworkAttributesGetter#getNetworkPeerPort(Object, Object)} or
* {@link NetworkAttributesGetter#getNetworkLocalPort(Object, Object)} instead.
*/
@Deprecated
@Nullable
default Integer getServerSocketPort(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getPort(getServerInetSocketAddress(request, response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void shouldNotSetAnyValueIfPeerNameDoesNotMatch() {
assertTrue(endAttributes.build().isEmpty());
}

@SuppressWarnings("deprecation") // old semconv
@Test
void shouldSetPeerNameIfItMatches() {
// given
Expand Down Expand Up @@ -106,6 +107,7 @@ void shouldSetPeerNameIfItMatches() {
verify(httpAttributesExtractor, never()).getServerSocketDomain(any(), any());
}

@SuppressWarnings("deprecation") // old semconv
@Test
void shouldSetSockPeerNameIfItMatchesAndNoPeerNameProvided() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Integer getServerPort(InetSocketAddress request) {
}

@Override
public InetSocketAddress getServerInetSocketAddress(
public InetSocketAddress getNetworkPeerInetSocketAddress(
InetSocketAddress request, InetSocketAddress response) {
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ public Integer getServerPort(Addresses request) {
}

@Override
public InetSocketAddress getClientInetSocketAddress(Addresses request, Addresses response) {
public InetSocketAddress getNetworkPeerInetSocketAddress(
Addresses request, Addresses response) {
return request.peer;
}

@Override
public InetSocketAddress getServerInetSocketAddress(Addresses request, Addresses response) {
public InetSocketAddress getNetworkLocalInetSocketAddress(
Addresses request, Addresses response) {
return request.host;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,12 @@ public String getSockFamily(Map<String, String> request, Map<String, String> res
}

@Override
public String getServerSocketDomain(Map<String, String> request, Map<String, String> response) {
// we only support the InetSocketAddress case here; nearly no instrumentations override this
// method anyway
return null;
}

@Override
public String getServerSocketAddress(
Map<String, String> request, Map<String, String> response) {
public String getNetworkPeerAddress(Map<String, String> request, Map<String, String> response) {
return response.get("sockPeerAddr");
}

@Override
public Integer getServerSocketPort(Map<String, String> request, Map<String, String> response) {
public Integer getNetworkPeerPort(Map<String, String> request, Map<String, String> response) {
String sockPeerPort = response.get("sockPeerPort");
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ public String getSockFamily(Map<String, String> request) {
}

@Override
public String getClientSocketAddress(Map<String, String> request, Void response) {
public String getNetworkPeerAddress(Map<String, String> request, Void response) {
return request.get("sockPeerAddr");
}

@Override
public Integer getClientSocketPort(Map<String, String> request, Void response) {
public Integer getNetworkPeerPort(Map<String, String> request, Void response) {
String sockPeerPort = request.get("sockPeerPort");
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
}

@Nullable
@Override
public String getServerSocketAddress(Map<String, String> request, Void response) {
public String getNetworkLocalAddress(Map<String, String> request, Void response) {
return request.get("sockHostAddr");
}

@Nullable
@Override
public Integer getServerSocketPort(Map<String, String> request, Void response) {
public Integer getNetworkLocalPort(Map<String, String> request, Void response) {
String sockHostPort = request.get("sockHostPort");
return sockHostPort == null ? null : Integer.valueOf(sockHostPort);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void shouldNotSetAnyValueIfPeerNameDoesNotMatch() {
}

@Test
@SuppressWarnings("deprecation") // old semconv
void shouldSetPeerNameIfItMatches() {
// given
Map<String, String> peerServiceMapping = new HashMap<>();
Expand Down Expand Up @@ -105,6 +106,7 @@ void shouldSetPeerNameIfItMatches() {
verify(netAttributesExtractor, never()).getServerSocketDomain(any(), any());
}

@SuppressWarnings("deprecation") // old semconv
@Test
void shouldSetSockPeerNameIfItMatchesAndNoPeerNameProvided() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,12 @@ public String getSockFamily(Map<String, String> request, Map<String, String> res
}

@Override
public String getServerSocketDomain(Map<String, String> request, Map<String, String> response) {
return response.get("sockPeerName");
}

@Override
public String getServerSocketAddress(
Map<String, String> request, Map<String, String> response) {
public String getNetworkPeerAddress(Map<String, String> request, Map<String, String> response) {
return response.get("sockPeerAddr");
}

@Override
public Integer getServerSocketPort(Map<String, String> request, Map<String, String> response) {
public Integer getNetworkPeerPort(Map<String, String> request, Map<String, String> response) {
String sockPeerPort = response.get("sockPeerPort");
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ public String getSockFamily(Map<String, String> request) {
}

@Override
public String getClientSocketAddress(Map<String, String> request, Void response) {
public String getNetworkPeerAddress(Map<String, String> request, Void response) {
return request.get("sockPeerAddr");
}

@Override
public Integer getClientSocketPort(Map<String, String> request, Void response) {
public Integer getNetworkPeerPort(Map<String, String> request, Void response) {
String sockPeerPort = request.get("sockPeerPort");
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
}

@Nullable
@Override
public String getServerSocketAddress(Map<String, String> request, Void response) {
public String getNetworkLocalAddress(Map<String, String> request, Void response) {
return request.get("sockHostAddr");
}

@Nullable
@Override
public Integer getServerSocketPort(Map<String, String> request, Void response) {
public Integer getNetworkLocalPort(Map<String, String> request, Void response) {
String sockHostPort = request.get("sockHostPort");
return sockHostPort == null ? null : Integer.valueOf(sockHostPort);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ public String getSockFamily(Map<String, String> request, Map<String, String> res
}

@Override
public String getServerSocketAddress(
Map<String, String> request, Map<String, String> response) {
public String getNetworkPeerAddress(Map<String, String> request, Map<String, String> response) {
return response.get("sockPeerAddr");
}

@Override
public Integer getServerSocketPort(Map<String, String> request, Map<String, String> response) {
public Integer getNetworkPeerPort(Map<String, String> request, Map<String, String> response) {
String sockPeerPort = response.get("sockPeerPort");
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
}
Expand Down
Loading

0 comments on commit e9026cd

Please sign in to comment.