Search in sources :

Example 81 with Event

use of org.hypertrace.core.datamodel.Event 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 82 with Event

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

the class EndpointEnricherTest method createMockEvent.

private Event createMockEvent() {
    Event e = mock(Event.class);
    when(e.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(new HashMap<>()).build());
    when(e.getEnrichedAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(new HashMap<>()).build());
    return e;
}
Also used : Event(org.hypertrace.core.datamodel.Event)

Example 83 with Event

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

the class SpanTypeAttributeEnricherTest method noAttributes.

@Test
public void noAttributes() {
    SpanTypeAttributeEnricher enricher = new SpanTypeAttributeEnricher();
    Event e = mock(Event.class);
    when(e.getAttributes()).thenReturn(null);
    enricher.enrichEvent(null, e);
    when(e.getAttributes()).thenReturn(new Attributes());
    enricher.enrichEvent(null, e);
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 84 with Event

use of org.hypertrace.core.datamodel.Event 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 85 with Event

use of org.hypertrace.core.datamodel.Event 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)

Aggregations

Event (org.hypertrace.core.datamodel.Event)304 Test (org.junit.jupiter.api.Test)257 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)54 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)54 Attributes (org.hypertrace.core.datamodel.Attributes)41 Entity (org.hypertrace.entity.data.service.v1.Entity)27 HashMap (java.util.HashMap)25 AbstractAttributeEnricherTest (org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)17 ByteBuffer (java.nio.ByteBuffer)13 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)13 StructuredTraceGraph (org.hypertrace.core.datamodel.shared.StructuredTraceGraph)12 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AttributeMetadata (org.hypertrace.core.attribute.service.v1.AttributeMetadata)10 SemanticConventionTestUtil.buildAttributes (org.hypertrace.semantic.convention.utils.SemanticConventionTestUtil.buildAttributes)8 Edge (org.hypertrace.core.datamodel.Edge)7 Entity (org.hypertrace.core.datamodel.Entity)7 HashSet (java.util.HashSet)6 List (java.util.List)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5