Skip to content
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

fix(replay): CLS score is not in ms #77397

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
} from 'sentry/utils/replays/types';
import {
isBreadcrumbFrame,
isCLSFrame,
isErrorFrame,
isFeedbackFrame,
isHydrationErrorFrame,
Expand Down Expand Up @@ -237,11 +238,7 @@ function WebVitalData({
const selectors = frameToExtraction?.get(frame)?.selectors;

const webVitalData = {value: frame.data.value};
if (
frame.description === 'cumulative-layout-shift' &&
frame.data.attributions &&
selectors
) {
if (isCLSFrame(frame) && frame.data.attributions && selectors) {
const layoutShifts: {[x: string]: ReactNode[]}[] = [];
for (const attr of frame.data.attributions) {
const elements: ReactNode[] = [];
Expand Down
10 changes: 7 additions & 3 deletions static/app/utils/replays/getFrameDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type {
} from 'sentry/utils/replays/types';
import {
getFrameOpOrCategory,
isCLSFrame,
isDeadClick,
isDeadRageClick,
isRageClick,
Expand Down Expand Up @@ -286,8 +287,9 @@ const MAPPER_FOR_FRAME: Record<string, (frame) => Details> = {
case 'good':
return {
color: 'green300',
description: tct('[value]ms (Good)', {
description: tct('[value][unit] (Good)', {
value: frame.data.value.toFixed(2),
unit: isCLSFrame(frame) ? '' : 'ms',
}),
tabKey: TabKey.NETWORK,
title: 'Web Vital: ' + toTitleCase(explodeSlug(frame.description)),
Expand All @@ -296,8 +298,9 @@ const MAPPER_FOR_FRAME: Record<string, (frame) => Details> = {
case 'needs-improvement':
return {
color: 'yellow300',
description: tct('[value]ms (Meh)', {
description: tct('[value][unit] (Meh)', {
value: frame.data.value.toFixed(2),
unit: isCLSFrame(frame) ? '' : 'ms',
}),
tabKey: TabKey.NETWORK,
title: 'Web Vital: ' + toTitleCase(explodeSlug(frame.description)),
Expand All @@ -306,8 +309,9 @@ const MAPPER_FOR_FRAME: Record<string, (frame) => Details> = {
default:
return {
color: 'red300',
description: tct('[value]ms (Poor)', {
description: tct('[value][unit] (Poor)', {
value: frame.data.value.toFixed(2),
unit: isCLSFrame(frame) ? '' : 'ms',
}),
tabKey: TabKey.NETWORK,
title: 'Web Vital: ' + toTitleCase(explodeSlug(frame.description)),
Expand Down
11 changes: 6 additions & 5 deletions static/app/utils/replays/replayReader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
EventType,
getNodeIds,
IncrementalSource,
isCLSFrame,
isDeadClick,
isDeadRageClick,
isPaintFrame,
Expand Down Expand Up @@ -637,12 +638,12 @@ export default class ReplayReader {
let lastTimestamp = 0;
const groupedCls: WebVitalFrame[] = [];

for (const cls of allWebVitals) {
if (cls.description === 'cumulative-layout-shift') {
if (lastTimestamp === cls.timestampMs) {
groupedCls.push(cls);
for (const frame of allWebVitals) {
if (isCLSFrame(frame)) {
if (lastTimestamp === frame.timestampMs) {
groupedCls.push(frame);
} else {
lastTimestamp = cls.timestampMs;
lastTimestamp = frame.timestampMs;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions static/app/utils/replays/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export function isWebVitalFrame(frame: SpanFrame): frame is WebVitalFrame {
return frame.op === 'web-vital';
}

export function isCLSFrame(frame: WebVitalFrame): frame is WebVitalFrame {
return frame.description === 'cumulative-layout-shift';
}

export function isPaintFrame(frame: SpanFrame): frame is PaintFrame {
return frame.op === 'paint';
}
Expand Down
Loading