Search in sources :

Example 16 with AttributeValue

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

the class EndpointEnricherTest method getBigTrace.

protected StructuredTrace getBigTrace() {
    /*
     * The graph looks like
     *             0 (entry)
     *             |
     *             1 (intermediate)
     * ------------|-------------------
     *             2 (exit)
     */
    // 0th raw span
    Map<String, AttributeValue> entrySpan0Map = new HashMap<>();
    entrySpan0Map.put(EnrichedSpanConstants.getValue(Http.HTTP_REQUEST_URL), AttributeValue.newBuilder().setValue("http://someservice.ai/users/1/checkout").build());
    Map<String, AttributeValue> enrichedEntrySpan0Map = new HashMap<>();
    enrichedEntrySpan0Map.put(EnrichedSpanConstants.getValue(Api.API_BOUNDARY_TYPE), AttributeValue.newBuilder().setValue("ENTRY").build());
    enrichedEntrySpan0Map.put(EntityConstants.getValue(ServiceAttribute.SERVICE_ATTRIBUTE_ID), AttributeValue.newBuilder().setValue(SERVICE_ID).build());
    enrichedEntrySpan0Map.put(EntityConstants.getValue(ServiceAttribute.SERVICE_ATTRIBUTE_NAME), AttributeValue.newBuilder().setValue(SERVICE_NAME).build());
    enrichedEntrySpan0Map.put(EntityConstants.getValue(ApiAttribute.API_ATTRIBUTE_ID), AttributeValue.newBuilder().setValue(API_ID).build());
    enrichedEntrySpan0Map.put(EntityConstants.getValue(ApiAttribute.API_ATTRIBUTE_URL_PATTERN), AttributeValue.newBuilder().setValue(API_PATTERN_VAL).build());
    enrichedEntrySpan0Map.put(EntityConstants.getValue(ApiAttribute.API_ATTRIBUTE_NAME), AttributeValue.newBuilder().setValue(API_NAME_VAL).build());
    Event event0 = Event.newBuilder().setCustomerId(TENANT_ID).setAttributes(Attributes.newBuilder().setAttributeMap(entrySpan0Map).build()).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(enrichedEntrySpan0Map).build()).setEventId(createByteBuffer("event0")).setEventName(API_PATTERN_VAL).build();
    RawSpan rawSpan0 = RawSpan.newBuilder().setCustomerId(TENANT_ID).setEvent(event0).setTraceId(createByteBuffer("trace")).build();
    // 1st intermediate raw span
    EventRef eventRef0 = EventRef.newBuilder().setRefType(EventRefType.CHILD_OF).setTraceId(createByteBuffer("trace")).setEventId(createByteBuffer("event0")).build();
    Map<String, AttributeValue> exitSpanMap = new HashMap<>();
    Map<String, AttributeValue> enrichedExitSpanMap = new HashMap<>();
    Event event1 = Event.newBuilder().setCustomerId(TENANT_ID).setEventId(createByteBuffer("event1")).setAttributes(Attributes.newBuilder().setAttributeMap(exitSpanMap).build()).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(enrichedExitSpanMap).build()).setEventRefList(Collections.singletonList(eventRef0)).build();
    RawSpan rawSpan1 = RawSpan.newBuilder().setCustomerId(TENANT_ID).setEvent(event1).setTraceId(createByteBuffer("trace")).build();
    // 2nd exit raw span
    EventRef eventRef1 = EventRef.newBuilder().setRefType(EventRefType.CHILD_OF).setTraceId(createByteBuffer("trace")).setEventId(createByteBuffer("event1")).build();
    Map<String, AttributeValue> entrySpan2Map = new HashMap<>();
    entrySpan2Map.put(EnrichedSpanConstants.getValue(Http.HTTP_REQUEST_URL), AttributeValue.newBuilder().setValue("http://nextservice.ai/login").build());
    Map<String, AttributeValue> enrichedEntrySpan2Map = new HashMap<>();
    enrichedEntrySpan2Map.put(EnrichedSpanConstants.getValue(Api.API_BOUNDARY_TYPE), AttributeValue.newBuilder().setValue("EXIT").build());
    Event event2 = Event.newBuilder().setCustomerId(TENANT_ID).setAttributes(Attributes.newBuilder().setAttributeMap(entrySpan2Map).build()).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(enrichedEntrySpan2Map).build()).setEventId(createByteBuffer("event2")).setEventRefList(Collections.singletonList(eventRef1)).build();
    RawSpan rawSpan2 = RawSpan.newBuilder().setCustomerId(TENANT_ID).setEvent(event2).setTraceId(createByteBuffer("trace")).build();
    return StructuredTraceBuilder.buildStructuredTraceFromRawSpans(List.of(rawSpan0, rawSpan1, rawSpan2), createByteBuffer("trace"), TENANT_ID);
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) EventRef(org.hypertrace.core.datamodel.EventRef) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) RawSpan(org.hypertrace.core.datamodel.RawSpan)

Example 17 with AttributeValue

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

the class SpanTypeAttributeEnricherTest method multipleAttributesExistsPrecedence.

@Test
public void multipleAttributesExistsPrecedence() {
    SpanTypeAttributeEnricher enricher = new SpanTypeAttributeEnricher();
    // span.kind takes precedence
    Event e = createMockEvent();
    when(e.getEventName()).thenReturn("Sent./api/10");
    addAttribute(e, SPAN_KIND_KEY, SERVER_VALUE);
    enricher.enrichEvent(null, e);
    Map<String, AttributeValue> enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(ENTRY));
    // Then Client
    e = createMockEvent();
    addAttribute(e, CLIENT_KEY, "false");
    when(e.getEventName()).thenReturn("Sent./api/10");
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(ENTRY));
    // Finally span name convention
    e = createMockEvent();
    when(e.getEventName()).thenReturn("Sent./api/10");
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(EXIT));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 18 with AttributeValue

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

the class SpanTypeAttributeEnricherTest method clientExists.

@Test
public void clientExists() {
    SpanTypeAttributeEnricher enricher = new SpanTypeAttributeEnricher();
    Event e = createMockEvent();
    addAttribute(e, CLIENT_KEY, "false");
    enricher.enrichEvent(null, e);
    Map<String, AttributeValue> enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(ENTRY));
    e = createMockEvent();
    addAttribute(e, CLIENT_KEY, "true");
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(EXIT));
    e = createMockEvent();
    addAttribute(e, CLIENT_KEY, "unknown");
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(UNKNOWN));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 19 with AttributeValue

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

the class SpanTypeAttributeEnricherTest method test_getProtocolName_HttpFromFullUrl_shouldReturnHttp.

@Test
public void test_getProtocolName_HttpFromFullUrl_shouldReturnHttp() {
    Map<String, AttributeValue> map = new HashMap<>();
    map.put(Constants.getRawSpanConstant(Http.HTTP_METHOD), AttributeValue.newBuilder().setValue("GET").build());
    Event e = createEvent(map, new HashMap<>());
    e.setHttp(org.hypertrace.core.datamodel.eventfields.http.Http.newBuilder().setRequest(Request.newBuilder().setUrl("http://hypertrace.org").build()).build());
    Assertions.assertEquals(Protocol.PROTOCOL_HTTP, SpanTypeAttributeEnricher.getProtocolName(e));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 20 with AttributeValue

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

the class UserAgentSpanEnricherTest method enrichFromUserAgent.

@Test
public void enrichFromUserAgent() {
    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(userAgent).build()).build());
    mockProtocol(e, Protocol.PROTOCOL_HTTP);
    addAttribute(e, RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), userAgent);
    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)

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