use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class RpcSemanticConventionUtilsTest method testGetGrpcAuthority.
@Test
public void testGetGrpcAuthority() {
Event e = mock(Event.class);
Attributes attributes = buildAttributes(Map.of("rpc.system", "grpc", "grpc.authority", "some-service:56003"));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = RpcSemanticConventionUtils.getSanitizedGrpcAuthority(e);
assertEquals("some-service:56003", v.get());
attributes = buildAttributes(Map.of(RPC_REQUEST_METADATA_AUTHORITY.getValue(), "some-service:56003", "rpc.system", "grpc", "grpc.authority", "other-service:56003"));
when(e.getAttributes()).thenReturn(attributes);
v = RpcSemanticConventionUtils.getSanitizedGrpcAuthority(e);
assertEquals("some-service:56003", v.get());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class RpcSemanticConventionUtilsTest method getGrpcURI.
@Test
void getGrpcURI() {
Event e = mock(Event.class);
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(RawSpanConstants.getValue(Grpc.GRPC_HOST_PORT), SemanticConventionTestUtil.buildAttributeValue("webhost:9011")));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = RpcSemanticConventionUtils.getGrpcURI(e);
assertEquals("webhost:9011", v.get());
attributes = SemanticConventionTestUtil.buildAttributes(Map.of("span.kind", SemanticConventionTestUtil.buildAttributeValue("client")));
when(e.getAttributes()).thenReturn(attributes);
v = RpcSemanticConventionUtils.getGrpcURI(e);
assertTrue(v.isEmpty());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class RpcSemanticConventionUtilsTest method testGetRpcDestination.
@Test
public void testGetRpcDestination() {
Event e = mock(Event.class);
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelRpcSemanticConventions.RPC_SYSTEM_SERVICE.getValue(), SemanticConventionTestUtil.buildAttributeValue("testService")));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = RpcSemanticConventionUtils.getRpcService(e);
assertEquals("testService", v.get());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class RpcSemanticConventionUtilsTest method testGetGrpcURI.
@Test
public void testGetGrpcURI() {
Event e = mock(Event.class);
// grpc_host_port is preferred
Attributes attributes = buildAttributes(Map.of(RawSpanConstants.getValue(Grpc.GRPC_HOST_PORT), "webhost:9011", "grpc.authority", "some-service:56003", "rpc.system", "grpc", OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), "otel-host"));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = RpcSemanticConventionUtils.getGrpcURL(e);
assertEquals("webhost:9011", v.get());
// no relevant attributes
attributes = buildAttributes(Map.of("span.kind", "client"));
when(e.getAttributes()).thenReturn(attributes);
v = RpcSemanticConventionUtils.getGrpcURL(e);
assertTrue(v.isEmpty());
// grpc authority is used
attributes = buildAttributes(Map.of("rpc.system", "grpc", OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), "otel-host", "grpc.authority", "some-service:56003"));
when(e.getAttributes()).thenReturn(attributes);
v = RpcSemanticConventionUtils.getGrpcURL(e);
assertEquals("some-service:56003", v.get());
// rpc.system is not present but grpc authority is present
attributes = buildAttributes(Map.of("grpc.authority", "some-service:56003"));
when(e.getAttributes()).thenReturn(attributes);
v = RpcSemanticConventionUtils.getGrpcURL(e);
assertEquals("some-service:56003", v.get());
// grpc authority is used
attributes = buildAttributes(Map.of(RPC_REQUEST_METADATA_AUTHORITY.getValue(), "some-service:56003", "rpc.system", "grpc", OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), "otel-host"));
when(e.getAttributes()).thenReturn(attributes);
v = RpcSemanticConventionUtils.getGrpcURL(e);
assertEquals("some-service:56003", v.get());
// rpc.system is not present but grpc authority is present
attributes = buildAttributes(Map.of("rpc.system", "grpc", RPC_REQUEST_METADATA_AUTHORITY.getValue(), "some-service:56003"));
when(e.getAttributes()).thenReturn(attributes);
v = RpcSemanticConventionUtils.getGrpcURL(e);
assertEquals("some-service:56003", v.get());
// otel host name is used
attributes = buildAttributes(Map.of("rpc.system", "grpc", OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), "otel-host"));
when(e.getAttributes()).thenReturn(attributes);
v = RpcSemanticConventionUtils.getGrpcURL(e);
assertEquals("otel-host", v.get());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class RpcSemanticConventionUtilsTest method testGetGrpcRequestEndpoint.
@Test
public void testGetGrpcRequestEndpoint() {
Event e = mock(Event.class);
// case 1: event name starts with Sent. prefix
Attributes attributes = buildAttributes(Map.of("rpc.request.metadata.:path", "/TestGrpcService/getRpcMetadataPathEcho"));
when(e.getAttributes()).thenReturn(attributes);
when(e.getEventName()).thenReturn("Sent.TestService.getEventEchos");
assertEquals("TestService.getEventEchos", RpcSemanticConventionUtils.getGrpcRequestEndpoint(e).get());
// case 2: event name starts with Sent. prefix
attributes = buildAttributes(Map.of("rpc.request.metadata.:path", "/TestGrpcService/getRpcMetadataPathEcho"));
when(e.getAttributes()).thenReturn(attributes);
when(e.getEventName()).thenReturn("Recv.TestService.getEventEchos");
assertEquals("TestService.getEventEchos", RpcSemanticConventionUtils.getGrpcRequestEndpoint(e).get());
// case 3: attributes map is empty, fallback to event name
attributes = buildAttributes(Map.of());
when(e.getAttributes()).thenReturn(attributes);
when(e.getEventName()).thenReturn("TestService.getEventEchos");
assertEquals("TestService.getEventEchos", RpcSemanticConventionUtils.getGrpcRequestEndpoint(e).get());
// case 4: event name doesn't start with req prefix, and rpc.system = grpc,
// uses rpc.request.metadata.:path
attributes = buildAttributes(Map.of("rpc.request.metadata.:path", "/TestGrpcService/getRpcRequestMetadataPathEcho", "rpc.service", "TestRpcService", "rpc.method", "getRpcMethodEcho", "http.request.header.:path", "/TestHttpGrpcService/getHttpRequestHeaderPathEcho", "grpc.path", "/TestGrpcService/getGrpcPathEcho"));
when(e.getAttributes()).thenReturn(attributes);
when(e.getEventName()).thenReturn("TestService.getEventEchos");
assertEquals("TestGrpcService.getRpcRequestMetadataPathEcho", RpcSemanticConventionUtils.getGrpcRequestEndpoint(e).get());
// case 5: event name doesn't start with req prefix, and rpc.system = grpc,
// uses rpc.service and rpc.method
attributes = buildAttributes(Map.of("rpc.service", "TestRpcService", "rpc.method", "getRpcMethodEcho", "http.request.header.:path", "/TestHttpGrpcService/getHttpRequestHeaderPathEcho", "grpc.path", "/TestGrpcService/getGrpcPathEcho"));
when(e.getAttributes()).thenReturn(attributes);
when(e.getEventName()).thenReturn("TestService.getEventEchos");
assertEquals("TestRpcService.getRpcMethodEcho", RpcSemanticConventionUtils.getGrpcRequestEndpoint(e).get());
// case 6: event name doesn't start with req prefix, and rpc.system = grpc,
// uses http.request.header.:path
attributes = buildAttributes(Map.of("http.request.header.:path", "/TestHttpGrpcService/getHttpRequestHeaderPathEcho", "grpc.path", "/TestGrpcService/getGrpcPathEcho"));
when(e.getAttributes()).thenReturn(attributes);
when(e.getEventName()).thenReturn("TestService.getEventEchos");
assertEquals("TestHttpGrpcService.getHttpRequestHeaderPathEcho", RpcSemanticConventionUtils.getGrpcRequestEndpoint(e).get());
// case 7: event name doesn't start with req prefix, and rpc.system = grpc,
// uses grpc.path
attributes = buildAttributes(Map.of("grpc.path", "/TestGrpcService/getGrpcPathEcho"));
when(e.getAttributes()).thenReturn(attributes);
when(e.getEventName()).thenReturn("TestService.getEventEchos");
assertEquals("TestGrpcService.getGrpcPathEcho", RpcSemanticConventionUtils.getGrpcRequestEndpoint(e).get());
// case 7: event name doesn't start with req prefix, and rpc.system = grpc,
// but all fallback attributes are missing, uses eventName
attributes = buildAttributes(Map.of());
when(e.getAttributes()).thenReturn(attributes);
when(e.getEventName()).thenReturn("TestService.getEventEchos");
assertEquals("TestService.getEventEchos", RpcSemanticConventionUtils.getGrpcRequestEndpoint(e).get());
}
Aggregations