diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java index 24e4d0e9b9b9..45ce8c788ca9 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/TracingClientInterceptor.java @@ -11,7 +11,6 @@ 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.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 @@ public ClientCall interceptCall( 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); diff --git a/instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.groovy b/instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.groovy index 4842e5e4d14b..ea3d891bb13b 100644 --- a/instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.groovy +++ b/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 diff --git a/instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.groovy b/instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.groovy index b4b445fd7d82..772a7840ff88 100644 --- a/instrumentation/grpc-1.6/testing/src/main/groovy/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.groovy +++ b/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) {