use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.
the class DefaultServiceEntityEnricherTest method test_case1_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService.
@Test
public void test_case1_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService() {
// Case 1: sampleapp (entry) -> redis (exit)
Event parent = createEvent(TENANT_ID, "parent", Map.of("span.kind", "server"), Map.of("SPAN_TYPE", "ENTRY", "SERVICE_NAME", "sampleapp"), null, "sampleapp");
Event current = createEvent(TENANT_ID, "current", Map.of("span.kind", "client"), Map.of("SPAN_TYPE", "EXIT"), ByteBuffer.wrap("parent".getBytes()), "redis");
StructuredTraceGraph graph = mock(StructuredTraceGraph.class);
when(graph.getParentEvent(current)).thenReturn(parent);
String actual = enricher.findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService(current, "redis", graph).orElse(null);
String expected = "sampleapp";
assertEquals(expected, actual);
}
use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.
the class DefaultServiceEntityEnricherTest method test_case2_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService.
@Test
public void test_case2_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService() {
// Case 2: sampleapp (entry) -> sampleapp (exit)
Event parent = createEvent(TENANT_ID, "parent", Map.of("span.kind", "server"), Map.of("SPAN_TYPE", "ENTRY", "SERVICE_NAME", "sampleapp"), null, "sampleapp");
Event current = createEvent(TENANT_ID, "current", Map.of("span.kind", "client"), Map.of("SPAN_TYPE", "EXIT"), ByteBuffer.wrap("parent".getBytes()), "sampleapp");
StructuredTraceGraph graph = mock(StructuredTraceGraph.class);
when(graph.getParentEvent(current)).thenReturn(parent);
String actual = enricher.findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService(current, "sampleapp", graph).orElse(null);
String expected = null;
assertEquals(expected, actual);
}
use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.
the class DefaultServiceEntityEnricherTest method test_case3_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService.
@Test
public void test_case3_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService() {
// Case 3: sampleapp (entry) -> sampleapp (exit) -> redis (exit)
Event parent1 = createEvent(TENANT_ID, "parent1", Map.of("span.kind", "server"), Map.of(API_BOUNDARY_TYPE_ATTR, "ENTRY", "SERVICE_NAME", "sampleapp"), null, "sampleapp");
Event parent2 = createEvent(TENANT_ID, "parent2", Map.of("span.kind", "client"), Map.of(API_BOUNDARY_TYPE_ATTR, "EXIT", "SERVICE_NAME", "sampleapp"), ByteBuffer.wrap("parent1".getBytes()), "sampleapp");
Event current = createEvent(TENANT_ID, "current", Map.of("span.kind", "client"), Map.of(API_BOUNDARY_TYPE_ATTR, "EXIT"), ByteBuffer.wrap("parent2".getBytes()), "redis");
StructuredTraceGraph graph = mock(StructuredTraceGraph.class);
when(graph.getParentEvent(current)).thenReturn(parent2);
when(graph.getParentEvent(parent2)).thenReturn(parent1);
String actual = enricher.findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService(current, "redis", graph).orElse(null);
String expected = "sampleapp";
assertEquals(expected, actual);
}
use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.
the class DefaultServiceEntityEnricherTest method test_case4_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService.
@Test
public void test_case4_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService() {
// Case 4: sampleapp (entry) -> sampleapp (exit) -> sampleapp (exit)
Event parent1 = createEvent(TENANT_ID, "parent1", Map.of("span.kind", "server"), Map.of(API_BOUNDARY_TYPE_ATTR, "ENTRY", "SERVICE_NAME", "sampleapp"), null, "sampleapp");
Event parent2 = createEvent(TENANT_ID, "parent2", Map.of("span.kind", "client"), Map.of(API_BOUNDARY_TYPE_ATTR, "EXIT", "SERVICE_NAME", "sampleapp"), ByteBuffer.wrap("parent1".getBytes()), "sampleapp");
Event current = createEvent(TENANT_ID, "current", Map.of("span.kind", "client"), Map.of(API_BOUNDARY_TYPE_ATTR, "EXIT"), ByteBuffer.wrap("parent2".getBytes()), "sampleapp");
StructuredTraceGraph graph = mock(StructuredTraceGraph.class);
when(graph.getParentEvent(current)).thenReturn(parent2);
String actual = enricher.findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService(current, "sampleapp", graph).orElse(null);
String expected = null;
assertEquals(expected, actual);
}
use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.
the class ApiBoundaryTypeAttributeEnricher method enrichEvent.
@Override
public void enrichEvent(StructuredTrace trace, Event event) {
if (event.getEnrichedAttributes() == null) {
return;
}
Map<String, AttributeValue> attributeMap = event.getEnrichedAttributes().getAttributeMap();
if (attributeMap == null) {
return;
}
boolean isEntrySpan = EnrichedSpanUtils.isEntrySpan(event);
boolean isExitSpan = EnrichedSpanUtils.isExitSpan(event);
// does not need to build the full traversal graph, just get the parents mapping
StructuredTraceGraph graph = buildGraph(trace);
if (isEntrySpan) {
/*
Determines if this is entry span is an entry to api
1. If the event is an ENTRY span, and
2. If the direct parent span is either an EXIT Span or Null, or direct parent span service name differs from current span service name.
*/
Event parentEvent = graph.getParentEvent(event);
if (!EnrichedSpanUtils.isEntrySpan(parentEvent) || EnrichedSpanUtils.areBothSpansFromDifferentService(event, parentEvent)) {
addEnrichedAttribute(event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(ENTRY_BOUNDARY_TYPE));
// For all API entry spans, try to enrich with host header.
enrichHostHeader(event);
}
} else if (isExitSpan) {
/*
Determines if this is exit span is an exit to api
1. If the event is an EXIT span, and
2. If the direct child span is either an ENTRY Span or Null, then this is the exit point.
*/
List<Event> childrenEvents = graph.getChildrenEvents(event);
if (childrenEvents == null || childrenEvents.isEmpty()) {
addEnrichedAttribute(event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(EXIT_BOUNDARY_TYPE));
} else {
for (Event childEvent : childrenEvents) {
if (EnrichedSpanUtils.isEntrySpan(childEvent)) {
addEnrichedAttribute(event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(EXIT_BOUNDARY_TYPE));
break;
}
}
}
}
}
Aggregations