fix: add attributes of net.peer.* for grpc client span (#5324)
This commit is contained in:
parent
afdeb1a557
commit
e551d99db3
|
|
@ -11,7 +11,6 @@ import io.grpc.ClientCall;
|
|||
import io.grpc.ClientInterceptor;
|
||||
import io.grpc.ForwardingClientCall;
|
||||
import io.grpc.ForwardingClientCallListener;
|
||||
import io.grpc.Grpc;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.Status;
|
||||
|
|
@ -21,7 +20,9 @@ import io.opentelemetry.context.Context;
|
|||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
||||
|
||||
final class TracingClientInterceptor implements ClientInterceptor {
|
||||
|
|
@ -55,8 +56,13 @@ final class TracingClientInterceptor implements ClientInterceptor {
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
SocketAddress address = result.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
|
||||
SocketAddress address = null;
|
||||
try {
|
||||
URI uri = new URI(null, next.authority(), null, null, null);
|
||||
address = InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort());
|
||||
} catch (Throwable e) {
|
||||
// do nothing
|
||||
}
|
||||
request.setRemoteAddress(address);
|
||||
|
||||
return new TracingClientCall<>(result, parentContext, context, request);
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ abstract class AbstractGrpcStreamingTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "Conversation"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" Status.OK.code.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
(1..(clientMessageCount * serverMessageCount + clientMessageCount)).each {
|
||||
def messageId = it
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ abstract class AbstractGrpcTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "SayHello"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" Status.Code.OK.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -236,6 +238,8 @@ abstract class AbstractGrpcTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "SayHello"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" Status.Code.OK.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -369,6 +373,8 @@ abstract class AbstractGrpcTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "SayHello"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" Status.Code.OK.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -465,6 +471,8 @@ abstract class AbstractGrpcTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "SayHello"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" grpcStatus.code.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -565,6 +573,8 @@ abstract class AbstractGrpcTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "SayHello"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" Status.UNKNOWN.code.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -740,6 +750,8 @@ abstract class AbstractGrpcTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "SayHello"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" Status.OK.code.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -871,6 +883,8 @@ abstract class AbstractGrpcTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "SayHello"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" Status.CANCELLED.code.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -985,6 +999,8 @@ abstract class AbstractGrpcTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "ServerReflectionInfo"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" Status.OK.code.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -1093,6 +1109,8 @@ abstract class AbstractGrpcTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_METHOD" "SayHello"
|
||||
"$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP
|
||||
"$SemanticAttributes.RPC_GRPC_STATUS_CODE" Status.Code.OK.value()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" port
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue