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);
}
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;
}
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);
}
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));
}
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));
}
Aggregations