Skip to content

Commit 3769e72

Browse files
Abdkhan14Abdullah Khan
authored andcommitted
feat(trace-eap-waterfall): Updating eap transaction re-parenting logic (#87529)
As we reparent the eap-transactions being rendered under a collapsed eap-transaction node, during expansion, we only need to target the direct eap-transaction children of that node. Consider this trace data: `txn 1` -- span 1 ----- `txn 2` ------ span 2 -------- `txn 3` Step 1: Initially the trace is loaded as `txn 1` -- `txn 2` ----- `txn 3` Step 2: Expanding txn 1 should render `txn 1` -- span 1 ---- `txn 2` ------ `txn 3` Step 3: Collapsing txn 1 should render `txn 1` -- `txn 2` ----- `txn 3` Without the changes in this PR, Step 3 would render the wrong hierarchy below: `txn 1` -- `txn 2` -- `txn 3` --------- Co-authored-by: Abdullah Khan <[email protected]>
1 parent 950918b commit 3769e72

File tree

3 files changed

+64
-54
lines changed

3 files changed

+64
-54
lines changed

static/app/views/performance/newTraceDetails/traceModels/__snapshots__/traceTree.spec.tsx.snap

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,31 @@ eap trace root
6969
"
7070
`;
7171

72-
exports[`TraceTree eap trace correctly renders eap-transactions collapsed state 1`] = `
72+
exports[`TraceTree eap trace correctly renders eap-transactions toggle state 1`] = `
7373
"
7474
eap trace root
7575
span.op - span.description (eap-transaction)
7676
span.op - span.description (eap-transaction)
77+
span.op - span.description (eap-transaction)
7778
"
7879
`;
7980

80-
exports[`TraceTree eap trace correctly renders eap-transactions expanded state 1`] = `
81+
exports[`TraceTree eap trace correctly renders eap-transactions toggle state 2`] = `
8182
"
8283
eap trace root
8384
span.op - span.description (eap-transaction)
8485
span.op - span.description
8586
span.op - span.description (eap-transaction)
87+
span.op - span.description (eap-transaction)
88+
"
89+
`;
90+
91+
exports[`TraceTree eap trace correctly renders eap-transactions toggle state 3`] = `
92+
"
93+
eap trace root
94+
span.op - span.description (eap-transaction)
95+
span.op - span.description (eap-transaction)
96+
span.op - span.description (eap-transaction)
8697
"
8798
`;
8899

static/app/views/performance/newTraceDetails/traceModels/traceTree.spec.tsx

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,14 @@ describe('TraceTree', () => {
534534
expect(findEAPSpanByEventId(tree, 'eap-span-2')?.expanded).toBe(true);
535535
});
536536

537-
it('correctly renders eap-transactions collapsed state', () => {
537+
it('correctly renders eap-transactions toggle state', () => {
538538
const tree = TraceTree.FromTrace(
539539
makeEAPTrace([
540540
makeEAPSpan({
541541
event_id: 'eap-span-1',
542542
start_timestamp: start,
543543
end_timestamp: start + 2,
544-
is_transaction: true,
544+
is_transaction: true, // is a transaction
545545
parent_span_id: undefined,
546546
children: [
547547
makeEAPSpan({
@@ -555,9 +555,27 @@ describe('TraceTree', () => {
555555
event_id: 'eap-span-3',
556556
start_timestamp: start + 2,
557557
end_timestamp: start + 3,
558-
is_transaction: true,
558+
is_transaction: true, // is a transaction
559559
parent_span_id: 'eap-span-2',
560-
children: [],
560+
children: [
561+
makeEAPSpan({
562+
event_id: 'eap-span-4',
563+
start_timestamp: start + 3,
564+
end_timestamp: start + 4,
565+
is_transaction: false,
566+
parent_span_id: 'eap-span-3',
567+
children: [
568+
makeEAPSpan({
569+
event_id: 'eap-span-5',
570+
start_timestamp: start + 4,
571+
end_timestamp: start + 5,
572+
is_transaction: true, // is a transaction
573+
parent_span_id: 'eap-span-4',
574+
children: [],
575+
}),
576+
],
577+
}),
578+
],
561579
}),
562580
],
563581
}),
@@ -566,45 +584,17 @@ describe('TraceTree', () => {
566584
]),
567585
traceMetadata
568586
);
569-
expect(tree.build().serialize()).toMatchSnapshot();
570-
});
571587

572-
it('correctly renders eap-transactions expanded state', () => {
573-
const tree = TraceTree.FromTrace(
574-
makeEAPTrace([
575-
makeEAPSpan({
576-
event_id: 'eap-span-1',
577-
start_timestamp: start,
578-
end_timestamp: start + 2,
579-
is_transaction: true,
580-
parent_span_id: undefined,
581-
children: [
582-
makeEAPSpan({
583-
event_id: 'eap-span-2',
584-
start_timestamp: start + 1,
585-
end_timestamp: start + 4,
586-
is_transaction: false,
587-
parent_span_id: 'eap-span-1',
588-
children: [
589-
makeEAPSpan({
590-
event_id: 'eap-span-3',
591-
start_timestamp: start + 2,
592-
end_timestamp: start + 3,
593-
is_transaction: true,
594-
parent_span_id: 'eap-span-2',
595-
children: [],
596-
}),
597-
],
598-
}),
599-
],
600-
}),
601-
]),
602-
traceMetadata
603-
);
588+
// Assert initial state
589+
expect(tree.build().serialize()).toMatchSnapshot();
604590

591+
// Assert expaneded state
605592
const eapTxn = findEAPSpanByEventId(tree, 'eap-span-1');
606593
tree.expand(eapTxn!, true);
594+
expect(tree.build().serialize()).toMatchSnapshot();
607595

596+
// Assert state upon collapsing
597+
tree.expand(eapTxn!, false);
608598
expect(tree.build().serialize()).toMatchSnapshot();
609599
});
610600
});

static/app/views/performance/newTraceDetails/traceModels/traceTree.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,13 @@ export class TraceTree extends TraceTreeEventDispatcher {
356356

357357
parentNode.children.push(node);
358358

359+
// Since we are reparenting EAP transactions at this stage, we need to sort the children
360+
if (isEAPTransactionNode(node)) {
361+
parentNode.children.sort(traceChronologicalSort);
362+
}
363+
359364
if (node.value && 'children' in node.value) {
360-
// EAP spans are not sorted by default
361-
const children = node.value.children.sort(
362-
(a, b) => a.start_timestamp - b.start_timestamp
363-
);
364-
for (const child of children) {
365+
for (const child of node.value.children) {
365366
visit(node, child);
366367
}
367368
}
@@ -1380,15 +1381,15 @@ export class TraceTree extends TraceTreeEventDispatcher {
13801381

13811382
static ReparentEAPTransactions(
13821383
node: TraceTreeNode<TraceTree.EAPSpan>,
1384+
findEAPTransactions: (
1385+
n: TraceTreeNode<TraceTree.EAPSpan>
1386+
) => Array<TraceTreeNode<TraceTree.EAPSpan>>,
13831387
findNewParent: (
13841388
t: TraceTreeNode<TraceTree.EAPSpan>
13851389
) => TraceTreeNode<TraceTree.NodeValue> | null
13861390
): void {
13871391
// Find all embedded eap-transactions, excluding the node itself
1388-
const eapTransactions = TraceTree.FindAll(
1389-
node,
1390-
n => isEAPTransactionNode(n) && n !== node
1391-
);
1392+
const eapTransactions = findEAPTransactions(node);
13921393

13931394
for (const t of eapTransactions) {
13941395
if (isEAPTransactionNode(t)) {
@@ -1469,10 +1470,13 @@ export class TraceTree extends TraceTreeEventDispatcher {
14691470
node.expanded = expanded;
14701471

14711472
// When eap-transaction nodes are expanded, we need to reparent the transactions under
1472-
// the eap-spans (by their parent_span_id) that were previously hidden.
1473+
// the eap-spans (by their parent_span_id) that were previously hidden. Note that this only impacts the
1474+
// direct eap-transaction children of the targetted eap-transaction node.
14731475
if (isEAPTransactionNode(node)) {
1474-
TraceTree.ReparentEAPTransactions(node, t =>
1475-
TraceTree.FindByID(node, t.value.parent_span_id)
1476+
TraceTree.ReparentEAPTransactions(
1477+
node,
1478+
t => t.children.filter(c => isEAPTransactionNode(c)),
1479+
t => TraceTree.FindByID(node, t.value.parent_span_id)
14761480
);
14771481
}
14781482

@@ -1489,8 +1493,13 @@ export class TraceTree extends TraceTreeEventDispatcher {
14891493
// Reparent the transactions from under the eap-spans in the expanded state, to under the closest eap-transaction
14901494
// in the collapsed state.
14911495
if (isEAPTransactionNode(node)) {
1492-
TraceTree.ReparentEAPTransactions(node, t =>
1493-
TraceTree.ParentEAPTransaction(t.parent)
1496+
TraceTree.ReparentEAPTransactions(
1497+
node,
1498+
t =>
1499+
TraceTree.FindAll(t, n => isEAPTransactionNode(n) && n !== t) as Array<
1500+
TraceTreeNode<TraceTree.EAPSpan>
1501+
>,
1502+
t => TraceTree.ParentEAPTransaction(t)
14941503
);
14951504
}
14961505

0 commit comments

Comments
 (0)