Search in sources :

Example 41 with Attributes

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());
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 42 with Attributes

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());
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 43 with Attributes

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());
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 44 with Attributes

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());
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 45 with Attributes

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());
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Aggregations

Attributes (org.hypertrace.core.datamodel.Attributes)45 Event (org.hypertrace.core.datamodel.Event)41 Test (org.junit.jupiter.api.Test)40 SemanticConventionTestUtil.buildAttributes (org.hypertrace.semantic.convention.utils.SemanticConventionTestUtil.buildAttributes)8 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)3 HashMap (java.util.HashMap)2 AvroBuilderCache.fastNewBuilder (org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1 JaegerSpanInternalModel (io.jaegertracing.api_v2.JaegerSpanInternalModel)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Nullable (javax.annotation.Nullable)1 Schema (org.apache.avro.Schema)1