Prevent DNS lookup by gRPC instrumentation
MODIFY
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/GrpcClientBuilderInstrumentation.java
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/GrpcClientBuilderInstrumentation.java
@@ -110,7 +110,7 @@ public class GrpcClientBuilderInstrumentation extends Instrumenter.Default {
@Advice.Return final ManagedChannelBuilder builder) {
final ContextStore<ManagedChannelBuilder, InetSocketAddress> contextStore =
InstrumentationContext.get(ManagedChannelBuilder.class, InetSocketAddress.class);
- contextStore.put(builder, new InetSocketAddress(address, port));
+ contextStore.put(builder, InetSocketAddress.createUnresolved(address, port));
}
}
}

MODIFY
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/TracingClientInterceptor.java
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/TracingClientInterceptor.java
@@ -55,7 +55,7 @@ public class TracingClientInterceptor implements ClientInterceptor {
final Span span = TRACER.spanBuilder(methodName).setSpanKind(CLIENT).startSpan();
try (final Scope scope = TRACER.withSpan(span)) {
DECORATE.afterStart(span);
- GrpcHelper.prepareSpan(span, methodName, peerAddress);
+ GrpcHelper.prepareSpan(span, methodName, peerAddress, false);
final ClientCall<ReqT, RespT> result;
try {

MODIFY
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/common/GrpcHelper.java
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/common/GrpcHelper.java
@@ -21,7 +21,10 @@ import java.net.InetSocketAddress;
public class GrpcHelper {
public static void prepareSpan(
- final Span span, final String methodName, final InetSocketAddress peerAddress) {
+ final Span span,
+ final String methodName,
+ final InetSocketAddress peerAddress,
+ final boolean server) {
String serviceName =
"(unknown)"; // Spec says it's mandatory, so populate even if we couldn't determine it.
final int slash = methodName.indexOf('/');
@@ -35,8 +38,11 @@ public class GrpcHelper {
span.setAttribute(MoreTags.RPC_SERVICE, serviceName);
if (peerAddress != null) {
span.setAttribute(MoreTags.NET_PEER_PORT, peerAddress.getPort());
+ if (server) {
span.setAttribute(MoreTags.NET_PEER_IP, peerAddress.getAddress().getHostAddress());
- span.setAttribute(MoreTags.NET_PEER_NAME, peerAddress.getAddress().getHostName());
+ } else {
+ span.setAttribute(MoreTags.NET_PEER_NAME, peerAddress.getHostName());
+ }
} else {
// The spec says these fields must be populated, so put some values in even if we don't have
// an address recorded.

MODIFY
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/server/TracingServerInterceptor.java
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/server/TracingServerInterceptor.java
@@ -64,7 +64,7 @@ public class TracingServerInterceptor implements ServerInterceptor {
final SocketAddress addr = call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
final InetSocketAddress iAddr =
addr instanceof InetSocketAddress ? (InetSocketAddress) addr : null;
- GrpcHelper.prepareSpan(span, methodName, iAddr);
+ GrpcHelper.prepareSpan(span, methodName, iAddr, true);
DECORATE.afterStart(span);

MODIFY
instrumentation/grpc-1.5/src/test/groovy/GrpcStreamingTest.groovy
instrumentation/grpc-1.5/src/test/groovy/GrpcStreamingTest.groovy
@@ -120,7 +120,6 @@ class GrpcStreamingTest extends AgentTestRunner {
"$MoreTags.RPC_SERVICE" "Greeter"
"$Tags.COMPONENT" "grpc-client"
"$MoreTags.NET_PEER_NAME" "localhost"
- "$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" port
"status.code" "OK"
}
@@ -144,7 +143,6 @@ class GrpcStreamingTest extends AgentTestRunner {
"$MoreTags.SPAN_TYPE" SpanTypes.RPC
"$MoreTags.RPC_SERVICE" "Greeter"
"$Tags.COMPONENT" "grpc-server"
- "$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
"status.code" "OK"

MODIFY
instrumentation/grpc-1.5/src/test/groovy/GrpcTest.groovy
instrumentation/grpc-1.5/src/test/groovy/GrpcTest.groovy
@@ -85,7 +85,6 @@ class GrpcTest extends AgentTestRunner {
"$MoreTags.RPC_SERVICE" "Greeter"
"$Tags.COMPONENT" "grpc-client"
"$MoreTags.NET_PEER_NAME" "localhost"
- "$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" port
"status.code" "OK"
}
@@ -106,7 +105,6 @@ class GrpcTest extends AgentTestRunner {
"$MoreTags.SPAN_TYPE" SpanTypes.RPC
"$MoreTags.RPC_SERVICE" "Greeter"
"$Tags.COMPONENT" "grpc-server"
- "$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
"status.code" "OK"
@@ -166,7 +164,6 @@ class GrpcTest extends AgentTestRunner {
"status.code" "${status.code.name()}"
"status.description" description
"$MoreTags.NET_PEER_NAME" "localhost"
- "$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" port
}
}
@@ -188,7 +185,6 @@ class GrpcTest extends AgentTestRunner {
"$MoreTags.RPC_SERVICE" "Greeter"
"status.code" "${status.code.name()}"
"status.description" description
- "$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
if (status.cause != null) {
@@ -255,7 +251,6 @@ class GrpcTest extends AgentTestRunner {
"$Tags.COMPONENT" "grpc-client"
"status.code" "UNKNOWN"
"$MoreTags.NET_PEER_NAME" "localhost"
- "$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
}
}
@@ -275,7 +270,6 @@ class GrpcTest extends AgentTestRunner {
"$MoreTags.SPAN_TYPE" SpanTypes.RPC
"$Tags.COMPONENT" "grpc-server"
"$MoreTags.RPC_SERVICE" "Greeter"
- "$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
errorTags error.class, error.message

Prevent DNS lookup by gRPC instrumentation (#224)