From bdd6d7e8a7287bcddb3c09a16122cc9c59c16a16 Mon Sep 17 00:00:00 2001 From: Joe Farro Date: Tue, 22 Aug 2017 12:25:39 -0400 Subject: [PATCH] PR comment - Comment getTraceSpanIdsAsTree() https://github.com/uber/jaeger-ui/pull/53#discussion_r134321990 --- src/selectors/trace.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/selectors/trace.js b/src/selectors/trace.js index 50efd3a7e4..5588e79a0f 100644 --- a/src/selectors/trace.js +++ b/src/selectors/trace.js @@ -54,6 +54,20 @@ export const getTraceSpansAsMap = createSelector(getTraceSpans, spans => export const TREE_ROOT_ID = '__root__'; +/** + * Build a tree of { value: spanID, children } items derived from the + * `span.references` information. The tree represents the grouping of parent / + * child relationships. The root-most node is nominal in that + * `.value === TREE_ROOT_ID`. This is done because a root span (the main trace + * span) is not always included with the trace data. Thus, there can be + * multiple top-level spans, and the root node acts as their common parent. + * + * The children are sorted by `span.startTime` after the tree is built. + * + * @param {Trace} trace The trace to build the tree of spanIDs. + * @return {TreeNode} A tree of spanIDs derived from the relationships + * between spans in the trace. + */ export function getTraceSpanIdsAsTree(trace) { const nodesById = new Map(trace.spans.map(span => [span.spanID, new TreeNode(span.spanID)])); const spansById = new Map(trace.spans.map(span => [span.spanID, span]));