Skip to content

Commit

Permalink
Net attributes getters changes: getter implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Aug 30, 2022
1 parent 3abaf5e commit e925d1b
Show file tree
Hide file tree
Showing 82 changed files with 1,782 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,39 @@ public List<String> responseHeader(Void unused, Void unused2, String name) {
static class ConstantNetAttributesGetter
extends InetSocketAddressNetServerAttributesGetter<Void> {

private static final InetSocketAddress ADDRESS =
private static final InetSocketAddress PEER_ADDRESS =
InetSocketAddress.createUnresolved("localhost", 8080);
private static final InetSocketAddress HOST_ADDRESS =
InetSocketAddress.createUnresolved("localhost", 80);

@Override
@Nullable
public InetSocketAddress getAddress(Void unused) {
return ADDRESS;
public String transport(Void unused) {
return SemanticAttributes.NetTransportValues.IP_TCP;
}

@Nullable
@Override
public String hostName(Void unused) {
return null;
}

@Nullable
public String transport(Void unused) {
return SemanticAttributes.NetTransportValues.IP_TCP;
@Override
public Integer hostPort(Void unused) {
return null;
}

@Override
@Nullable
public InetSocketAddress getPeerAddress(Void unused) {
return PEER_ADDRESS;
}

@Nullable
@Override
public InetSocketAddress getHostAddress(Void unused) {
return HOST_ADDRESS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,28 @@ public String peerName(HttpRequest httpRequest, @Nullable HttpResponse httpRespo
public Integer peerPort(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return httpRequest.uri().authority().port();
}

@Nullable
@Override
public String sockFamily(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}

@Nullable
@Override
public String sockPeerAddr(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}

@Nullable
@Override
public String sockPeerName(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}

@Nullable
@Override
public Integer sockPeerPort(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ static DubboRequest create(RpcInvocation invocation, RpcContext context) {
// In dubbo 3 RpcContext delegates to a ThreadLocal context. We copy the url and remote address
// here to ensure we can access them from the thread that ends the span.
return new AutoValue_DubboRequest(
invocation, context, context.getUrl(), context.getRemoteAddress());
invocation,
context,
context.getUrl(),
context.getRemoteAddress(),
context.getLocalAddress());
}

abstract RpcInvocation invocation();
Expand All @@ -30,4 +34,7 @@ static DubboRequest create(RpcInvocation invocation, RpcContext context) {

@Nullable
public abstract InetSocketAddress remoteAddress();

@Nullable
public abstract InetSocketAddress localAddress();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Result;

/**
Expand All @@ -21,19 +20,24 @@ public final class DubboNetClientAttributesGetter

@Override
@Nullable
public InetSocketAddress getAddress(DubboRequest request, @Nullable Result response) {
InetSocketAddress address = request.remoteAddress();
// dubbo 3 doesn't set remote address for client calls
if (address == null) {
URL url = request.url();
address = InetSocketAddress.createUnresolved(url.getHost(), url.getPort());
}
return address;
public String transport(DubboRequest request, @Nullable Result response) {
return null;
}

@Nullable
@Override
public String peerName(DubboRequest request, @Nullable Result result) {
return request.url().getHost();
}

@Override
public Integer peerPort(DubboRequest request, @Nullable Result result) {
return request.url().getPort();
}

@Override
@Nullable
public String transport(DubboRequest request, @Nullable Result response) {
return null;
public InetSocketAddress getPeerAddress(DubboRequest request, @Nullable Result response) {
return request.remoteAddress();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,31 @@ public final class DubboNetServerAttributesGetter

@Override
@Nullable
public InetSocketAddress getAddress(DubboRequest request) {
return request.remoteAddress();
public String transport(DubboRequest request) {
return null;
}

@Nullable
@Override
public String hostName(DubboRequest request) {
return null;
}

@Nullable
public String transport(DubboRequest request) {
@Override
public Integer hostPort(DubboRequest request) {
return null;
}

@Override
@Nullable
public InetSocketAddress getPeerAddress(DubboRequest request) {
return request.remoteAddress();
}

@Nullable
@Override
public InetSocketAddress getHostAddress(DubboRequest request) {
return request.localAddress();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

package io.opentelemetry.javaagent.instrumentation.apachehttpasyncclient;

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

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

@Override
public String transport(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
Expand All @@ -28,4 +29,11 @@ public String peerName(ApacheHttpClientRequest request, @Nullable HttpResponse r
public Integer peerPort(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return request.getPeerPort();
}

@Nullable
@Override
public InetSocketAddress getPeerAddress(
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return request.peerAddress();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import static java.util.logging.Level.FINE;

import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand All @@ -27,15 +29,17 @@ public final class ApacheHttpClientRequest {
@Nullable private final URI uri;

private final HttpRequest delegate;
@Nullable private final HttpHost target;

public ApacheHttpClientRequest(HttpHost httpHost, HttpRequest httpRequest) {
public ApacheHttpClientRequest(@Nullable HttpHost httpHost, HttpRequest httpRequest) {
URI calculatedUri = getUri(httpRequest);
if (calculatedUri != null && httpHost != null) {
uri = getCalculatedUri(httpHost, calculatedUri);
} else {
uri = calculatedUri;
}
delegate = httpRequest;
target = httpHost;
}

public List<String> getHeader(String name) {
Expand Down Expand Up @@ -143,4 +147,13 @@ private static URI getCalculatedUri(HttpHost httpHost, URI uri) {
return null;
}
}

@Nullable
public InetSocketAddress peerAddress() {
if (target == null) {
return null;
}
InetAddress inetAddress = target.getAddress();
return inetAddress == null ? null : new InetSocketAddress(inetAddress, target.getPort());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,28 @@ public Integer peerPort(HttpMethod request, @Nullable HttpMethod response) {
HostConfiguration hostConfiguration = request.getHostConfiguration();
return hostConfiguration != null ? hostConfiguration.getPort() : null;
}

@Nullable
@Override
public String sockFamily(HttpMethod request, @Nullable HttpMethod response) {
return null;
}

@Nullable
@Override
public String sockPeerAddr(HttpMethod request, @Nullable HttpMethod response) {
return null;
}

@Nullable
@Override
public String sockPeerName(HttpMethod request, @Nullable HttpMethod response) {
return null;
}

@Nullable
@Override
public Integer sockPeerPort(HttpMethod request, @Nullable HttpMethod response) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,28 @@ public String peerName(ApacheHttpClientRequest request, @Nullable HttpResponse r
public Integer peerPort(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return request.getPeerPort();
}

@Nullable
@Override
public String sockFamily(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}

@Nullable
@Override
public String sockPeerAddr(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}

@Nullable
@Override
public String sockPeerName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}

@Nullable
@Override
public Integer sockPeerPort(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

package io.opentelemetry.instrumentation.apachehttpclient.v4_3;

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

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

@Override
public String transport(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
Expand All @@ -29,4 +30,11 @@ public String peerName(ApacheHttpClientRequest request, @Nullable HttpResponse r
public Integer peerPort(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return request.getPeerPort();
}

@Nullable
@Override
public InetSocketAddress getPeerAddress(
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return request.peerAddress();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import static java.util.logging.Level.FINE;

import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand All @@ -27,6 +29,7 @@ public final class ApacheHttpClientRequest {
@Nullable private final URI uri;

private final HttpRequest delegate;
@Nullable private final HttpHost target;

ApacheHttpClientRequest(@Nullable HttpHost httpHost, HttpRequest httpRequest) {
URI calculatedUri = getUri(httpRequest);
Expand All @@ -36,6 +39,7 @@ public final class ApacheHttpClientRequest {
uri = calculatedUri;
}
delegate = httpRequest;
target = httpHost;
}

/** Returns the actual {@link HttpRequest} being executed by the client. */
Expand Down Expand Up @@ -146,4 +150,13 @@ private static URI getCalculatedUri(HttpHost httpHost, URI uri) {
return null;
}
}

@Nullable
public InetSocketAddress peerAddress() {
if (target == null) {
return null;
}
InetAddress inetAddress = target.getAddress();
return inetAddress == null ? null : new InetSocketAddress(inetAddress, target.getPort());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,28 @@ public Integer peerPort(HttpRequest request, @Nullable HttpResponse response) {
return null;
}
}

@Nullable
@Override
public String sockFamily(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}

@Nullable
@Override
public String sockPeerAddr(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}

@Nullable
@Override
public String sockPeerName(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}

@Nullable
@Override
public Integer sockPeerPort(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}
}
Loading

0 comments on commit e925d1b

Please sign in to comment.