Skip to content

Commit

Permalink
Add remote address to gRPC spans
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Jan 30, 2025
1 parent 8edf94b commit 5d0ed38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
import static io.opentelemetry.api.trace.SpanKind.SERVER;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_GRPC_STATUS_CODE;
Expand Down Expand Up @@ -132,6 +134,8 @@ void grpc() {
assertEquals(Status.Code.OK.value(), server.getAttributes().get(RPC_GRPC_STATUS_CODE));
assertNotNull(server.getAttributes().get(SERVER_PORT));
assertNotNull(server.getAttributes().get(SERVER_ADDRESS));
assertNotNull(server.getAttributes().get(NETWORK_PEER_PORT));
assertNotNull(server.getAttributes().get(NETWORK_PEER_ADDRESS));

final SpanData internal = getSpanByKindAndParentId(spans, INTERNAL, server.getSpanId());
assertEquals("span.internal", internal.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.opentelemetry.runtime.tracing.intrumentation.grpc;

import static io.grpc.Grpc.TRANSPORT_ATTR_REMOTE_ADDR;

import java.net.SocketAddress;

import io.grpc.Attributes;
Expand All @@ -13,7 +15,12 @@ public static GrpcRequest server(
final Metadata metadata,
final Attributes attributes,
final String authority) {
return new GrpcRequest(methodDescriptor, metadata, attributes, null, authority);

return new GrpcRequest(methodDescriptor,
metadata,
attributes,
attributes == null ? null : attributes.get(TRANSPORT_ATTR_REMOTE_ADDR),
authority);
}

public static GrpcRequest client(final MethodDescriptor<?, ?> methodDescriptor, String authority) {
Expand Down

0 comments on commit 5d0ed38

Please sign in to comment.