Search in sources :

Example 41 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class UserAgentSpanEnricherTest method badUserAgent.

@Test
public void badUserAgent() {
    String badUserAgent = "I am not a User Agent!";
    Event e = createMockEvent();
    when(e.getHttp()).thenReturn(Http.newBuilder().setRequest(Request.newBuilder().setHeaders(RequestHeaders.newBuilder().setUserAgent(badUserAgent).build()).setUserAgent(badUserAgent).build()).build());
    mockProtocol(e, Protocol.PROTOCOL_HTTP);
    addAttribute(e, RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), badUserAgent);
    addAttribute(e, RawSpanConstants.getValue(HTTP_USER_AGENT_REQUEST_HEADER), badUserAgent);
    enricher.enrichEvent(null, e);
    Map<String, AttributeValue> map = e.getEnrichedAttributes().getAttributeMap();
    assertEquals(7, map.size());
    assertEquals("unknown", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_NAME)).getValue());
    assertEquals("", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_BROWSER_VERSION)).getValue());
    assertEquals("", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_DEVICE_CATEGORY)).getValue());
    assertEquals("unknown", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_NAME)).getValue());
    assertEquals("", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_VERSION)).getValue());
    assertEquals("", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_BROWSER_VERSION)).getValue());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 42 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class UserAgentSpanEnricherTest method should_preferUserAgent_fromHeaders.

@Test
public void should_preferUserAgent_fromHeaders() {
    String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3)" + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
    Event e = createMockEvent();
    when(e.getHttp()).thenReturn(Http.newBuilder().setRequest(Request.newBuilder().setHeaders(RequestHeaders.newBuilder().setUserAgent(userAgent).build()).setUserAgent("I am not a User Agent!").build()).build());
    mockProtocol(e, Protocol.PROTOCOL_HTTP);
    addAttribute(e, RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), "I am not a User Agent!");
    addAttribute(e, RawSpanConstants.getValue(HTTP_USER_AGENT_REQUEST_HEADER), userAgent);
    enricher.enrichEvent(null, e);
    Map<String, AttributeValue> map = e.getEnrichedAttributes().getAttributeMap();
    assertEquals(7, map.size());
    assertEquals("Chrome", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_NAME)).getValue());
    assertEquals("Browser", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_TYPE)).getValue());
    assertEquals("Personal computer", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_DEVICE_CATEGORY)).getValue());
    assertEquals("OS X", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_NAME)).getValue());
    assertEquals("10.14.3", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_VERSION)).getValue());
    assertEquals("73.0.3683.103", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_BROWSER_VERSION)).getValue());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 43 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class UserAgentSpanEnricherTest method should_fallbackToUserAgent_fromRequest.

@Test
public void should_fallbackToUserAgent_fromRequest() {
    String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3)" + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
    Event e = createMockEvent();
    when(e.getHttp()).thenReturn(Http.newBuilder().setRequest(Request.newBuilder().setUserAgent(userAgent).build()).build());
    mockProtocol(e, Protocol.PROTOCOL_HTTP);
    addAttribute(e, RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), userAgent);
    enricher.enrichEvent(null, e);
    Map<String, AttributeValue> map = e.getEnrichedAttributes().getAttributeMap();
    assertEquals(7, map.size());
    assertEquals("Chrome", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_NAME)).getValue());
    assertEquals("Browser", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_TYPE)).getValue());
    assertEquals("Personal computer", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_DEVICE_CATEGORY)).getValue());
    assertEquals("OS X", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_NAME)).getValue());
    assertEquals("10.14.3", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_VERSION)).getValue());
    assertEquals("73.0.3683.103", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_BROWSER_VERSION)).getValue());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 44 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class CassandraBackendProviderTest method testBackendResolutionWithoutConnectionString.

@Test
public void testBackendResolutionWithoutConnectionString() {
    BackendInfo backendInfo = backendEntityEnricher.resolve(getCassandraOTelEvent(), structuredTrace, structuredTraceGraph).get();
    Entity entity = backendInfo.getEntity();
    Assertions.assertEquals("test:9000", entity.getEntityName());
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("select"), "BACKEND_DESTINATION", AttributeValueCreator.create("customer.orders")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 45 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class ElasticsearchBackendProviderTest method testBackendResolution.

@Test
public void testBackendResolution() {
    BackendInfo backendInfo = backendEntityEnricher.resolve(getElasticsearchEvent(), structuredTrace, structuredTraceGraph).get();
    Entity entity = backendInfo.getEntity();
    Assertions.assertEquals("test-index", entity.getEntityName());
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("GET"), "BACKEND_DESTINATION", AttributeValueCreator.create("test-index")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeValue (org.hypertrace.core.datamodel.AttributeValue)84 Test (org.junit.jupiter.api.Test)65 Event (org.hypertrace.core.datamodel.Event)53 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)24 Entity (org.hypertrace.entity.data.service.v1.Entity)22 HashMap (java.util.HashMap)19 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AvroBuilderCache.fastNewBuilder (org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 EventRef (org.hypertrace.core.datamodel.EventRef)3 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)3 Attributes (org.hypertrace.core.datamodel.Attributes)2 MetricValue (org.hypertrace.core.datamodel.MetricValue)2 RawSpan (org.hypertrace.core.datamodel.RawSpan)2 SpanEventView (org.hypertrace.viewgenerator.api.SpanEventView)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1