Skip to content

Commit

Permalink
Process FOLLOWS_FROM spans in TraceView (#335)
Browse files Browse the repository at this point in the history
* Process FOLLOWS_FROM spans in TraceView

Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>

* Add test for FOLLOWS_FROM span relation for SpanTreeOffset

Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
  • Loading branch information
rubenvp8510 authored and tiffon committed Mar 7, 2019
1 parent 75a7069 commit caf91a7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import cx from 'classnames';
import _get from 'lodash/get';
import _find from 'lodash/find';
import React from 'react';
import IoChevronRight from 'react-icons/lib/io/chevron-right';
import IoIosArrowDown from 'react-icons/lib/io/ios-arrow-down';
Expand Down Expand Up @@ -54,14 +53,7 @@ export class UnconnectedSpanTreeOffset extends React.PureComponent<SpanTreeOffse
super(props);

this.ancestorIds = [];
let currentSpan: Span = props.span;
while (currentSpan) {
currentSpan = _get(_find(currentSpan.references, { refType: 'CHILD_OF' }), 'span');
if (currentSpan) {
this.ancestorIds.push(currentSpan.spanID);
}
}

this.computeAncestors(props.span);
// Some traces have multiple root-level spans, this connects them all under one guideline and adds the
// necessary padding for the collapse icon on root-level spans.
this.ancestorIds.push('root');
Expand Down Expand Up @@ -106,6 +98,19 @@ export class UnconnectedSpanTreeOffset extends React.PureComponent<SpanTreeOffse
}
};

computeAncestors(rootSpan: Span) {
let currentSpan: Span = rootSpan;
while (currentSpan && Array.isArray(currentSpan.references) && currentSpan.references.length) {
const { refType, span } = currentSpan.references[0] || {};
if (span && (refType === 'FOLLOWS_FROM' || refType === 'CHILD_OF')) {
this.ancestorIds.push(span.spanID);
currentSpan = span;
} else {
break;
}
}
}

render() {
const { showChildrenIcon, childrenVisible, onClick, span } = this.props;
const { hasChildren, spanID } = span;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('SpanTreeOffset', () => {
],
spanID: ownSpanID,
};

const specialRootID = 'root';
let props;
let wrapper;
Expand Down Expand Up @@ -77,6 +78,35 @@ describe('SpanTreeOffset', () => {
expect(indentGuides.prop('data-ancestor-id')).toBe(specialRootID);
});

it('renders one .SpanTreeOffset--indentGuide per ancestor span, plus one for entire trace, including FOLLOWS_FROM', () => {
props.span = {
hasChildren: false,
references: [
{
refType: 'FOLLOWS_FROM',
span: {
spanID: parentSpanID,
references: [
{
refType: 'CHILD_OF',
span: {
spanID: rootSpanID,
},
},
],
},
},
],
spanID: ownSpanID,
};
wrapper = shallow(<UnconnectedSpanTreeOffset {...props} />);
const indentGuides = wrapper.find('.SpanTreeOffset--indentGuide');
expect(indentGuides.length).toBe(3);
expect(indentGuides.at(0).prop('data-ancestor-id')).toBe(specialRootID);
expect(indentGuides.at(1).prop('data-ancestor-id')).toBe(rootSpanID);
expect(indentGuides.at(2).prop('data-ancestor-id')).toBe(parentSpanID);
});

it('renders one .SpanTreeOffset--indentGuide per ancestor span, plus one for entire trace', () => {
const indentGuides = wrapper.find('.SpanTreeOffset--indentGuide');
expect(indentGuides.length).toBe(3);
Expand Down

0 comments on commit caf91a7

Please sign in to comment.