Skip to content

fix(replay): Remove duplicate nav events from the Replay>Breadcrumbs list #69057

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

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Changes from 1 commit
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
60 changes: 46 additions & 14 deletions static/app/utils/replays/replayReader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ function removeDuplicateClicks(frames: BreadcrumbFrame[]) {
return uniqueClickFrames.concat(otherFrames).concat(slowClickFrames);
}

// If a `navigation` crumb and `navigation.*` span happen within this timeframe,
// we'll consider them duplicates.
const DUPLICATE_NAV_THRESHOLD_MS = 2;

/**
* Return a list of BreadcrumbFrames, where any navigation crumb is removed if
* there is a matching navigation.* span to replace it.
*
* SpanFrame is preferred because they render with more specific titles.
*/
function removeDuplicateNavCrumbs(
crumbFrames: BreadcrumbFrame[],
spanFrames: SpanFrame[]
) {
const navCrumbs = crumbFrames.filter(crumb => crumb.category === 'navigation');
const otherBreadcrumbFrames = crumbFrames.filter(
crumb => crumb.category !== 'navigation'
);

const navSpans = spanFrames.filter(span => span.op.startsWith('navigation.'));

const uniqueNavCrumbs = navCrumbs.filter(
crumb =>
!navSpans.some(
span => Math.abs(crumb.offsetMs - span.offsetMs) <= DUPLICATE_NAV_THRESHOLD_MS
)
);
return otherBreadcrumbFrames.concat(uniqueNavCrumbs);
}

export default class ReplayReader {
static factory({attachments, errors, replayRecord, clipWindow}: ReplayReaderParams) {
if (!attachments || !replayRecord || !errors) {
Expand Down Expand Up @@ -446,20 +476,22 @@ export default class ReplayReader {
)
);

getPerfFrames = memoize(() =>
[
...removeDuplicateClicks(
this._sortedBreadcrumbFrames.filter(
frame =>
['navigation', 'ui.click'].includes(frame.category) ||
(frame.category === 'ui.slowClickDetected' &&
(isDeadClick(frame as SlowClickFrame) ||
isDeadRageClick(frame as SlowClickFrame)))
)
),
...this._sortedSpanFrames.filter(frame => frame.op.startsWith('navigation.')),
].sort(sortFrames)
);
getPerfFrames = memoize(() => {
const crumbs = removeDuplicateClicks(
this._sortedBreadcrumbFrames.filter(
frame =>
['navigation', 'ui.click'].includes(frame.category) ||
(frame.category === 'ui.slowClickDetected' &&
(isDeadClick(frame as SlowClickFrame) ||
isDeadRageClick(frame as SlowClickFrame)))
)
);
const spans = this._sortedSpanFrames.filter(frame =>
frame.op.startsWith('navigation.')
);
const uniqueCrumbs = removeDuplicateNavCrumbs(crumbs, spans);
return [...uniqueCrumbs, ...spans].sort(sortFrames);
});

getLPCFrames = memoize(() => this._sortedSpanFrames.filter(isLCPFrame));

Expand Down
Loading