Skip to content

Commit 18b5898

Browse files
Abdkhan14Abdullah Khan
andauthored
feat(trace-eap-waterfall): Using spans count from tree (#95806)
For EAP traces, there is a mismatch between spans count in `/trace` vs `/trace-meta`. The prior is accurate so we are resorting to it for now. Will stack a PR, to capture a sentry event for when the mismatch occurs. --------- Co-authored-by: Abdullah Khan <abdullahkhan@PG9Y57YDXQ.local>
1 parent cefe0e4 commit 18b5898

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

static/app/views/performance/newTraceDetails/traceHeader/meta.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {RepresentativeTraceEvent} from 'sentry/views/performance/newTraceDe
1313
import {TraceDrawerComponents} from 'sentry/views/performance/newTraceDetails/traceDrawer/details/styles';
1414
import {
1515
isEAPError,
16+
isEAPTraceNode,
1617
isTraceError,
1718
} from 'sentry/views/performance/newTraceDetails/traceGuards';
1819
import type {TraceTree} from 'sentry/views/performance/newTraceDetails/traceModels/traceTree';
@@ -71,7 +72,7 @@ function getRootDuration(event: TraceTree.TraceEvent | null) {
7172
}
7273

7374
export function Meta(props: MetaProps) {
74-
const traceNode = props.tree.root.children[0]!;
75+
const traceNode = props.tree.root.children[0];
7576
const {timestamp} = useTraceQueryParams();
7677

7778
const uniqueErrorIssues = useMemo(() => {
@@ -112,14 +113,22 @@ export function Meta(props: MetaProps) {
112113
return unique;
113114
}, [traceNode]);
114115

116+
if (!traceNode) {
117+
return null;
118+
}
119+
120+
const spansCount = isEAPTraceNode(traceNode)
121+
? props.tree.eap_spans_count
122+
: (props.meta?.span_count ?? 0);
123+
115124
const uniqueIssuesCount = uniqueErrorIssues.length + uniquePerformanceIssues.length;
116125

117126
// If there is no trace data, use the timestamp from the query params as an approximation for
118127
// the age of the trace.
119128
const ageStartTimestamp =
120129
traceNode?.space[0] ?? (timestamp ? timestamp * 1000 : undefined);
121130

122-
const hasSpans = (props.meta?.span_count ?? 0) > 0;
131+
const hasSpans = spansCount > 0;
123132
const hasLogs = (props.logs?.length ?? 0) > 0;
124133

125134
return (
@@ -138,9 +147,7 @@ export function Meta(props: MetaProps) {
138147
)
139148
}
140149
/>
141-
{hasSpans ? (
142-
<MetaSection headingText={t('Spans')} bodyText={props.meta?.span_count} />
143-
) : null}
150+
{hasSpans ? <MetaSection headingText={t('Spans')} bodyText={spansCount} /> : null}
144151
{ageStartTimestamp ? (
145152
<MetaSection
146153
headingText={t('Age')}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ function fetchTrace(
335335

336336
export class TraceTree extends TraceTreeEventDispatcher {
337337
transactions_count = 0;
338+
eap_spans_count = 0;
338339
projects = new Map<number, TraceTree.Project>();
339340

340341
type: 'loading' | 'empty' | 'error' | 'trace' = 'trace';
@@ -445,6 +446,10 @@ export class TraceTree extends TraceTreeEventDispatcher {
445446
tree.transactions_count++;
446447
}
447448

449+
if (isEAPSpanNode(node)) {
450+
tree.eap_spans_count++;
451+
}
452+
448453
if (isTransactionNode(node)) {
449454
const spanChildrenCount =
450455
options.meta?.transaction_child_count_map[node.value.event_id];

static/app/views/performance/newTraceDetails/traceWaterfall.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,21 @@ export function TraceWaterfall(props: TraceWaterfallProps) {
524524
action_source: 'load',
525525
});
526526
});
527+
528+
// TODO Abdullah Khan: Remove this once /trace-meta/ starts responding
529+
// with the correct spans count for EAP traces.
530+
if (
531+
traceNode &&
532+
isEAPTraceNode(traceNode) &&
533+
props.tree.eap_spans_count !== props.meta?.data?.span_count
534+
) {
535+
Sentry.withScope(scope => {
536+
scope.setFingerprint(['trace-eap-spans-count-mismatch']);
537+
scope.captureMessage(
538+
'EAP spans count from /trace/ and /trace-meta/ are not equal'
539+
);
540+
});
541+
}
527542
}, [
528543
setRowAsFocused,
529544
traceDispatch,
@@ -535,6 +550,7 @@ export function TraceWaterfall(props: TraceWaterfallProps) {
535550
props.organization,
536551
isLoadingSubscriptionDetails,
537552
hasExceededPerformanceUsageLimit,
553+
props.meta?.data?.span_count,
538554
source,
539555
timestamp,
540556
]);

static/app/views/performance/newTraceDetails/useTraceOnLoad.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {IssuesTraceTree} from 'sentry/views/performance/newTraceDetails/traceMod
1212
import {TraceTree} from './traceModels/traceTree';
1313
import type {TracePreferencesState} from './traceState/tracePreferences';
1414
import {useTraceState} from './traceState/traceStateProvider';
15-
import {isEAPTransactionNode, isTransactionNode} from './traceGuards';
15+
import {isEAPTraceNode, isEAPTransactionNode, isTransactionNode} from './traceGuards';
1616
import type {TraceReducerState} from './traceState';
1717
import type {useTraceScrollToPath} from './useTraceScrollToPath';
1818

@@ -29,10 +29,20 @@ async function maybeAutoExpandTrace(
2929
},
3030
meta: TraceMetaQueryResults
3131
): Promise<TraceTree> {
32+
const traceNode = tree.root.children[0];
33+
34+
if (!traceNode) {
35+
return tree;
36+
}
37+
38+
const spansCount = isEAPTraceNode(traceNode)
39+
? tree.eap_spans_count
40+
: (meta.data?.span_count ?? 0);
41+
3242
if (
3343
!(
3444
tree.transactions_count < AUTO_EXPAND_TRANSACTIONS_THRESHOLD ||
35-
(meta.data?.span_count ?? 0) < AUTO_EXPAND_SPANS_THRESHOLD
45+
(spansCount ?? 0) < AUTO_EXPAND_SPANS_THRESHOLD
3646
)
3747
) {
3848
return tree;

0 commit comments

Comments
 (0)