From 0e38323ff295309eff5bfa6f42b0b51c8e4227e6 Mon Sep 17 00:00:00 2001 From: JonasBa Date: Wed, 27 Nov 2024 07:32:33 -0500 Subject: [PATCH] fix(trace) match event_id by error --- .../traceModels/traceTree.spec.tsx | 33 ++++++++++++++ .../newTraceDetails/traceModels/traceTree.tsx | 44 +++++++++++++------ 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/static/app/views/performance/newTraceDetails/traceModels/traceTree.spec.tsx b/static/app/views/performance/newTraceDetails/traceModels/traceTree.spec.tsx index 496f493a9c1707..82f4cab10a6ea4 100644 --- a/static/app/views/performance/newTraceDetails/traceModels/traceTree.spec.tsx +++ b/static/app/views/performance/newTraceDetails/traceModels/traceTree.spec.tsx @@ -15,6 +15,7 @@ import { import type {ParentAutogroupNode} from './parentAutogroupNode'; import {TraceTree} from './traceTree'; import { + assertTransactionNode, makeEventTransaction, makeSpan, makeTrace, @@ -993,6 +994,38 @@ describe('TraceTree', () => { }); }); + describe('FindByID', () => { + it('finds transaction by event_id', () => { + const traceWithError = makeTrace({ + transactions: [ + makeTransaction({transaction: 'first', event_id: 'first-event-id'}), + ], + }); + const tree = TraceTree.FromTrace(traceWithError, traceMetadata); + const node = TraceTree.FindByID(tree.root, 'first-event-id'); + + assertTransactionNode(node); + expect(node.value.transaction).toBe('first'); + }); + + it('matches by error event_id', () => { + const traceWithError = makeTrace({ + transactions: [ + makeTransaction({ + transaction: 'first', + event_id: 'txn-event-id', + errors: [makeTraceError({event_id: 'error-event-id'})], + }), + ], + }); + const tree = TraceTree.FromTrace(traceWithError, traceMetadata); + const node = TraceTree.FindByID(tree.root, 'error-event-id'); + + assertTransactionNode(node); + expect(node.value.transaction).toBe('first'); + }); + }); + describe('FindAll', () => { it('finds all nodes by predicate', () => { const tree = TraceTree.FromTrace(trace, traceMetadata); diff --git a/static/app/views/performance/newTraceDetails/traceModels/traceTree.tsx b/static/app/views/performance/newTraceDetails/traceModels/traceTree.tsx index f4a9084224fed3..cda92934f8dd7a 100644 --- a/static/app/views/performance/newTraceDetails/traceModels/traceTree.tsx +++ b/static/app/views/performance/newTraceDetails/traceModels/traceTree.tsx @@ -1222,10 +1222,38 @@ export class TraceTree extends TraceTreeEventDispatcher { if (isTransactionNode(n)) { // A transaction itself is a span and we are starting to treat it as such. // Hence we check for both event_id and span_id. - return n.value.event_id === eventId || n.value.span_id === eventId; + if (n.value.event_id === eventId || n.value.span_id === eventId) { + return true; + } + + // If we dont have an exact match, then look for an event_id in the errors or performance issues + for (const e of n.errors) { + if (e.event_id === eventId) { + return true; + } + } + for (const p of n.performance_issues) { + if (p.event_id === eventId) { + return true; + } + } } if (isSpanNode(n)) { - return n.value.span_id === eventId; + if (n.value.span_id === eventId) { + return true; + } + + // If we dont have an exact match, then look for an event_id in the errors or performance issues + for (const e of n.errors) { + if (e.event_id === eventId) { + return true; + } + } + for (const p of n.performance_issues) { + if (p.event_id === eventId) { + return true; + } + } } if (isTraceErrorNode(n)) { return n.value.event_id === eventId; @@ -1255,18 +1283,6 @@ export class TraceTree extends TraceTreeEventDispatcher { return true; } - // If we dont have an exact match, then look for an event_id in the errors or performance issues - for (const e of n.errors) { - if (e.event_id === eventId) { - return true; - } - } - for (const p of n.performance_issues) { - if (p.event_id === eventId) { - return true; - } - } - return false; }); }