Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate InetSocketAddressNetClientAttributesGetter and move its met… #8591

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,17 @@
/**
* 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}. Most network libraries will provide access to a
* {@link InetSocketAddress} so this is a convenient alternative to {@link
* NetClientAttributesExtractor}. There is no meaning to implement both in the same instrumentation.
* 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
protected abstract InetSocketAddress getPeerSocketAddress(
REQUEST request, @Nullable RESPONSE response);

@Nullable
@Override
public String getSockFamily(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getSockFamily(getPeerSocketAddress(request, response), null);
}

@Override
@Nullable
public final String getSockPeerAddr(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getHostAddress(getPeerSocketAddress(request, response));
}

@Override
@Nullable
public String getSockPeerName(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getHostName(getPeerSocketAddress(request, response));
}

@Nullable
@Override
public Integer getSockPeerPort(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getPort(getPeerSocketAddress(request, response));
}
public abstract InetSocketAddress getPeerSocketAddress(
REQUEST request, @Nullable RESPONSE response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.instrumentation.api.instrumenter.net;

import java.net.InetSocketAddress;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -48,23 +49,82 @@ default String getProtocolVersion(REQUEST request, @Nullable RESPONSE response)
@Nullable
Integer getPeerPort(REQUEST 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)}.
*/
@Nullable
default String getSockFamily(REQUEST request, @Nullable RESPONSE response) {
default InetSocketAddress getPeerSocketAddress(REQUEST request, @Nullable RESPONSE response) {
return null;
}

/**
* 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: {@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)}.
*/
@Nullable
default String getSockFamily(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getSockFamily(getPeerSocketAddress(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)}.
*/
@Nullable
default String getSockPeerAddr(REQUEST request, @Nullable RESPONSE response) {
return null;
return InetSocketAddressUtil.getHostAddress(getPeerSocketAddress(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)}.
*/
@Nullable
default String getSockPeerName(REQUEST request, @Nullable RESPONSE response) {
return null;
return InetSocketAddressUtil.getHostName(getPeerSocketAddress(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)}.
*/
@Nullable
default Integer getSockPeerPort(REQUEST request, @Nullable RESPONSE response) {
return null;
return InetSocketAddressUtil.getPort(getPeerSocketAddress(request, response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@
@ExtendWith(MockitoExtension.class)
class InetSocketAddressNetClientAttributesGetterTest {

private final InetSocketAddressNetClientAttributesGetter<InetSocketAddress, InetSocketAddress>
getter =
new InetSocketAddressNetClientAttributesGetter<InetSocketAddress, InetSocketAddress>() {

@Override
public String getPeerName(InetSocketAddress request) {
// net.peer.name and net.peer.port are tested in NetClientAttributesExtractorTest
return null;
}

@Override
public Integer getPeerPort(InetSocketAddress request) {
// net.peer.name and net.peer.port are tested in NetClientAttributesExtractorTest
return null;
}

@Override
protected InetSocketAddress getPeerSocketAddress(
InetSocketAddress request, InetSocketAddress response) {
return response;
}
};
static class TestNetClientAttributesGetter
implements NetClientAttributesGetter<InetSocketAddress, InetSocketAddress> {

@Override
public String getPeerName(InetSocketAddress request) {
// net.peer.name and net.peer.port are tested in NetClientAttributesExtractorTest
return null;
}

@Override
public Integer getPeerPort(InetSocketAddress request) {
// net.peer.name and net.peer.port are tested in NetClientAttributesExtractorTest
return null;
}

@Override
public InetSocketAddress getPeerSocketAddress(
InetSocketAddress request, InetSocketAddress response) {
return response;
}
}

private final AttributesExtractor<InetSocketAddress, InetSocketAddress> extractor =
NetClientAttributesExtractor.create(getter);
NetClientAttributesExtractor.create(new TestNetClientAttributesGetter());

@Test
void noInetSocketAddress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -88,8 +88,7 @@ public List<String> getResponseHeader(Void unused, Void unused2, String name) {
}
}

static class ConstantNetAttributesGetter
extends InetSocketAddressNetClientAttributesGetter<Void, Void> {
static class ConstantNetAttributesGetter implements NetClientAttributesGetter<Void, Void> {

private static final InetSocketAddress PEER_ADDRESS =
InetSocketAddress.createUnresolved("localhost", 8080);
Expand Down Expand Up @@ -120,7 +119,7 @@ public Integer getPeerPort(Void request) {

@Nullable
@Override
protected InetSocketAddress getPeerSocketAddress(Void request, @Nullable Void response) {
public InetSocketAddress getPeerSocketAddress(Void request, @Nullable Void response) {
return PEER_ADDRESS;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal;

import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import org.apache.dubbo.rpc.Result;
Expand All @@ -16,7 +16,7 @@
* any time.
*/
public final class DubboNetClientAttributesGetter
extends InetSocketAddressNetClientAttributesGetter<DubboRequest, Result> {
implements NetClientAttributesGetter<DubboRequest, Result> {

@Nullable
@Override
Expand All @@ -31,8 +31,7 @@ public Integer getPeerPort(DubboRequest request) {

@Override
@Nullable
protected InetSocketAddress getPeerSocketAddress(
DubboRequest request, @Nullable Result response) {
public InetSocketAddress getPeerSocketAddress(DubboRequest request, @Nullable Result response) {
return request.remoteAddress();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

package io.opentelemetry.javaagent.instrumentation.apachehttpasyncclient;

import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import org.apache.http.HttpResponse;

final class ApacheHttpAsyncClientNetAttributesGetter
extends InetSocketAddressNetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {
implements NetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {

@Override
public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
Expand All @@ -37,7 +37,7 @@ public Integer getPeerPort(ApacheHttpClientRequest request) {

@Nullable
@Override
protected InetSocketAddress getPeerSocketAddress(
public InetSocketAddress getPeerSocketAddress(
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return request.peerSocketAddress();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

package io.opentelemetry.instrumentation.apachehttpclient.v4_3;

import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import org.apache.http.HttpResponse;

final class ApacheHttpClientNetAttributesGetter
extends InetSocketAddressNetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {
implements NetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {

@Override
public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
Expand All @@ -38,7 +38,7 @@ public Integer getPeerPort(ApacheHttpClientRequest request) {

@Nullable
@Override
protected InetSocketAddress getPeerSocketAddress(
public InetSocketAddress getPeerSocketAddress(
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return request.peerSocketAddress();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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.InetSocketAddressNetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import javax.annotation.Nullable;
Expand All @@ -19,7 +19,7 @@
* any time.
*/
public final class ArmeriaNetClientAttributesGetter
extends InetSocketAddressNetClientAttributesGetter<RequestContext, RequestLog> {
implements NetClientAttributesGetter<RequestContext, RequestLog> {

@Override
public String getProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) {
Expand Down Expand Up @@ -65,7 +65,7 @@ public Integer getPeerPort(RequestContext ctx) {

@Override
@Nullable
protected InetSocketAddress getPeerSocketAddress(
public InetSocketAddress getPeerSocketAddress(
RequestContext ctx, @Nullable RequestLog requestLog) {
SocketAddress address = ctx.remoteAddress();
if (address instanceof InetSocketAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import org.asynchttpclient.Response;
import org.asynchttpclient.netty.request.NettyRequest;

final class AsyncHttpClientNetAttributesGetter
extends InetSocketAddressNetClientAttributesGetter<RequestContext, Response> {
implements NetClientAttributesGetter<RequestContext, Response> {

@Nullable
@Override
Expand Down Expand Up @@ -62,7 +62,7 @@ public Integer getPeerPort(RequestContext request) {

@Override
@Nullable
protected InetSocketAddress getPeerSocketAddress(
public InetSocketAddress getPeerSocketAddress(
RequestContext request, @Nullable Response response) {
if (response != null && response.getRemoteAddress() instanceof InetSocketAddress) {
return (InetSocketAddress) response.getRemoteAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
package io.opentelemetry.javaagent.instrumentation.cassandra.v3_0;

import com.datastax.driver.core.ExecutionInfo;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;

final class CassandraNetAttributesGetter
extends InetSocketAddressNetClientAttributesGetter<CassandraRequest, ExecutionInfo> {
implements NetClientAttributesGetter<CassandraRequest, ExecutionInfo> {

@Nullable
@Override
Expand All @@ -27,7 +27,7 @@ public Integer getPeerPort(CassandraRequest request) {

@Override
@Nullable
protected InetSocketAddress getPeerSocketAddress(
public InetSocketAddress getPeerSocketAddress(
CassandraRequest request, @Nullable ExecutionInfo executionInfo) {
return executionInfo == null ? null : executionInfo.getQueriedHost().getSocketAddress();
}
Expand Down
Loading