123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- import type {ReactNode} from 'react';
- import {Fragment} from 'react';
- import FeatureBadge from 'sentry/components/featureBadge';
- import ExternalLink from 'sentry/components/links/externalLink';
- import {Tooltip} from 'sentry/components/tooltip';
- import {
- IconCursorArrow,
- IconFire,
- IconFix,
- IconInfo,
- IconInput,
- IconKeyDown,
- IconLocation,
- IconMegaphone,
- 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,
- FeedbackFrame,
- 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 stripURLOrigin from 'sentry/utils/url/stripURLOrigin';
- 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: stripURLOrigin(frame.message ?? ''),
- tabKey: TabKey.CONSOLE,
- title: 'Replay Start',
- icon: <IconTerminal size="xs" />,
- }),
- navigation: (frame: NavFrame) => ({
- color: 'green300',
- description: stripURLOrigin((frame as NavFrame).data.to),
- tabKey: TabKey.NETWORK,
- title: 'Navigation',
- icon: <IconLocation size="xs" />,
- }),
- feedback: (frame: FeedbackFrame) => ({
- color: 'pink300',
- description: frame.data.projectSlug,
- tabKey: TabKey.BREADCRUMBS,
- title: defaultTitle(frame),
- icon: <IconMegaphone 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.BREADCRUMBS,
- };
- }
- 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.BREADCRUMBS,
- };
- },
- '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.BREADCRUMBS,
- 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.BREADCRUMBS,
- title: 'Multi Click',
- icon: <IconWarning size="xs" />,
- };
- },
- 'replay.mutations': (frame: MutationFrame) => ({
- color: 'yellow300',
- description: frame.data.limit
- ? tct(
- 'A large number of mutations was detected [count]. Replay is now stopped to prevent poor performance for your customer. [link]',
- {
- count: frame.data.count,
- link: (
- <ExternalLink href="https://docs.sentry.io/platforms/javascript/session-replay/configuration/#mutation-limits">
- {t('Learn more.')}
- </ExternalLink>
- ),
- }
- )
- : tct(
- 'A large number of mutations was detected [count]. This can slow down the Replay SDK and impact your customers. [link]',
- {
- count: frame.data.count,
- link: (
- <ExternalLink href="https://docs.sentry.io/platforms/javascript/session-replay/configuration/#mutation-limits">
- {t('Learn more.')}
- </ExternalLink>
- ),
- }
- ),
- tabKey: TabKey.BREADCRUMBS,
- title: 'Replay',
- icon: <IconWarning size="xs" />,
- }),
- 'replay.hydrate-error': () => ({
- color: 'red300',
- description: t(
- 'There was a conflict between the server rendered html and the first client render.'
- ),
- tabKey: TabKey.BREADCRUMBS,
- title: (
- <Fragment>
- Hydration Error <FeatureBadge type="beta" />
- </Fragment>
- ),
- icon: <IconFire size="xs" />,
- }),
- 'ui.click': frame => ({
- color: 'blue300',
- description: frame.message ?? '',
- tabKey: TabKey.BREADCRUMBS,
- title: 'User Click',
- icon: <IconCursorArrow size="xs" />,
- }),
- 'ui.input': () => ({
- color: 'blue300',
- description: 'User Action',
- tabKey: TabKey.BREADCRUMBS,
- title: 'User Input',
- icon: <IconInput size="xs" />,
- }),
- 'ui.keyDown': () => ({
- color: 'blue300',
- description: 'User Action',
- tabKey: TabKey.BREADCRUMBS,
- title: 'User KeyDown',
- icon: <IconKeyDown size="xs" />,
- }),
- 'ui.blur': () => ({
- color: 'blue300',
- description: 'User Action',
- tabKey: TabKey.BREADCRUMBS,
- title: 'User Blur',
- icon: <IconUser size="xs" />,
- }),
- 'ui.focus': () => ({
- color: 'blue300',
- description: 'User Action',
- tabKey: TabKey.BREADCRUMBS,
- 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: stripURLOrigin(frame.description),
- tabKey: TabKey.NETWORK,
- title: 'Page Load',
- icon: <IconLocation size="xs" />,
- }),
- 'navigation.reload': frame => ({
- color: 'green300',
- description: stripURLOrigin(frame.description),
- tabKey: TabKey.NETWORK,
- title: 'Reload',
- icon: <IconLocation size="xs" />,
- }),
- 'navigation.back_forward': frame => ({
- color: 'green300',
- description: stripURLOrigin(frame.description),
- tabKey: TabKey.NETWORK,
- title: 'Navigate Back/Forward',
- icon: <IconLocation size="xs" />,
- }),
- 'navigation.push': frame => ({
- color: 'green300',
- description: stripURLOrigin(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) {
- // Override title for User Feedback frames
- if ('message' in frame && frame.message === 'User Feedback') {
- return t('User Feedback');
- }
- 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('')
- : ''
- }`;
- }
|