Skip to content

Commit 64ca9a6

Browse files
authored
fix(waterfall): Relax "next_trace" lookup to just the trace id (#104047)
For the "Next Trace" button, we'd previously, search for spans matching the exact trace and span id of the current trace root span. However, in some cases, the product considers another span the trace root span than our SDK. An example is a web vital (INP) span, which happened slightly before the navigation span started but was only added by the SDK retroactively. In the product, we consider the web vital span the trace root, while in the SDK we assigned the previous_trace span link to the navigation span. To still correctly find the next trace span, this PR now relaxes the search criteria for the next trace, to search for a span with the `previous_trace` attribute containing the current trace's traceId, but _any_ spanId. This works well as long as there's only one `previous_trace` span link per trace. If there are multiple, we'd take the first one, which also isn't the end of the world. However, in the SDK, we make sure to only set the link once per trace. => I think this works well enough. h/t @bcoe for the "contains" idea 🙏
1 parent 105f121 commit 64ca9a6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

static/app/views/performance/newTraceDetails/traceLinksNavigation/useFindLinkedTraces.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export function useFindAdjacentTrace({
3030
projectId,
3131
environment,
3232
currentTraceId,
33-
currentSpanId,
3433
adjacentTraceId,
3534
adjacentTraceSpanId,
3635
hasAdjacentTraceLink,
@@ -39,7 +38,6 @@ export function useFindAdjacentTrace({
3938
let _projectId: number | undefined = undefined;
4039
let _environment: string | undefined = undefined;
4140
let _currentTraceId: string | undefined;
42-
let _currentSpanId: string | undefined;
4341
let _adjacentTraceAttribute: TraceItemResponseAttribute | undefined = undefined;
4442

4543
for (const a of attributes ?? []) {
@@ -49,8 +47,6 @@ export function useFindAdjacentTrace({
4947
_environment = a.value;
5048
} else if (a.name === 'trace' && a.type === 'str') {
5149
_currentTraceId = a.value;
52-
} else if (a.name === 'transaction.span_id' && a.type === 'str') {
53-
_currentSpanId = a.value;
5450
} else if (a.name === 'previous_trace' && a.type === 'str') {
5551
_adjacentTraceAttribute = a;
5652
}
@@ -74,7 +70,6 @@ export function useFindAdjacentTrace({
7470
projectId: _projectId,
7571
environment: _environment,
7672
currentTraceId: _currentTraceId,
77-
currentSpanId: _currentSpanId,
7873
hasAdjacentTraceLink: _hasAdjacentTraceLink,
7974
adjacentTraceSampled: _adjacentTraceSampledFlag === '1',
8075
adjacentTraceId: _adjacentTraceId,
@@ -84,7 +79,12 @@ export function useFindAdjacentTrace({
8479

8580
const searchQuery =
8681
direction === 'next'
87-
? `sentry.previous_trace:${currentTraceId}-${currentSpanId}-1`
82+
? // relaxed the next trace lookup to match spans containing only the
83+
// traceId and not the spanId of the current trace root. We can't
84+
// always be sure that the current trace root is indeed the span the
85+
// next span would link towards, because sometimes the root might be a web
86+
// vital span instead of the actual intial span from the SDK's perspective.
87+
`sentry.previous_trace:${currentTraceId}-*-1`
8888
: `id:${adjacentTraceSpanId} trace:${adjacentTraceId}`;
8989

9090
const enabled =

0 commit comments

Comments
 (0)