Skip to content

Commit

Permalink
feat: add forming grpc reqeuest url if rpc attributes are present (#280)
Browse files Browse the repository at this point in the history
* feat: add forming grpc reqeust url if rpc attributes are present

* nit: minor fix on comment
  • Loading branch information
kotharironak authored Nov 8, 2021
1 parent ece2263 commit 30f0a7b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
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

0 comments on commit 30f0a7b

Please sign in to comment.