styles.tsx 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  1. import {Fragment, type PropsWithChildren, useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {LocationDescriptor} from 'history';
  4. import {Button, LinkButton} from 'sentry/components/button';
  5. import {CopyToClipboardButton} from 'sentry/components/copyToClipboardButton';
  6. import {
  7. DropdownMenu,
  8. type DropdownMenuProps,
  9. type MenuItemProps,
  10. } from 'sentry/components/dropdownMenu';
  11. import EventTagsDataSection from 'sentry/components/events/eventTagsAndScreenshot/tags';
  12. import {generateStats} from 'sentry/components/events/opsBreakdown';
  13. import {DataSection} from 'sentry/components/events/styles';
  14. import FileSize from 'sentry/components/fileSize';
  15. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  16. import KeyValueData, {
  17. CardPanel,
  18. type KeyValueDataContentProps,
  19. Subject,
  20. } from 'sentry/components/keyValueData';
  21. import {LazyRender, type LazyRenderProps} from 'sentry/components/lazyRender';
  22. import Link from 'sentry/components/links/link';
  23. import Panel from 'sentry/components/panels/panel';
  24. import PanelBody from 'sentry/components/panels/panelBody';
  25. import PanelHeader from 'sentry/components/panels/panelHeader';
  26. import {pickBarColor} from 'sentry/components/performance/waterfall/utils';
  27. import QuestionTooltip from 'sentry/components/questionTooltip';
  28. import {Tooltip} from 'sentry/components/tooltip';
  29. import {
  30. IconChevron,
  31. IconCircleFill,
  32. IconFocus,
  33. IconJson,
  34. IconOpen,
  35. IconPanel,
  36. IconProfiling,
  37. } from 'sentry/icons';
  38. import {t, tct} from 'sentry/locale';
  39. import {space} from 'sentry/styles/space';
  40. import type {Event, EventTransaction} from 'sentry/types/event';
  41. import type {KeyValueListData} from 'sentry/types/group';
  42. import type {Organization} from 'sentry/types/organization';
  43. import type {Project} from 'sentry/types/project';
  44. import {formatBytesBase10} from 'sentry/utils/bytes/formatBytesBase10';
  45. import getDuration from 'sentry/utils/duration/getDuration';
  46. import type {Color, ColorOrAlias} from 'sentry/utils/theme';
  47. import {useNavigate} from 'sentry/utils/useNavigate';
  48. import useOrganization from 'sentry/utils/useOrganization';
  49. import {useParams} from 'sentry/utils/useParams';
  50. import {traceAnalytics} from '../../traceAnalytics';
  51. import {useTransaction} from '../../traceApi/useTransaction';
  52. import {useDrawerContainerRef} from '../../traceDrawer/details/drawerContainerRefContext';
  53. import {
  54. makeTraceContinuousProfilingLink,
  55. makeTransactionProfilingLink,
  56. } from '../../traceDrawer/traceProfilingLink';
  57. import {
  58. isAutogroupedNode,
  59. isMissingInstrumentationNode,
  60. isRootNode,
  61. isSpanNode,
  62. isTraceErrorNode,
  63. isTransactionNode,
  64. } from '../../traceGuards';
  65. import type {MissingInstrumentationNode} from '../../traceModels/missingInstrumentationNode';
  66. import type {ParentAutogroupNode} from '../../traceModels/parentAutogroupNode';
  67. import type {SiblingAutogroupNode} from '../../traceModels/siblingAutogroupNode';
  68. import {TraceTree} from '../../traceModels/traceTree';
  69. import type {TraceTreeNode} from '../../traceModels/traceTreeNode';
  70. import {useTraceState, useTraceStateDispatch} from '../../traceState/traceStateProvider';
  71. import {useHasTraceNewUi} from '../../useHasTraceNewUi';
  72. const BodyContainer = styled('div')<{hasNewTraceUi?: boolean}>`
  73. display: flex;
  74. flex-direction: column;
  75. gap: ${p => (p.hasNewTraceUi ? 0 : space(2))};
  76. padding: ${p => (p.hasNewTraceUi ? `${space(0.5)} ${space(2)}` : space(1))};
  77. height: calc(100% - 52px);
  78. overflow: auto;
  79. ${DataSection} {
  80. padding: 0;
  81. }
  82. `;
  83. const DetailContainer = styled('div')`
  84. height: 100%;
  85. overflow: hidden;
  86. padding-bottom: ${space(1)};
  87. `;
  88. const FlexBox = styled('div')`
  89. display: flex;
  90. align-items: center;
  91. `;
  92. const Actions = styled(FlexBox)`
  93. gap: ${space(0.5)};
  94. justify-content: end;
  95. width: 100%;
  96. `;
  97. const Title = styled(FlexBox)`
  98. gap: ${space(1)};
  99. flex-grow: 1;
  100. overflow: hidden;
  101. > span {
  102. min-width: 30px;
  103. }
  104. `;
  105. const LegacyTitleText = styled('div')`
  106. ${p => p.theme.overflowEllipsis}
  107. `;
  108. const TitleText = styled('div')`
  109. font-size: ${p => p.theme.fontSizeExtraLarge};
  110. font-weight: bold;
  111. `;
  112. function TitleWithTestId(props: PropsWithChildren<{}>) {
  113. return <Title data-test-id="trace-drawer-title">{props.children}</Title>;
  114. }
  115. function SubtitleWithCopyButton({
  116. text,
  117. hideCopyButton = false,
  118. }: {
  119. text: string;
  120. hideCopyButton?: boolean;
  121. }) {
  122. return (
  123. <SubTitleWrapper>
  124. <StyledSubTitleText>{text}</StyledSubTitleText>
  125. {!hideCopyButton ? (
  126. <CopyToClipboardButton
  127. borderless
  128. size="zero"
  129. iconSize="xs"
  130. text={text}
  131. tooltipProps={{disabled: true}}
  132. />
  133. ) : null}
  134. </SubTitleWrapper>
  135. );
  136. }
  137. const SubTitleWrapper = styled(FlexBox)`
  138. ${p => p.theme.overflowEllipsis}
  139. `;
  140. const StyledSubTitleText = styled('span')`
  141. font-size: ${p => p.theme.fontSizeMedium};
  142. color: ${p => p.theme.subText};
  143. `;
  144. function TitleOp({text}: {text: string}) {
  145. return (
  146. <Tooltip
  147. title={
  148. <Fragment>
  149. {text}
  150. <CopyToClipboardButton
  151. borderless
  152. size="zero"
  153. iconSize="xs"
  154. text={text}
  155. tooltipProps={{disabled: true}}
  156. />
  157. </Fragment>
  158. }
  159. showOnlyOnOverflow
  160. isHoverable
  161. >
  162. <TitleOpText>{text}</TitleOpText>
  163. </Tooltip>
  164. );
  165. }
  166. const Type = styled('div')`
  167. font-size: ${p => p.theme.fontSizeSmall};
  168. `;
  169. const TitleOpText = styled('div')`
  170. font-size: 15px;
  171. font-weight: ${p => p.theme.fontWeightBold};
  172. ${p => p.theme.overflowEllipsis}
  173. `;
  174. const Table = styled('table')`
  175. margin-bottom: 0 !important;
  176. td {
  177. overflow: hidden;
  178. }
  179. `;
  180. const IconTitleWrapper = styled(FlexBox)`
  181. gap: ${space(1)};
  182. min-width: 30px;
  183. `;
  184. const IconBorder = styled('div')<{backgroundColor: string; errored?: boolean}>`
  185. background-color: ${p => p.backgroundColor};
  186. border-radius: ${p => p.theme.borderRadius};
  187. padding: 0;
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. width: 30px;
  192. height: 30px;
  193. min-width: 30px;
  194. svg {
  195. fill: ${p => p.theme.white};
  196. width: 14px;
  197. height: 14px;
  198. }
  199. `;
  200. const LegacyHeaderContainer = styled(FlexBox)`
  201. margin: ${space(1)};
  202. justify-content: space-between;
  203. gap: ${space(3)};
  204. container-type: inline-size;
  205. @container (max-width: 780px) {
  206. .DropdownMenu {
  207. display: block;
  208. }
  209. .Actions {
  210. display: none;
  211. }
  212. }
  213. @container (min-width: 781px) {
  214. .DropdownMenu {
  215. display: none;
  216. }
  217. }
  218. `;
  219. const HeaderContainer = styled(FlexBox)`
  220. align-items: baseline;
  221. justify-content: space-between;
  222. gap: ${space(3)};
  223. padding: ${space(0.25)} 0 ${space(0.5)} 0;
  224. margin: 0 ${space(2)} ${space(1)} ${space(2)};
  225. border-bottom: 1px solid ${p => p.theme.border};
  226. `;
  227. const DURATION_COMPARISON_STATUS_COLORS: {
  228. equal: {light: ColorOrAlias; normal: ColorOrAlias};
  229. faster: {light: ColorOrAlias; normal: ColorOrAlias};
  230. slower: {light: ColorOrAlias; normal: ColorOrAlias};
  231. } = {
  232. faster: {
  233. light: 'green100',
  234. normal: 'green300',
  235. },
  236. slower: {
  237. light: 'red100',
  238. normal: 'red300',
  239. },
  240. equal: {
  241. light: 'gray100',
  242. normal: 'gray300',
  243. },
  244. };
  245. const MIN_PCT_DURATION_DIFFERENCE = 10;
  246. type DurationComparison = {
  247. deltaPct: number;
  248. deltaText: JSX.Element;
  249. status: 'faster' | 'slower' | 'equal';
  250. } | null;
  251. const getDurationComparison = (
  252. baseline: number | undefined,
  253. duration: number,
  254. baseDescription?: string
  255. ): DurationComparison => {
  256. if (!baseline) {
  257. return null;
  258. }
  259. const delta = duration - baseline;
  260. const deltaPct = Math.round(Math.abs((delta / baseline) * 100));
  261. const status = delta > 0 ? 'slower' : delta < 0 ? 'faster' : 'equal';
  262. const formattedBaseDuration = (
  263. <Tooltip
  264. title={baseDescription}
  265. showUnderline
  266. underlineColor={DURATION_COMPARISON_STATUS_COLORS[status].normal}
  267. >
  268. {getDuration(baseline, 2, true)}
  269. </Tooltip>
  270. );
  271. const deltaText =
  272. status === 'equal'
  273. ? tct(`equal to avg [formattedBaseDuration]`, {
  274. formattedBaseDuration,
  275. })
  276. : status === 'faster'
  277. ? tct(`[deltaPct] faster than avg [formattedBaseDuration]`, {
  278. formattedBaseDuration,
  279. deltaPct: `${deltaPct}%`,
  280. })
  281. : tct(`[deltaPct] slower than avg [formattedBaseDuration]`, {
  282. formattedBaseDuration,
  283. deltaPct: `${deltaPct}%`,
  284. });
  285. return {deltaPct, status, deltaText};
  286. };
  287. type DurationProps = {
  288. baseline: number | undefined;
  289. duration: number;
  290. node: TraceTreeNode<TraceTree.NodeValue>;
  291. baseDescription?: string;
  292. ratio?: number;
  293. };
  294. function Duration(props: DurationProps) {
  295. if (typeof props.duration !== 'number' || Number.isNaN(props.duration)) {
  296. return <DurationContainer>{t('unknown')}</DurationContainer>;
  297. }
  298. // Since transactions have ms precision, we show 2 decimal places only if the duration is greater than 1 second.
  299. const precision = isTransactionNode(props.node) ? (props.duration > 1 ? 2 : 0) : 2;
  300. if (props.baseline === undefined || props.baseline === 0) {
  301. return (
  302. <DurationContainer>
  303. {getDuration(props.duration, precision, true)}
  304. </DurationContainer>
  305. );
  306. }
  307. const comparison = getDurationComparison(
  308. props.baseline,
  309. props.duration,
  310. props.baseDescription
  311. );
  312. return (
  313. <Fragment>
  314. <DurationContainer>
  315. {getDuration(props.duration, precision, true)}{' '}
  316. {props.ratio ? `(${(props.ratio * 100).toFixed()}%)` : null}
  317. </DurationContainer>
  318. {comparison && comparison.deltaPct >= MIN_PCT_DURATION_DIFFERENCE ? (
  319. <Comparison status={comparison.status}>{comparison.deltaText}</Comparison>
  320. ) : null}
  321. </Fragment>
  322. );
  323. }
  324. function TableRow({
  325. title,
  326. keep,
  327. children,
  328. prefix,
  329. extra = null,
  330. toolTipText,
  331. }: {
  332. children: React.ReactNode;
  333. title: JSX.Element | string | null;
  334. extra?: React.ReactNode;
  335. keep?: boolean;
  336. prefix?: JSX.Element;
  337. toolTipText?: string;
  338. }) {
  339. if (!keep && !children) {
  340. return null;
  341. }
  342. return (
  343. <tr>
  344. <td className="key">
  345. <Flex>
  346. {prefix}
  347. {title}
  348. {toolTipText ? <StyledQuestionTooltip size="xs" title={toolTipText} /> : null}
  349. </Flex>
  350. </td>
  351. <ValueTd className="value">
  352. <TableValueRow>
  353. <StyledPre>
  354. <span className="val-string">{children}</span>
  355. </StyledPre>
  356. <TableRowButtonContainer>{extra}</TableRowButtonContainer>
  357. </TableValueRow>
  358. </ValueTd>
  359. </tr>
  360. );
  361. }
  362. type HighlightProps = {
  363. avgDuration: number | undefined;
  364. bodyContent: React.ReactNode;
  365. headerContent: React.ReactNode;
  366. node: TraceTreeNode<TraceTree.NodeValue>;
  367. project: Project | undefined;
  368. transaction: EventTransaction | undefined;
  369. };
  370. function Highlights({
  371. node,
  372. transaction: event,
  373. avgDuration,
  374. project,
  375. headerContent,
  376. bodyContent,
  377. }: HighlightProps) {
  378. if (!isTransactionNode(node) && !isSpanNode(node)) {
  379. return null;
  380. }
  381. const startTimestamp = node.space[0];
  382. const endTimestamp = node.space[0] + node.space[1];
  383. const durationInSeconds = (endTimestamp - startTimestamp) / 1e3;
  384. const comparison = getDurationComparison(
  385. avgDuration,
  386. durationInSeconds,
  387. t('Average duration for this transaction over the last 24 hours')
  388. );
  389. return (
  390. <Fragment>
  391. <HighlightsWrapper>
  392. <HighlightsLeftColumn>
  393. <Tooltip title={node.value?.project_slug}>
  394. <ProjectBadge
  395. project={project ? project : {slug: node.value?.project_slug ?? ''}}
  396. avatarSize={18}
  397. hideName
  398. />
  399. </Tooltip>
  400. <VerticalLine />
  401. </HighlightsLeftColumn>
  402. <HighlightsRightColumn>
  403. <HighlightOp>
  404. {isTransactionNode(node) ? node.value?.['transaction.op'] : node.value?.op}
  405. </HighlightOp>
  406. <HighlightsDurationWrapper>
  407. <HighlightDuration>
  408. {getDuration(durationInSeconds, 2, true)}
  409. </HighlightDuration>
  410. {comparison && comparison.deltaPct >= MIN_PCT_DURATION_DIFFERENCE ? (
  411. <HiglightsDurationComparison status={comparison.status}>
  412. {comparison.deltaText}
  413. </HiglightsDurationComparison>
  414. ) : null}
  415. </HighlightsDurationWrapper>
  416. <StyledPanel>
  417. <StyledPanelHeader>{headerContent}</StyledPanelHeader>
  418. <PanelBody>{bodyContent}</PanelBody>
  419. </StyledPanel>
  420. {event ? <HighLightsOpsBreakdown event={event} /> : null}
  421. </HighlightsRightColumn>
  422. </HighlightsWrapper>
  423. <SectionDivider />
  424. </Fragment>
  425. );
  426. }
  427. const StyledPanel = styled(Panel)`
  428. margin-bottom: 0;
  429. `;
  430. function HighLightsOpsBreakdown({event}: {event: EventTransaction}) {
  431. const breakdown = generateStats(event, {type: 'no_filter'});
  432. return (
  433. <HighlightsOpsBreakdownWrapper>
  434. <HighlightsSpanCount>
  435. {t('Most frequent span ops for this transaction are')}
  436. </HighlightsSpanCount>
  437. <TopOpsList>
  438. {breakdown.slice(0, 3).map(currOp => {
  439. const {name, percentage} = currOp;
  440. const operationName = typeof name === 'string' ? name : t('Other');
  441. const color = pickBarColor(operationName);
  442. const pctLabel = isFinite(percentage) ? Math.round(percentage * 100) : '∞';
  443. return (
  444. <HighlightsOpRow key={operationName}>
  445. <IconCircleFill size="xs" color={color as Color} />
  446. {operationName}
  447. <HighlightsOpPct>{pctLabel}%</HighlightsOpPct>
  448. </HighlightsOpRow>
  449. );
  450. })}
  451. </TopOpsList>
  452. </HighlightsOpsBreakdownWrapper>
  453. );
  454. }
  455. const TopOpsList = styled('div')`
  456. display: flex;
  457. flex-direction: row;
  458. gap: ${space(1)};
  459. `;
  460. const HighlightsOpPct = styled('div')`
  461. color: ${p => p.theme.subText};
  462. font-size: 14px;
  463. `;
  464. const HighlightsSpanCount = styled('div')`
  465. margin-bottom: ${space(0.25)};
  466. `;
  467. const HighlightsOpRow = styled(FlexBox)`
  468. font-size: 13px;
  469. gap: ${space(0.5)};
  470. `;
  471. const HighlightsOpsBreakdownWrapper = styled(FlexBox)`
  472. align-items: flex-start;
  473. flex-direction: column;
  474. gap: ${space(0.25)};
  475. margin-top: ${space(1.5)};
  476. `;
  477. const HiglightsDurationComparison = styled('div')<{status: string}>`
  478. white-space: nowrap;
  479. border-radius: 12px;
  480. color: ${p => p.theme[DURATION_COMPARISON_STATUS_COLORS[p.status].normal]};
  481. background-color: ${p => p.theme[DURATION_COMPARISON_STATUS_COLORS[p.status].light]};
  482. border: solid 1px ${p => p.theme[DURATION_COMPARISON_STATUS_COLORS[p.status].light]};
  483. font-size: ${p => p.theme.fontSizeExtraSmall};
  484. padding: ${space(0.25)} ${space(1)};
  485. display: inline-block;
  486. height: 21px;
  487. `;
  488. const HighlightsDurationWrapper = styled(FlexBox)`
  489. gap: ${space(1)};
  490. margin-bottom: ${space(1)};
  491. `;
  492. const HighlightDuration = styled('div')`
  493. font-size: ${p => p.theme.headerFontSize};
  494. font-weight: 400;
  495. `;
  496. const HighlightOp = styled('div')`
  497. font-weight: bold;
  498. font-size: ${p => p.theme.fontSizeMedium};
  499. line-height: normal;
  500. `;
  501. const StyledPanelHeader = styled(PanelHeader)`
  502. font-weight: normal;
  503. padding: 0;
  504. line-height: normal;
  505. text-transform: none;
  506. overflow: hidden;
  507. `;
  508. const SectionDivider = styled('hr')`
  509. border-color: ${p => p.theme.translucentBorder};
  510. margin: ${space(3)} 0 ${space(1.5)} 0;
  511. `;
  512. const VerticalLine = styled('div')`
  513. width: 1px;
  514. height: 100%;
  515. background-color: ${p => p.theme.border};
  516. margin-top: ${space(0.5)};
  517. `;
  518. const HighlightsWrapper = styled('div')`
  519. display: flex;
  520. align-items: stretch;
  521. gap: ${space(1)};
  522. width: 100%;
  523. margin: ${space(1)} 0;
  524. `;
  525. const HighlightsLeftColumn = styled('div')`
  526. display: flex;
  527. flex-direction: column;
  528. justify-content: center;
  529. align-items: center;
  530. `;
  531. const HighlightsRightColumn = styled('div')`
  532. display: flex;
  533. flex-direction: column;
  534. justify-content: left;
  535. height: 100%;
  536. flex: 1;
  537. overflow: hidden;
  538. `;
  539. function IssuesLink({
  540. node,
  541. children,
  542. }: {
  543. children: React.ReactNode;
  544. node: TraceTreeNode<TraceTree.NodeValue>;
  545. }) {
  546. const organization = useOrganization();
  547. const params = useParams<{traceSlug?: string}>();
  548. const traceSlug = params.traceSlug?.trim() ?? '';
  549. // Adding a buffer of 15mins for errors only traces, where there is no concept of
  550. // trace duration and start equals end timestamps.
  551. const buffer = node.space[1] > 0 ? 0 : 15 * 60 * 1000;
  552. return (
  553. <Link
  554. to={{
  555. pathname: `/organizations/${organization.slug}/issues/`,
  556. query: {
  557. query: `trace:${traceSlug}`,
  558. start: new Date(node.space[0] - buffer).toISOString(),
  559. end: new Date(node.space[0] + node.space[1] + buffer).toISOString(),
  560. // If we don't pass the project param, the issues page will filter by the last selected project.
  561. // Traces can have multiple projects, so we query issues by all projects and rely on our search query to filter the results.
  562. project: -1,
  563. },
  564. }}
  565. >
  566. {children}
  567. </Link>
  568. );
  569. }
  570. const LAZY_RENDER_PROPS: Partial<LazyRenderProps> = {
  571. observerOptions: {rootMargin: '50px'},
  572. };
  573. const DurationContainer = styled('span')`
  574. font-weight: ${p => p.theme.fontWeightBold};
  575. margin-right: ${space(1)};
  576. `;
  577. const Comparison = styled('span')<{status: 'faster' | 'slower' | 'equal'}>`
  578. color: ${p => p.theme[DURATION_COMPARISON_STATUS_COLORS[p.status].normal]};
  579. `;
  580. const Flex = styled('div')`
  581. display: flex;
  582. align-items: center;
  583. `;
  584. const TableValueRow = styled('div')`
  585. display: grid;
  586. grid-template-columns: auto min-content;
  587. gap: ${space(1)};
  588. border-radius: 4px;
  589. background-color: ${p => p.theme.surface200};
  590. margin: 2px;
  591. `;
  592. const StyledQuestionTooltip = styled(QuestionTooltip)`
  593. margin-left: ${space(0.5)};
  594. `;
  595. const StyledPre = styled('pre')`
  596. margin: 0 !important;
  597. background-color: transparent !important;
  598. `;
  599. const TableRowButtonContainer = styled('div')`
  600. padding: 8px 10px;
  601. `;
  602. const ValueTd = styled('td')`
  603. position: relative;
  604. `;
  605. function getThreadIdFromNode(
  606. node: TraceTreeNode<TraceTree.NodeValue>,
  607. transaction: EventTransaction | undefined
  608. ): string | undefined {
  609. if (isSpanNode(node) && node.value.data?.['thread.id']) {
  610. return node.value.data['thread.id'];
  611. }
  612. if (transaction) {
  613. return transaction.contexts?.trace?.data?.['thread.id'];
  614. }
  615. return undefined;
  616. }
  617. // Renders the dropdown menu list at the root trace drawer content container level, to prevent
  618. // being stacked under other content.
  619. function DropdownMenuWithPortal(props: DropdownMenuProps) {
  620. const drawerContainerRef = useDrawerContainerRef();
  621. return (
  622. <DropdownMenu
  623. {...props}
  624. usePortal={!!drawerContainerRef}
  625. portalContainerRef={drawerContainerRef}
  626. />
  627. );
  628. }
  629. function TypeSafeBoolean<T>(value: T | null | undefined): value is NonNullable<T> {
  630. return value !== null && value !== undefined;
  631. }
  632. function PanelPositionDropDown({organization}: {organization: Organization}) {
  633. const traceState = useTraceState();
  634. const traceDispatch = useTraceStateDispatch();
  635. const options: MenuItemProps[] = [];
  636. const layoutOptions = traceState.preferences.drawer.layoutOptions;
  637. if (layoutOptions.includes('drawer left')) {
  638. options.push({
  639. key: 'drawer-left',
  640. onAction: () => {
  641. traceAnalytics.trackLayoutChange('drawer left', organization);
  642. traceDispatch({type: 'set layout', payload: 'drawer left'});
  643. },
  644. leadingItems: <IconPanel direction="left" size="xs" />,
  645. label: t('Left'),
  646. disabled: traceState.preferences.layout === 'drawer left',
  647. });
  648. }
  649. if (layoutOptions.includes('drawer right')) {
  650. options.push({
  651. key: 'drawer-right',
  652. onAction: () => {
  653. traceAnalytics.trackLayoutChange('drawer right', organization);
  654. traceDispatch({type: 'set layout', payload: 'drawer right'});
  655. },
  656. leadingItems: <IconPanel direction="right" size="xs" />,
  657. label: t('Right'),
  658. disabled: traceState.preferences.layout === 'drawer right',
  659. });
  660. }
  661. if (layoutOptions.includes('drawer bottom')) {
  662. options.push({
  663. key: 'drawer-bottom',
  664. onAction: () => {
  665. traceAnalytics.trackLayoutChange('drawer bottom', organization);
  666. traceDispatch({type: 'set layout', payload: 'drawer bottom'});
  667. },
  668. leadingItems: <IconPanel direction="down" size="xs" />,
  669. label: t('Bottom'),
  670. disabled: traceState.preferences.layout === 'drawer bottom',
  671. });
  672. }
  673. return (
  674. <DropdownMenu
  675. size="sm"
  676. items={options}
  677. menuTitle={<div>{t('Panel Position')}</div>}
  678. trigger={triggerProps => (
  679. <Tooltip title={t('Panel Position')}>
  680. <ActionButton
  681. {...triggerProps}
  682. size="xs"
  683. aria-label={t('Panel position')}
  684. icon={<IconPanel direction="right" size="xs" />}
  685. />
  686. </Tooltip>
  687. )}
  688. />
  689. );
  690. }
  691. function NodeActions(props: {
  692. node: TraceTreeNode<any>;
  693. onTabScrollToNode: (
  694. node:
  695. | TraceTreeNode<any>
  696. | ParentAutogroupNode
  697. | SiblingAutogroupNode
  698. | MissingInstrumentationNode
  699. ) => void;
  700. organization: Organization;
  701. eventSize?: number | undefined;
  702. }) {
  703. const hasNewTraceUi = useHasTraceNewUi();
  704. const organization = useOrganization();
  705. const params = useParams<{traceSlug?: string}>();
  706. const {data: transaction} = useTransaction({
  707. node: isTransactionNode(props.node) ? props.node : null,
  708. organization,
  709. });
  710. const transactionProfileTarget = useMemo(() => {
  711. const profileId = isTransactionNode(props.node)
  712. ? props.node.value.profile_id
  713. : isSpanNode(props.node)
  714. ? props.node.event?.contexts?.profile?.profile_id ?? ''
  715. : '';
  716. if (!profileId) {
  717. return null;
  718. }
  719. return makeTransactionProfilingLink(profileId, {
  720. orgSlug: props.organization.slug,
  721. projectSlug: props.node.metadata.project_slug ?? '',
  722. });
  723. }, [props.node, props.organization]);
  724. const continuousProfileTarget = useMemo(() => {
  725. const profilerId = isTransactionNode(props.node)
  726. ? props.node.value.profiler_id
  727. : isSpanNode(props.node)
  728. ? props.node.value.sentry_tags?.profiler_id ?? null
  729. : null;
  730. if (!profilerId) {
  731. return null;
  732. }
  733. return makeTraceContinuousProfilingLink(props.node, profilerId, {
  734. orgSlug: props.organization.slug,
  735. projectSlug: props.node.metadata.project_slug ?? '',
  736. traceId: params.traceSlug ?? '',
  737. threadId: getThreadIdFromNode(props.node, transaction),
  738. });
  739. }, [params.traceSlug, props.node, props.organization, transaction]);
  740. if (!hasNewTraceUi) {
  741. return (
  742. <LegacyNodeActions
  743. {...props}
  744. continuousProfileTarget={continuousProfileTarget}
  745. transactionProfileTarget={transactionProfileTarget}
  746. />
  747. );
  748. }
  749. return (
  750. <ActionWrapper>
  751. <Tooltip title={t('Show in view')}>
  752. <ActionButton
  753. onClick={_e => {
  754. traceAnalytics.trackShowInView(props.organization);
  755. props.onTabScrollToNode(props.node);
  756. }}
  757. size="xs"
  758. aria-label={t('Show in view')}
  759. icon={<IconFocus size="xs" />}
  760. />
  761. </Tooltip>
  762. {isTransactionNode(props.node) ? (
  763. <Tooltip title={t('JSON')}>
  764. <ActionButton
  765. onClick={() => traceAnalytics.trackViewEventJSON(props.organization)}
  766. href={`/api/0/projects/${props.organization.slug}/${props.node.value.project_slug}/events/${props.node.value.event_id}/json/`}
  767. size="xs"
  768. aria-label={t('JSON')}
  769. icon={<IconJson size="xs" />}
  770. />
  771. </Tooltip>
  772. ) : null}
  773. {continuousProfileTarget ? (
  774. <Tooltip title={t('Profile')}>
  775. <ActionButton
  776. onClick={() => traceAnalytics.trackViewContinuousProfile(props.organization)}
  777. to={continuousProfileTarget}
  778. size="xs"
  779. aria-label={t('Profile')}
  780. icon={<IconProfiling size="xs" />}
  781. />
  782. </Tooltip>
  783. ) : transactionProfileTarget ? (
  784. <Tooltip title={t('Profile')}>
  785. <ActionButton
  786. onClick={() => traceAnalytics.trackViewTransactionProfile(props.organization)}
  787. to={transactionProfileTarget}
  788. size="xs"
  789. aria-label={t('Profile')}
  790. icon={<IconProfiling size="xs" />}
  791. />
  792. </Tooltip>
  793. ) : null}
  794. <PanelPositionDropDown organization={organization} />
  795. </ActionWrapper>
  796. );
  797. }
  798. const ActionButton = styled(Button)`
  799. border: none;
  800. background-color: transparent;
  801. box-shadow: none;
  802. transition: none !important;
  803. opacity: 0.8;
  804. height: 24px;
  805. max-height: 24px;
  806. &:hover {
  807. border: none;
  808. background-color: transparent;
  809. box-shadow: none;
  810. opacity: 1;
  811. }
  812. `;
  813. const ActionWrapper = styled('div')`
  814. display: flex;
  815. align-items: center;
  816. gap: ${space(0.25)};
  817. `;
  818. function LegacyNodeActions(props: {
  819. continuousProfileTarget: LocationDescriptor | null;
  820. node: TraceTreeNode<any>;
  821. onTabScrollToNode: (
  822. node:
  823. | TraceTreeNode<any>
  824. | ParentAutogroupNode
  825. | SiblingAutogroupNode
  826. | MissingInstrumentationNode
  827. ) => void;
  828. organization: Organization;
  829. transactionProfileTarget: LocationDescriptor | null;
  830. eventSize?: number | undefined;
  831. }) {
  832. const navigate = useNavigate();
  833. const items = useMemo((): MenuItemProps[] => {
  834. const showInView: MenuItemProps = {
  835. key: 'show-in-view',
  836. label: t('Show in View'),
  837. onAction: () => {
  838. traceAnalytics.trackShowInView(props.organization);
  839. props.onTabScrollToNode(props.node);
  840. },
  841. };
  842. const eventId =
  843. props.node.metadata.event_id ??
  844. TraceTree.ParentTransaction(props.node)?.metadata.event_id;
  845. const projectSlug =
  846. props.node.metadata.project_slug ??
  847. TraceTree.ParentTransaction(props.node)?.metadata.project_slug;
  848. const eventSize = props.eventSize;
  849. const jsonDetails: MenuItemProps = {
  850. key: 'json-details',
  851. onAction: () => {
  852. traceAnalytics.trackViewEventJSON(props.organization);
  853. window.open(
  854. `/api/0/projects/${props.organization.slug}/${projectSlug}/events/${eventId}/json/`,
  855. '_blank'
  856. );
  857. },
  858. label:
  859. t('JSON') +
  860. (typeof eventSize === 'number' ? ` (${formatBytesBase10(eventSize, 0)})` : ''),
  861. };
  862. const profileLink: MenuItemProps | null = props.continuousProfileTarget
  863. ? {
  864. key: 'profile',
  865. onAction: () => {
  866. traceAnalytics.trackViewContinuousProfile(props.organization);
  867. navigate(props.continuousProfileTarget!);
  868. },
  869. label: t('View Profile'),
  870. }
  871. : props.transactionProfileTarget
  872. ? {
  873. key: 'profile',
  874. onAction: () => {
  875. traceAnalytics.trackViewTransactionProfile(props.organization);
  876. navigate(props.transactionProfileTarget!);
  877. },
  878. label: t('View Profile'),
  879. }
  880. : null;
  881. if (isTransactionNode(props.node)) {
  882. return [showInView, jsonDetails, profileLink].filter(TypeSafeBoolean);
  883. }
  884. if (isSpanNode(props.node)) {
  885. return [showInView, profileLink].filter(TypeSafeBoolean);
  886. }
  887. if (isMissingInstrumentationNode(props.node)) {
  888. return [showInView, profileLink].filter(TypeSafeBoolean);
  889. }
  890. if (isTraceErrorNode(props.node)) {
  891. return [showInView, profileLink].filter(TypeSafeBoolean);
  892. }
  893. if (isRootNode(props.node)) {
  894. return [showInView];
  895. }
  896. if (isAutogroupedNode(props.node)) {
  897. return [showInView];
  898. }
  899. return [showInView];
  900. }, [props, navigate]);
  901. return (
  902. <ActionsContainer>
  903. <Actions className="Actions">
  904. {props.continuousProfileTarget ? (
  905. <LinkButton size="xs" to={props.continuousProfileTarget}>
  906. {t('View Profile')}
  907. </LinkButton>
  908. ) : props.transactionProfileTarget ? (
  909. <LinkButton size="xs" to={props.transactionProfileTarget}>
  910. {t('View Profile')}
  911. </LinkButton>
  912. ) : null}
  913. <Button
  914. size="xs"
  915. onClick={_e => {
  916. traceAnalytics.trackShowInView(props.organization);
  917. props.onTabScrollToNode(props.node);
  918. }}
  919. >
  920. {t('Show in view')}
  921. </Button>
  922. {isTransactionNode(props.node) ? (
  923. <LinkButton
  924. size="xs"
  925. icon={<IconOpen />}
  926. onClick={() => traceAnalytics.trackViewEventJSON(props.organization)}
  927. href={`/api/0/projects/${props.organization.slug}/${props.node.value.project_slug}/events/${props.node.value.event_id}/json/`}
  928. external
  929. >
  930. {t('JSON')} (<FileSize bytes={props.eventSize ?? 0} />)
  931. </LinkButton>
  932. ) : null}
  933. </Actions>
  934. <DropdownMenuWithPortal
  935. items={items}
  936. className="DropdownMenu"
  937. position="bottom-end"
  938. trigger={triggerProps => (
  939. <ActionsButtonTrigger size="xs" {...triggerProps}>
  940. {t('Actions')}
  941. <IconChevron direction="down" size="xs" />
  942. </ActionsButtonTrigger>
  943. )}
  944. />
  945. </ActionsContainer>
  946. );
  947. }
  948. const ActionsButtonTrigger = styled(Button)`
  949. svg {
  950. margin-left: ${space(0.5)};
  951. width: 10px;
  952. height: 10px;
  953. }
  954. `;
  955. const ActionsContainer = styled('div')`
  956. display: flex;
  957. justify-content: end;
  958. align-items: center;
  959. gap: ${space(1)};
  960. `;
  961. function EventTags({projectSlug, event}: {event: Event; projectSlug: string}) {
  962. const hasNewTraceUi = useHasTraceNewUi();
  963. if (!hasNewTraceUi) {
  964. return <LegacyEventTags event={event} projectSlug={projectSlug} />;
  965. }
  966. return <EventTagsDataSection event={event} projectSlug={projectSlug} />;
  967. }
  968. function LegacyEventTags({projectSlug, event}: {event: Event; projectSlug: string}) {
  969. return (
  970. <LazyRender {...TraceDrawerComponents.LAZY_RENDER_PROPS} containerHeight={200}>
  971. <TagsWrapper>
  972. <EventTagsDataSection event={event} projectSlug={projectSlug} />
  973. </TagsWrapper>
  974. </LazyRender>
  975. );
  976. }
  977. const TagsWrapper = styled('div')`
  978. h3 {
  979. color: ${p => p.theme.textColor};
  980. }
  981. `;
  982. export type SectionCardKeyValueList = KeyValueListData;
  983. function SectionCard({
  984. items,
  985. title,
  986. disableTruncate,
  987. sortAlphabetically = false,
  988. itemProps = {},
  989. }: {
  990. items: SectionCardKeyValueList;
  991. title: React.ReactNode;
  992. disableTruncate?: boolean;
  993. itemProps?: Partial<KeyValueDataContentProps>;
  994. sortAlphabetically?: boolean;
  995. }) {
  996. const contentItems = items.map(item => ({item, ...itemProps}));
  997. return (
  998. <CardWrapper>
  999. <KeyValueData.Card
  1000. title={title}
  1001. contentItems={contentItems}
  1002. sortAlphabetically={sortAlphabetically}
  1003. truncateLength={disableTruncate ? Infinity : 5}
  1004. />
  1005. </CardWrapper>
  1006. );
  1007. }
  1008. // This is trace-view specific styling. The card is rendered in a number of different places
  1009. // with tests failing otherwise, since @container queries are not supported by the version of
  1010. // jsdom currently used by jest.
  1011. const CardWrapper = styled('div')`
  1012. ${CardPanel} {
  1013. container-type: inline-size;
  1014. }
  1015. ${Subject} {
  1016. @container (width < 350px) {
  1017. max-width: 200px;
  1018. }
  1019. }
  1020. `;
  1021. function SectionCardGroup({children}: {children: React.ReactNode}) {
  1022. return <KeyValueData.Container>{children}</KeyValueData.Container>;
  1023. }
  1024. function CopyableCardValueWithLink({
  1025. value,
  1026. linkTarget,
  1027. linkText,
  1028. onClick,
  1029. }: {
  1030. value: React.ReactNode;
  1031. linkTarget?: LocationDescriptor;
  1032. linkText?: string;
  1033. onClick?: () => void;
  1034. }) {
  1035. return (
  1036. <CardValueContainer>
  1037. <CardValueText>
  1038. {value}
  1039. {typeof value === 'string' ? (
  1040. <StyledCopyToClipboardButton
  1041. borderless
  1042. size="zero"
  1043. iconSize="xs"
  1044. text={value}
  1045. />
  1046. ) : null}
  1047. </CardValueText>
  1048. {linkTarget && linkTarget ? (
  1049. <Link to={linkTarget} onClick={onClick}>
  1050. {linkText}
  1051. </Link>
  1052. ) : null}
  1053. </CardValueContainer>
  1054. );
  1055. }
  1056. function TraceDataSection({event}: {event: EventTransaction}) {
  1057. const traceData = event.contexts.trace?.data;
  1058. if (!traceData) {
  1059. return null;
  1060. }
  1061. return (
  1062. <SectionCard
  1063. items={Object.entries(traceData).map(([key, value]) => ({
  1064. key,
  1065. subject: key,
  1066. value,
  1067. }))}
  1068. title={t('Trace Data')}
  1069. />
  1070. );
  1071. }
  1072. const StyledCopyToClipboardButton = styled(CopyToClipboardButton)`
  1073. transform: translateY(2px);
  1074. `;
  1075. const CardValueContainer = styled(FlexBox)`
  1076. justify-content: space-between;
  1077. gap: ${space(1)};
  1078. flex-wrap: wrap;
  1079. `;
  1080. const CardValueText = styled('span')`
  1081. overflow-wrap: anywhere;
  1082. `;
  1083. export const CardContentSubject = styled('div')`
  1084. grid-column: span 1;
  1085. font-family: ${p => p.theme.text.familyMono};
  1086. word-wrap: break-word;
  1087. `;
  1088. const TraceDrawerComponents = {
  1089. DetailContainer,
  1090. BodyContainer,
  1091. FlexBox,
  1092. Title: TitleWithTestId,
  1093. Type,
  1094. TitleOp,
  1095. HeaderContainer,
  1096. LegacyHeaderContainer,
  1097. Highlights,
  1098. Actions,
  1099. NodeActions,
  1100. Table,
  1101. IconTitleWrapper,
  1102. IconBorder,
  1103. TitleText,
  1104. LegacyTitleText,
  1105. Duration,
  1106. TableRow,
  1107. LAZY_RENDER_PROPS,
  1108. TableRowButtonContainer,
  1109. TableValueRow,
  1110. IssuesLink,
  1111. SectionCard,
  1112. CopyableCardValueWithLink,
  1113. EventTags,
  1114. SubtitleWithCopyButton,
  1115. TraceDataSection,
  1116. SectionCardGroup,
  1117. DropdownMenuWithPortal,
  1118. };
  1119. export {TraceDrawerComponents};