Skip to content

Commit

Permalink
PR comment - Comment getTraceSpanIdsAsTree()
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffon committed Aug 22, 2017
1 parent d16097b commit bdd6d7e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/selectors/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down

0 comments on commit bdd6d7e

Please sign in to comment.