123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- import {ReactNode} from 'react';
- import {Tooltip} from 'sentry/components/tooltip';
- import {
- IconCursorArrow,
- IconFire,
- IconFix,
- IconInfo,
- IconInput,
- IconKeyDown,
- IconLocation,
- IconSort,
- IconTerminal,
- IconUser,
- IconWarning,
- } from 'sentry/icons';
- import {t, tct} from 'sentry/locale';
- import {TabKey} from 'sentry/utils/replays/hooks/useActiveReplayTab';
- import type {
- BreadcrumbFrame,
- ErrorFrame,
- LargestContentfulPaintFrame,
- MultiClickFrame,
- MutationFrame,
- NavFrame,
- ReplayFrame,
- SlowClickFrame,
- } from 'sentry/utils/replays/types';
- import {
- getFrameOpOrCategory,
- isDeadClick,
- isDeadRageClick,
- isRageClick,
- } from 'sentry/utils/replays/types';
- import type {Color} from 'sentry/utils/theme';
- import stripOrigin from 'sentry/utils/url/stripOrigin';
- interface Details {
- color: Color;
- description: ReactNode;
- icon: ReactNode;
- tabKey: TabKey;
- title: ReactNode;
- }
- const MAPPER_FOR_FRAME: Record<string, (frame) => Details> = {
- 'replay.init': (frame: BreadcrumbFrame) => ({
- color: 'gray300',
- description: stripOrigin(frame.message ?? ''),
- tabKey: TabKey.CONSOLE,
- title: 'Replay Start',
- icon: <IconTerminal size="xs" />,
- }),
- navigation: (frame: NavFrame) => ({
- color: 'green300',
- description: stripOrigin((frame as NavFrame).data.to),
- tabKey: TabKey.NETWORK,
- title: 'Navigation',
- icon: <IconLocation size="xs" />,
- }),
- issue: (frame: ErrorFrame) => ({
- color: 'red300',
- description: frame.message,
- tabKey: TabKey.ERRORS,
- title: defaultTitle(frame),
- icon: <IconFire size="xs" />,
- }),
- 'ui.slowClickDetected': (frame: SlowClickFrame) => {
- const node = frame.data.node;
- if (isDeadClick(frame)) {
- return {
- color: isDeadRageClick(frame) ? 'red300' : 'yellow300',
- description: tct(
- 'Click on [selector] did not cause a visible effect within [timeout] ms',
- {
- selector: stringifyNodeAttributes(node),
- timeout: Math.round(frame.data.timeAfterClickMs),
- }
- ),
- icon: <IconCursorArrow size="xs" />,
- title: isDeadRageClick(frame) ? 'Rage Click' : 'Dead Click',
- tabKey: TabKey.DOM,
- };
- }
- return {
- color: 'yellow300',
- description: tct(
- 'Click on [selector] took [duration] ms to have a visible effect',
- {
- selector: stringifyNodeAttributes(node),
- duration: Math.round(frame.data.timeAfterClickMs),
- }
- ),
- icon: <IconWarning size="xs" />,
- title: 'Slow Click',
- tabKey: TabKey.DOM,
- };
- },
- 'ui.multiClick': (frame: MultiClickFrame) => {
- if (isRageClick(frame)) {
- return {
- color: 'red300',
- description: tct('Rage clicked [clickCount] times on [selector]', {
- clickCount: frame.data.clickCount,
- selector: stringifyNodeAttributes(frame.data.node),
- }),
- tabKey: TabKey.DOM,
- title: 'Rage Click',
- icon: <IconFire size="xs" />,
- };
- }
- return {
- color: 'yellow300',
- description: tct('[clickCount] clicks on [selector]', {
- clickCount: frame.data.clickCount,
- selector: stringifyNodeAttributes(frame.data.node),
- }),
- tabKey: TabKey.DOM,
- title: 'Multi Click',
- icon: <IconWarning size="xs" />,
- };
- },
- 'replay.mutations': (frame: MutationFrame) => ({
- color: 'yellow300',
- description: frame.data.limit
- ? t(
- 'A large number of mutations was detected (%s). Replay is now stopped to prevent poor performance for your customer.',
- frame.data.count
- )
- : t(
- 'A large number of mutations was detected (%s). This can slow down the Replay SDK and impact your customers.',
- frame.data.count
- ),
- tabKey: TabKey.DOM,
- title: 'Replay',
- icon: <IconWarning size="xs" />,
- }),
- 'ui.click': frame => ({
- color: 'purple300',
- description: frame.message ?? '',
- tabKey: TabKey.DOM,
- title: 'User Click',
- icon: <IconCursorArrow size="xs" />,
- }),
- 'ui.input': () => ({
- color: 'purple300',
- description: 'User Action',
- tabKey: TabKey.DOM,
- title: 'User Input',
- icon: <IconInput size="xs" />,
- }),
- 'ui.keyDown': () => ({
- color: 'purple300',
- description: 'User Action',
- tabKey: TabKey.DOM,
- title: 'User KeyDown',
- icon: <IconKeyDown size="xs" />,
- }),
- 'ui.blur': () => ({
- color: 'purple300',
- description: 'User Action',
- tabKey: TabKey.DOM,
- title: 'User Blur',
- icon: <IconUser size="xs" />,
- }),
- 'ui.focus': () => ({
- color: 'purple300',
- description: 'User Action',
- tabKey: TabKey.DOM,
- title: 'User Focus',
- icon: <IconUser size="xs" />,
- }),
- console: frame => ({
- color: 'gray300',
- description: frame.message ?? '',
- tabKey: TabKey.CONSOLE,
- title: 'Console',
- icon: <IconFix size="xs" />,
- }),
- 'navigation.navigate': frame => ({
- color: 'green300',
- description: stripOrigin(frame.description),
- tabKey: TabKey.NETWORK,
- title: 'Page Load',
- icon: <IconLocation size="xs" />,
- }),
- 'navigation.reload': frame => ({
- color: 'green300',
- description: stripOrigin(frame.description),
- tabKey: TabKey.NETWORK,
- title: 'Reload',
- icon: <IconLocation size="xs" />,
- }),
- 'navigation.back_forward': frame => ({
- color: 'green300',
- description: stripOrigin(frame.description),
- tabKey: TabKey.NETWORK,
- title: 'Navigate Back/Forward',
- icon: <IconLocation size="xs" />,
- }),
- 'navigation.push': frame => ({
- color: 'green300',
- description: stripOrigin(frame.description),
- tabKey: TabKey.NETWORK,
- title: 'Navigation',
- icon: <IconLocation size="xs" />,
- }),
- 'largest-contentful-paint': (frame: LargestContentfulPaintFrame) => ({
- color: 'gray300',
- description:
- typeof frame.data.value === 'number' ? (
- `${Math.round(frame.data.value)}ms`
- ) : (
- <Tooltip
- title={t(
- 'This replay uses a SDK version that is subject to inaccurate LCP values. Please upgrade to the latest version for best results if you have not already done so.'
- )}
- >
- <IconWarning />
- </Tooltip>
- ),
- tabKey: TabKey.NETWORK,
- title: 'LCP',
- icon: <IconInfo size="xs" />,
- }),
- memory: () => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.MEMORY,
- title: 'Memory',
- icon: <IconInfo size="xs" />,
- }),
- paint: () => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.NETWORK,
- title: 'Paint',
- icon: <IconInfo size="xs" />,
- }),
- 'resource.css': frame => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.NETWORK,
- title: frame.description,
- icon: <IconSort size="xs" rotated />,
- }),
- 'resource.fetch': frame => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.NETWORK,
- title: frame.description,
- icon: <IconSort size="xs" rotated />,
- }),
- 'resource.iframe': frame => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.NETWORK,
- title: frame.description,
- icon: <IconSort size="xs" rotated />,
- }),
- 'resource.img': frame => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.NETWORK,
- title: frame.description,
- icon: <IconSort size="xs" rotated />,
- }),
- 'resource.link': frame => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.NETWORK,
- title: frame.description,
- icon: <IconSort size="xs" rotated />,
- }),
- 'resource.other': frame => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.NETWORK,
- title: frame.description,
- icon: <IconSort size="xs" rotated />,
- }),
- 'resource.script': frame => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.NETWORK,
- title: frame.description,
- icon: <IconSort size="xs" rotated />,
- }),
- 'resource.xhr': frame => ({
- color: 'gray300',
- description: undefined,
- tabKey: TabKey.NETWORK,
- title: frame.description,
- icon: <IconSort size="xs" rotated />,
- }),
- };
- const MAPPER_DEFAULT = (frame): Details => ({
- color: 'gray300',
- description: frame.message ?? '',
- tabKey: TabKey.CONSOLE,
- title: defaultTitle(frame),
- icon: <IconTerminal size="xs" />,
- });
- export default function getFrameDetails(frame: ReplayFrame): Details {
- const key = getFrameOpOrCategory(frame);
- const fn = MAPPER_FOR_FRAME[key] ?? MAPPER_DEFAULT;
- try {
- return fn(frame);
- } catch (error) {
- return MAPPER_DEFAULT(frame);
- }
- }
- function defaultTitle(frame: ReplayFrame) {
- if ('category' in frame) {
- const [type, action] = frame.category.split('.');
- return `${type} ${action || ''}`.trim();
- }
- if ('message' in frame) {
- return frame.message as string; // TODO(replay): Included for backwards compat
- }
- return frame.description ?? '';
- }
- function stringifyNodeAttributes(node: SlowClickFrame['data']['node']) {
- const {tagName, attributes} = node ?? {};
- const attributesEntries = Object.entries(attributes ?? {});
- return `${tagName}${
- attributesEntries.length
- ? attributesEntries.map(([attr, val]) => `[${attr}="${val}"]`).join('')
- : ''
- }`;
- }
|