Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process FOLLOWS_FROM spans in TraceView #335

Merged
merged 4 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}

rubenvp8510 marked this conversation as resolved.
Show resolved Hide resolved
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