Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.hypertrace.core.datamodel.StructuredTrace;
import org.hypertrace.core.datamodel.shared.SpanAttributeUtils;
import org.hypertrace.semantic.convention.utils.http.HttpSemanticConventionUtils;
import org.hypertrace.semantic.convention.utils.rpc.RpcSemanticConventionUtils;
import org.hypertrace.traceenricher.enrichedspan.constants.EnrichedSpanConstants;
import org.hypertrace.traceenricher.enrichedspan.constants.utils.EnrichedSpanUtils;
import org.hypertrace.traceenricher.enrichedspan.constants.v1.Api;
Expand Down Expand Up @@ -315,7 +316,15 @@ String getRequestUrl(Event event, Protocol protocol) {
.orElse(HttpSemanticConventionUtils.getHttpPath(event).orElse(null));

case PROTOCOL_GRPC:
return event.getEventName();
/**
* For RPC methods, we show URL/URI as a combination of rpc.service and rpc.method. The same
* information is also available as Span Name -
* https://github.com/open-telemetry/opentelemetry-specification/blob/3e380e249f60c3a5f68746f5e84d10195ba41a79/specification/trace/semantic_conventions/rpc.md#span-name
* So, as part of this method, we will form Url using rpc.service and rpc.method, and
* fallback to spanName. While setting GRPC protocol from rpc attributes, it already checks
* for rpc.system.
*/
return RpcSemanticConventionUtils.getRpcPath(event).orElse(event.getEventName());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,57 @@ public void test_getRequestUrl_grpcProctol_shouldReturnEventName() {
spanEventViewGenerator.getRequestUrl(event, Protocol.PROTOCOL_GRPC));
}

@Test
public void test_getRequestUrl_grpcProctol_shouldReturnRpcServiceAndMethod() {
Event event = mock(Event.class);
when(event.getAttributes())
.thenReturn(
Attributes.newBuilder()
.setAttributeMap(
Map.of(
"rpc.service",
AttributeValue.newBuilder().setValue("hipstershop.AdService").build(),
"rpc.method",
AttributeValue.newBuilder().setValue("GetEcho").build()))
.build());
when(event.getEventName()).thenReturn("Sent.hipstershop.AdService.GetAds");
assertEquals(
"hipstershop.AdService.GetEcho",
spanEventViewGenerator.getRequestUrl(event, Protocol.PROTOCOL_GRPC));
}

@Test
public void test_getRequestUrl_grpcProctol_shouldReturnEventNameIfOnlyRpcService() {
Event event = mock(Event.class);
when(event.getAttributes())
.thenReturn(
Attributes.newBuilder()
.setAttributeMap(
Map.of(
"rpc.service",
AttributeValue.newBuilder().setValue("hipstershop.AdService").build()))
.build());
when(event.getEventName()).thenReturn("Sent.hipstershop.AdService.GetAds");
assertEquals(
"Sent.hipstershop.AdService.GetAds",
spanEventViewGenerator.getRequestUrl(event, Protocol.PROTOCOL_GRPC));
}

@Test
public void test_getRequestUrl_grpcProctol_shouldReturnEventNameIfOnlyRpcMethod() {
Event event = mock(Event.class);
when(event.getAttributes())
.thenReturn(
Attributes.newBuilder()
.setAttributeMap(
Map.of("rpc.method", AttributeValue.newBuilder().setValue("GetEcho").build()))
.build());
when(event.getEventName()).thenReturn("Sent.hipstershop.AdService.GetAds");
assertEquals(
"Sent.hipstershop.AdService.GetAds",
spanEventViewGenerator.getRequestUrl(event, Protocol.PROTOCOL_GRPC));
}

@Test
public void testGetRequestUrl_fullUrlIsAbsent() {
Event event =
Expand Down