fix: add attributes of net.peer.* for grpc client span
MODIFY
instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java
instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java
@@ -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);

MODIFY
instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.groovy
instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.groovy
@@ -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

MODIFY
instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.groovy
instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.groovy
@@ -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) {

fix: add attributes of net.peer.* for grpc client span (#5324)