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

NetAttributesExtractor optimization #4278

Closed
wants to merge 1 commit into from
Closed
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 @@ -110,6 +110,10 @@ static class ConstantNetAttributesExtractor
private static final InetSocketAddress ADDRESS =
InetSocketAddress.createUnresolved("localhost", 8080);

protected ConstantNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public @Nullable InetSocketAddress getAddress(Void unused, @Nullable Void unused2) {
return ADDRESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
public abstract class InetSocketAddressNetAttributesExtractor<REQUEST, RESPONSE>
extends NetAttributesExtractor<REQUEST, RESPONSE> {

protected InetSocketAddressNetAttributesExtractor() {
this(NetPeerAttributeExtraction.ON_BOTH);
}

protected InetSocketAddressNetAttributesExtractor(
NetPeerAttributeExtraction netPeerAttributeExtraction) {
super(netPeerAttributeExtraction);
}

/**
* This method will be called twice: both when the request starts ({@code response} is always null
* then) and when the response ends. This way it is possible to capture net attributes in both
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@
public abstract class NetAttributesExtractor<REQUEST, RESPONSE>
extends AttributesExtractor<REQUEST, RESPONSE> {

private final NetPeerAttributeExtraction netPeerAttributeExtraction;

protected NetAttributesExtractor() {
this(NetPeerAttributeExtraction.ON_BOTH);
}

protected NetAttributesExtractor(NetPeerAttributeExtraction netPeerAttributeExtraction) {
this.netPeerAttributeExtraction = netPeerAttributeExtraction;
}

@Override
protected final void onStart(AttributesBuilder attributes, REQUEST request) {
set(attributes, SemanticAttributes.NET_TRANSPORT, transport(request));

if (netPeerAttributeExtraction == NetPeerAttributeExtraction.ON_END) {
return;
}

String peerIp = peerIp(request, null);
String peerName = peerName(request, null);

Expand All @@ -44,6 +58,10 @@ protected final void onEnd(
@Nullable RESPONSE response,
@Nullable Throwable error) {

if (netPeerAttributeExtraction == NetPeerAttributeExtraction.ON_START) {
return;
}

String peerIp = peerIp(request, response);
String peerName = peerName(request, response);

Expand Down Expand Up @@ -84,4 +102,10 @@ protected final void onEnd(
*/
@Nullable
public abstract String peerIp(REQUEST request, @Nullable RESPONSE response);

public enum NetPeerAttributeExtraction {
ON_START,
ON_END,
ON_BOTH
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
public final class DubboNetAttributesExtractor
extends InetSocketAddressNetAttributesExtractor<DubboRequest, Result> {

public DubboNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public @Nullable InetSocketAddress getAddress(DubboRequest request, @Nullable Result result) {
return request.context().getRemoteAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
final class ApacheHttpAsyncClientNetAttributesExtractor
extends NetAttributesExtractor<ApacheHttpClientRequest, HttpResponse> {

ApacheHttpAsyncClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(ApacheHttpClientRequest request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
final class ApacheHttpClientNetAttributesExtractor
extends NetAttributesExtractor<HttpMethod, HttpMethod> {

ApacheHttpClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(HttpMethod request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
final class ApacheHttpClientNetAttributesExtractor
extends NetAttributesExtractor<ApacheHttpClientRequest, HttpResponse> {

ApacheHttpClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(ApacheHttpClientRequest request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
final class ApacheHttpClientNetAttributesExtractor
extends NetAttributesExtractor<ApacheHttpClientRequest, HttpResponse> {

ApacheHttpClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(ApacheHttpClientRequest request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ final class ApacheHttpClientNetAttributesExtractor
private static final Logger logger =
LoggerFactory.getLogger(ApacheHttpClientNetAttributesExtractor.class);

ApacheHttpClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(ClassicHttpRequest request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
public final class ArmeriaNetAttributesExtractor
extends InetSocketAddressNetAttributesExtractor<RequestContext, RequestLog> {

public ArmeriaNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_END);
}

@Override
public String transport(RequestContext ctx) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
final class AsyncHttpClientNetAttributesExtractor
extends NetAttributesExtractor<Request, Response> {

AsyncHttpClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(Request request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
final class AsyncHttpClientNetAttributesExtractor
extends InetSocketAddressNetAttributesExtractor<RequestContext, Response> {

AsyncHttpClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_END);
}

@Override
public String transport(RequestContext requestContext) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
final class CassandraNetAttributesExtractor
extends InetSocketAddressNetAttributesExtractor<CassandraRequest, ExecutionInfo> {

CassandraNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_END);
}

@Override
@Nullable
public String transport(CassandraRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
final class CassandraNetAttributesExtractor
extends InetSocketAddressNetAttributesExtractor<CassandraRequest, ExecutionInfo> {

CassandraNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_END);
}

@Override
@Nullable
public String transport(CassandraRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

final class ElasticsearchRestNetAttributesExtractor
extends NetAttributesExtractor<String, Response> {
ElasticsearchRestNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_END);
}

@Override
public String transport(String s) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

public class Elasticsearch6TransportNetAttributesExtractor
extends InetSocketAddressNetAttributesExtractor<ElasticTransportRequest, ActionResponse> {

public Elasticsearch6TransportNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_END);
}

@Override
public @Nullable String transport(ElasticTransportRequest elasticTransportRequest) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

public class ElasticTransportNetAttributesExtractor
extends NetAttributesExtractor<ElasticTransportRequest, ActionResponse> {
public ElasticTransportNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_END);
}

@Override
public @Nullable String transport(ElasticTransportRequest elasticTransportRequest) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
final class GoogleHttpClientNetAttributesExtractor
extends NetAttributesExtractor<HttpRequest, HttpResponse> {

GoogleHttpClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(HttpRequest request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

public final class GrpcNetAttributesExtractor
extends InetSocketAddressNetAttributesExtractor<GrpcRequest, Status> {

public GrpcNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
@Nullable
public InetSocketAddress getAddress(GrpcRequest request, @Nullable Status status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import org.checkerframework.checker.nullness.qual.Nullable;

class HttpUrlNetAttributesExtractor extends NetAttributesExtractor<HttpURLConnection, Integer> {
HttpUrlNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public @Nullable String transport(HttpURLConnection connection) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class JdkHttpNetAttributesExtractor

private static final Logger logger = LoggerFactory.getLogger(JdkHttpNetAttributesExtractor.class);

public JdkHttpNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(HttpRequest httpRequest) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
final class JaxRsClientNetAttributesExtractor
extends NetAttributesExtractor<ClientRequest, ClientResponse> {

JaxRsClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(ClientRequest request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
final class JaxRsClientNetAttributesExtractor
extends NetAttributesExtractor<ClientRequestContext, ClientResponseContext> {

JaxRsClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(ClientRequestContext request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
final class ResteasyClientNetAttributesExtractor
extends NetAttributesExtractor<ClientInvocation, Response> {

ResteasyClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(ClientInvocation request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

public final class JdbcNetAttributesExtractor extends NetAttributesExtractor<DbRequest, Void> {

public JdbcNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Nullable
@Override
public String transport(DbRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

final class JedisNetAttributesExtractor extends NetAttributesExtractor<JedisRequest, Void> {

JedisNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
@Nullable
public String transport(JedisRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
final class JedisNetAttributesExtractor
extends InetSocketAddressNetAttributesExtractor<JedisRequest, Void> {

JedisNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public @Nullable InetSocketAddress getAddress(JedisRequest jedisRequest, @Nullable Void unused) {
Socket socket = jedisRequest.getConnection().getSocket();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
public class JettyHttpClientNetAttributesExtractor
extends NetAttributesExtractor<Request, Response> {

public JettyHttpClientNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(Request request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import org.checkerframework.checker.nullness.qual.Nullable;

class KubernetesNetAttributesExtractor extends NetAttributesExtractor<Request, ApiResponse<?>> {
KubernetesNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
public String transport(Request request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

final class LettuceConnectNetAttributesExtractor extends NetAttributesExtractor<RedisURI, Void> {

LettuceConnectNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
@Nullable
public String transport(RedisURI redisUri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

final class LettuceConnectNetAttributesExtractor extends NetAttributesExtractor<RedisURI, Void> {

LettuceConnectNetAttributesExtractor() {
super(NetPeerAttributeExtraction.ON_START);
}

@Override
@Nullable
public String transport(RedisURI redisUri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public static void stopSpan(
scope.close();

LibertyResponse response = new LibertyResponse(statusCode);
request.setCompleted();

Throwable t = failure != null ? failure : throwable;
instrumenter().end(context, request, response, t);
Expand Down
Loading