use of org.hypertrace.core.datamodel.shared.HexUtils in project hypertrace-ingester by hypertrace.
the class ApiTraceGraph method buildApiNodes.
/**
* The idea is to filter out the events in an API boundary. The ApiNode will contain a head event
* for the API Trace, a list of events that fall within the API boundary, the Entry event or null
* if the head span is not an entry span and a list of exit events from the API.
*/
private void buildApiNodes(StructuredTraceGraph graph) {
Set<ByteBuffer> remainingEventIds = new HashSet<>(graph.getEventMap().keySet());
for (Event event : trace.getEventList()) {
if (EnrichedSpanUtils.isEntryApiBoundary(event)) {
// create new ApiNode from the events in the api boundary
ApiNode<Event> apiNode = buildApiNode(graph, event);
apiNodeList.add(apiNode);
// Remove the events in ApiNode from remainingEventIds
apiNode.getEvents().forEach(e -> {
remainingEventIds.remove(e.getEventId());
});
}
}
if (!remainingEventIds.isEmpty()) {
// Process all the roots which aren't processed yet.
for (Event event : graph.getRootEvents()) {
if (!remainingEventIds.contains(event.getEventId())) {
continue;
}
// TODO: What if the root is an internal span?
if (EnrichedSpanUtils.isExitSpan(event)) {
// Get all the spans that should be included in this ApiNode and create new node.
ApiNode<Event> apiNode = buildApiNode(graph, event);
// We expect all events to be present in the remaining events here.
Set<ByteBuffer> newEventIds = apiNode.getEvents().stream().map(Event::getEventId).collect(Collectors.toSet());
Set<ByteBuffer> additionalEvents = Sets.difference(newEventIds, remainingEventIds);
if (!additionalEvents.isEmpty()) {
LOGGER.warn("Unexpected spans are included in ApiNode; additionalSpans: {}", additionalEvents.stream().map(HexUtils::getHex).collect(Collectors.toSet()));
}
apiNodeList.add(apiNode);
apiNode.getEvents().forEach(e -> remainingEventIds.remove(e.getEventId()));
} else if (!StringUtils.equals(EnrichedSpanUtils.getSpanType(event), UNKNOWN_SPAN_KIND_VALUE)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Non exit root span wasn't picked for ApiNode; traceId: {}, spanId: {}, spanName: {}, serviceName: {}", HexUtils.getHex(trace.getTraceId()), HexUtils.getHex(event.getEventId()), event.getEventName(), event.getServiceName());
}
}
}
}
if (!remainingEventIds.isEmpty() && LOGGER.isDebugEnabled()) {
LOGGER.debug("Not all spans from trace are included in ApiNodes; traceId: {}, spanIds: {}", HexUtils.getHex(trace.getTraceId()), remainingEventIds.stream().map(HexUtils::getHex).collect(Collectors.toSet()));
}
}
Aggregations