trace.tsx 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634
  1. import type React from 'react';
  2. import {Fragment, useCallback, useEffect, useMemo, useRef, useState} from 'react';
  3. import {browserHistory} from 'react-router';
  4. import {AutoSizer, List} from 'react-virtualized';
  5. import {type Theme, useTheme} from '@emotion/react';
  6. import styled from '@emotion/styled';
  7. import * as qs from 'query-string';
  8. import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
  9. import Link from 'sentry/components/links/link';
  10. import LoadingIndicator from 'sentry/components/loadingIndicator';
  11. import {pickBarColor} from 'sentry/components/performance/waterfall/utils';
  12. import Placeholder from 'sentry/components/placeholder';
  13. import {generateIssueEventTarget} from 'sentry/components/quickTrace/utils';
  14. import {Tooltip} from 'sentry/components/tooltip';
  15. import {IconChevron, IconFire, IconZoom} from 'sentry/icons';
  16. import {t} from 'sentry/locale';
  17. import {space} from 'sentry/styles/space';
  18. import type {Organization, Project} from 'sentry/types';
  19. import {getDuration} from 'sentry/utils/formatters';
  20. import useApi from 'sentry/utils/useApi';
  21. import {useLocation} from 'sentry/utils/useLocation';
  22. import useOrganization from 'sentry/utils/useOrganization';
  23. import useProjects from 'sentry/utils/useProjects';
  24. import {
  25. getRovingIndexActionFromEvent,
  26. type RovingTabIndexAction,
  27. type RovingTabIndexUserActions,
  28. } from 'sentry/views/performance/newTraceDetails/rovingTabIndex';
  29. import {
  30. isAutogroupedNode,
  31. isMissingInstrumentationNode,
  32. isParentAutogroupedNode,
  33. isSpanNode,
  34. isTraceErrorNode,
  35. isTraceNode,
  36. isTransactionNode,
  37. } from './guards';
  38. import {ParentAutogroupNode, type TraceTree, type TraceTreeNode} from './traceTree';
  39. import {VirtualizedViewManager} from './virtualizedViewManager';
  40. function decodeScrollQueue(maybePath: unknown): TraceTree.NodePath[] | null {
  41. if (Array.isArray(maybePath)) {
  42. return maybePath;
  43. }
  44. if (typeof maybePath === 'string') {
  45. return [maybePath as TraceTree.NodePath];
  46. }
  47. return null;
  48. }
  49. const COUNT_FORMATTER = Intl.NumberFormat(undefined, {notation: 'compact'});
  50. interface RovingTabIndexState {
  51. index: number | null;
  52. items: number | null;
  53. node: TraceTreeNode<TraceTree.NodeValue> | null;
  54. }
  55. function computeNextIndexFromAction(
  56. current_index: number,
  57. action: RovingTabIndexUserActions,
  58. items: number
  59. ): number {
  60. switch (action) {
  61. case 'next':
  62. if (current_index === items) {
  63. return 0;
  64. }
  65. return current_index + 1;
  66. case 'previous':
  67. if (current_index === 0) {
  68. return items;
  69. }
  70. return current_index - 1;
  71. case 'last':
  72. return items;
  73. case 'first':
  74. return 0;
  75. default:
  76. throw new TypeError(`Invalid or not implemented reducer action - ${action}`);
  77. }
  78. }
  79. function maybeFocusRow(
  80. ref: HTMLDivElement | null,
  81. index: number,
  82. previouslyFocusedIndexRef: React.MutableRefObject<number | null>
  83. ) {
  84. if (!ref) return;
  85. if (index === previouslyFocusedIndexRef.current) return;
  86. ref.focus();
  87. previouslyFocusedIndexRef.current = index;
  88. }
  89. interface TraceProps {
  90. roving_dispatch: React.Dispatch<RovingTabIndexAction>;
  91. roving_state: RovingTabIndexState;
  92. setDetailNode: (node: TraceTreeNode<TraceTree.NodeValue> | null) => void;
  93. trace: TraceTree;
  94. trace_id: string;
  95. }
  96. function Trace({
  97. trace,
  98. trace_id,
  99. roving_state,
  100. roving_dispatch,
  101. setDetailNode,
  102. }: TraceProps) {
  103. const theme = useTheme();
  104. const api = useApi();
  105. const {projects} = useProjects();
  106. const organization = useOrganization();
  107. const location = useLocation();
  108. const viewManager = useMemo(() => {
  109. return new VirtualizedViewManager({
  110. list: {width: 0.5},
  111. span_list: {width: 0.5},
  112. });
  113. }, []);
  114. const previouslyFocusedIndexRef = useRef<number | null>(null);
  115. const [_rerender, setRender] = useState(0);
  116. const scrollQueue = useRef<TraceTree.NodePath[] | null>(null);
  117. const treeRef = useRef<TraceTree>(trace);
  118. treeRef.current = trace;
  119. if (
  120. trace.root.space &&
  121. (trace.root.space[0] !== viewManager.to_origin ||
  122. trace.root.space[1] !== viewManager.trace_space.width)
  123. ) {
  124. viewManager.initializeTraceSpace([trace.root.space[0], 0, trace.root.space[1], 1]);
  125. scrollQueue.current = decodeScrollQueue(qs.parse(location.search).node);
  126. }
  127. useEffect(() => {
  128. if (trace.type === 'loading' || scrollQueue.current === null || !viewManager) {
  129. return;
  130. }
  131. viewManager
  132. .scrollToPath(trace, scrollQueue.current, () => setRender(a => (a + 1) % 2), {
  133. api,
  134. organization,
  135. })
  136. .then(maybeNode => {
  137. scrollQueue.current = null;
  138. if (!maybeNode) {
  139. return;
  140. }
  141. viewManager.onScrollEndOutOfBoundsCheck();
  142. setDetailNode(maybeNode.node);
  143. roving_dispatch({
  144. type: 'set index',
  145. index: maybeNode.index,
  146. node: maybeNode.node,
  147. });
  148. });
  149. }, [api, organization, trace, trace_id, viewManager, setDetailNode, roving_dispatch]);
  150. const handleZoomIn = useCallback(
  151. (
  152. event: React.MouseEvent,
  153. node: TraceTreeNode<TraceTree.NodeValue>,
  154. value: boolean
  155. ) => {
  156. if (!isTransactionNode(node) && !isSpanNode(node)) {
  157. throw new TypeError('Node must be a transaction or span');
  158. }
  159. event.stopPropagation();
  160. treeRef.current
  161. .zoomIn(node, value, {
  162. api,
  163. organization,
  164. })
  165. .then(() => {
  166. setRender(a => (a + 1) % 2);
  167. });
  168. },
  169. [api, organization]
  170. );
  171. const handleExpandNode = useCallback(
  172. (
  173. event: React.MouseEvent<Element>,
  174. node: TraceTreeNode<TraceTree.NodeValue>,
  175. value: boolean
  176. ) => {
  177. event.stopPropagation();
  178. treeRef.current.expand(node, value);
  179. setRender(a => (a + 1) % 2);
  180. },
  181. []
  182. );
  183. const onRowClick = useCallback(
  184. (
  185. _event: React.MouseEvent,
  186. index: number,
  187. node: TraceTreeNode<TraceTree.NodeValue>
  188. ) => {
  189. browserHistory.push({
  190. pathname: location.pathname,
  191. query: {
  192. ...qs.parse(location.search),
  193. node: node.path,
  194. },
  195. });
  196. setDetailNode(node);
  197. roving_dispatch({type: 'set index', index, node});
  198. },
  199. // eslint-disable-next-line react-hooks/exhaustive-deps
  200. [roving_dispatch, setDetailNode]
  201. );
  202. const onRowKeyDown = useCallback(
  203. (
  204. event: React.KeyboardEvent,
  205. index: number,
  206. node: TraceTreeNode<TraceTree.NodeValue>
  207. ) => {
  208. if (!viewManager.list) {
  209. return;
  210. }
  211. const action = getRovingIndexActionFromEvent(event);
  212. if (action) {
  213. event.preventDefault();
  214. const nextIndex = computeNextIndexFromAction(
  215. index,
  216. action,
  217. treeRef.current.list.length - 1
  218. );
  219. viewManager.list.scrollToRow(nextIndex);
  220. roving_dispatch({type: 'set index', index: nextIndex, node});
  221. }
  222. },
  223. [viewManager.list, roving_dispatch]
  224. );
  225. // @TODO this is the implementation of infinite scroll. Once the user
  226. // reaches the end of the list, we fetch more data. The data is not yet
  227. // being appended to the tree as we need to figure out UX for this.
  228. // onRowsRendered callback should be passed to the List component
  229. // const limitRef = useRef<number | null>(null);
  230. // if (limitRef.current === null) {
  231. // let decodedLimit = getTraceQueryParams(qs.parse(location.search)).limit;
  232. // if (typeof decodedLimit === 'string') {
  233. // decodedLimit = parseInt(decodedLimit, 2);
  234. // }
  235. // limitRef.current = decodedLimit;
  236. // }
  237. // const loadMoreRequestRef =
  238. // useRef<Promise<TraceSplitResults<TraceFullDetailed> | null> | null>(null);
  239. // const onRowsRendered = useCallback((rows: RenderedRows) => {
  240. // if (loadMoreRequestRef.current) {
  241. // // in flight request
  242. // return;
  243. // }
  244. // if (rows.stopIndex !== treeRef.current.list.length - 1) {
  245. // // not at the end
  246. // return;
  247. // }
  248. // if (
  249. // !loadMoreRequestRef.current &&
  250. // limitRef.current &&
  251. // rows.stopIndex === treeRef.current.list.length - 1
  252. // ) {
  253. // limitRef.current = limitRef.current + 500;
  254. // const promise = fetchTrace(api, {
  255. // traceId: trace_id,
  256. // orgSlug: organization.slug,
  257. // query: qs.stringify(getTraceQueryParams(location, {limit: limitRef.current})),
  258. // })
  259. // .then(data => {
  260. // return data;
  261. // })
  262. // .catch(e => {
  263. // return e;
  264. // });
  265. // loadMoreRequestRef.current = promise;
  266. // }
  267. // }, []);
  268. const projectLookup = useMemo(() => {
  269. return projects.reduce<Record<Project['slug'], Project>>((acc, project) => {
  270. acc[project.slug] = project;
  271. return acc;
  272. }, {});
  273. }, [projects]);
  274. return (
  275. <Fragment>
  276. <TraceStylingWrapper
  277. ref={r => viewManager.onContainerRef(r)}
  278. className={trace.type === 'loading' ? 'Loading' : ''}
  279. style={{
  280. height: '70vh',
  281. width: '100%',
  282. margin: 'auto',
  283. }}
  284. >
  285. <TraceDivider
  286. className="TraceDivider"
  287. ref={r => viewManager?.registerDividerRef(r)}
  288. />
  289. {trace.type === 'loading' ? <TraceLoading /> : null}
  290. <AutoSizer>
  291. {({width, height}) => (
  292. <Fragment>
  293. <div
  294. className="TraceIndicatorContainer"
  295. ref={r => viewManager.registerIndicatorContainerRef(r)}
  296. >
  297. {trace.indicators.length > 0
  298. ? trace.indicators.map((indicator, i) => {
  299. return (
  300. <div
  301. key={i}
  302. ref={r => viewManager.registerIndicatorRef(r, i, indicator)}
  303. className="TraceIndicator"
  304. >
  305. <div className="TraceIndicatorLabel">{indicator.label}</div>
  306. <div className="TraceIndicatorLine" />
  307. </div>
  308. );
  309. })
  310. : null}
  311. </div>
  312. <List
  313. ref={r => viewManager.registerList(r)}
  314. rowHeight={24}
  315. height={height}
  316. width={width}
  317. scrollToAlignment="center"
  318. overscanRowCount={5}
  319. rowCount={treeRef.current.list.length ?? 0}
  320. rowRenderer={p => {
  321. return trace.type === 'loading' ? (
  322. <RenderPlaceholderRow
  323. style={p.style}
  324. node={treeRef.current.list[p.index]}
  325. index={p.index}
  326. theme={theme}
  327. projects={projectLookup}
  328. viewManager={viewManager!}
  329. startIndex={
  330. (p.parent as unknown as {_rowStartIndex: number})
  331. ._rowStartIndex ?? 0
  332. }
  333. />
  334. ) : (
  335. <RenderRow
  336. key={p.key}
  337. theme={theme}
  338. startIndex={
  339. (p.parent as unknown as {_rowStartIndex: number})
  340. ._rowStartIndex ?? 0
  341. }
  342. organization={organization}
  343. previouslyFocusedIndexRef={previouslyFocusedIndexRef}
  344. tabIndex={roving_state.index ?? -1}
  345. index={p.index}
  346. style={p.style}
  347. trace_id={trace_id}
  348. projects={projectLookup}
  349. node={treeRef.current.list[p.index]}
  350. viewManager={viewManager!}
  351. onExpand={handleExpandNode}
  352. onZoomIn={handleZoomIn}
  353. onRowClick={onRowClick}
  354. onRowKeyDown={onRowKeyDown}
  355. />
  356. );
  357. }}
  358. />
  359. </Fragment>
  360. )}
  361. </AutoSizer>
  362. </TraceStylingWrapper>
  363. </Fragment>
  364. );
  365. }
  366. export default Trace;
  367. const TraceDivider = styled('div')`
  368. position: absolute;
  369. height: 100%;
  370. background-color: transparent;
  371. top: 0;
  372. z-index: 10;
  373. cursor: col-resize;
  374. &:before {
  375. content: '';
  376. position: absolute;
  377. width: 1px;
  378. height: 100%;
  379. background-color: ${p => p.theme.border};
  380. left: 50%;
  381. }
  382. &:hover&:before {
  383. background-color: ${p => p.theme.purple300};
  384. }
  385. `;
  386. function RenderRow(props: {
  387. index: number;
  388. node: TraceTreeNode<TraceTree.NodeValue>;
  389. onExpand: (
  390. event: React.MouseEvent<Element>,
  391. node: TraceTreeNode<TraceTree.NodeValue>,
  392. value: boolean
  393. ) => void;
  394. onRowClick: (
  395. event: React.MouseEvent<Element>,
  396. index: number,
  397. node: TraceTreeNode<TraceTree.NodeValue>
  398. ) => void;
  399. onRowKeyDown: (
  400. event: React.KeyboardEvent,
  401. index: number,
  402. node: TraceTreeNode<TraceTree.NodeValue>
  403. ) => void;
  404. onZoomIn: (
  405. event: React.MouseEvent<Element>,
  406. node: TraceTreeNode<TraceTree.NodeValue>,
  407. value: boolean
  408. ) => void;
  409. organization: Organization;
  410. previouslyFocusedIndexRef: React.MutableRefObject<number | null>;
  411. projects: Record<Project['slug'], Project>;
  412. startIndex: number;
  413. style: React.CSSProperties;
  414. tabIndex: number;
  415. theme: Theme;
  416. trace_id: string;
  417. viewManager: VirtualizedViewManager;
  418. }) {
  419. const virtualizedIndex = props.index - props.startIndex;
  420. if (!props.node.value) {
  421. return null;
  422. }
  423. if (isAutogroupedNode(props.node)) {
  424. return (
  425. <div
  426. key={props.index}
  427. ref={r =>
  428. props.tabIndex === props.index
  429. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  430. : null
  431. }
  432. tabIndex={props.tabIndex === props.index ? 0 : -1}
  433. className="TraceRow Autogrouped"
  434. onClick={e => props.onRowClick(e, props.index, props.node)}
  435. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  436. style={{
  437. top: props.style.top,
  438. height: props.style.height,
  439. }}
  440. >
  441. <div
  442. className="TraceLeftColumn"
  443. ref={r =>
  444. props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
  445. }
  446. style={{
  447. width: props.viewManager.columns.list.width * 100 + '%',
  448. }}
  449. >
  450. <div
  451. className="TraceLeftColumnInner"
  452. style={{
  453. paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
  454. }}
  455. >
  456. <div className="TraceChildrenCountWrapper">
  457. <Connectors node={props.node} viewManager={props.viewManager} />
  458. <ChildrenCountButton
  459. expanded={!props.node.expanded}
  460. onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
  461. >
  462. {COUNT_FORMATTER.format(props.node.groupCount)}{' '}
  463. </ChildrenCountButton>
  464. </div>
  465. <span className="TraceOperation">{t('Autogrouped')}</span>
  466. <strong className="TraceEmDash"> — </strong>
  467. <span className="TraceDescription">{props.node.value.autogrouped_by.op}</span>
  468. </div>
  469. </div>
  470. <div
  471. className="TraceRightColumn"
  472. ref={r =>
  473. props.viewManager.registerColumnRef(
  474. 'span_list',
  475. r,
  476. virtualizedIndex,
  477. props.node
  478. )
  479. }
  480. style={{
  481. width: props.viewManager.columns.span_list.width * 100 + '%',
  482. backgroundColor:
  483. props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
  484. }}
  485. >
  486. {isParentAutogroupedNode(props.node) ? (
  487. <TraceBar
  488. virtualizedIndex={virtualizedIndex}
  489. viewManager={props.viewManager}
  490. color={props.theme.blue300}
  491. node_space={props.node.space}
  492. />
  493. ) : (
  494. <SiblingAutogroupedBar
  495. virtualizedIndex={virtualizedIndex}
  496. viewManager={props.viewManager}
  497. color={props.theme.blue300}
  498. node={props.node}
  499. />
  500. )}
  501. </div>
  502. </div>
  503. );
  504. }
  505. if (isTransactionNode(props.node)) {
  506. return (
  507. <div
  508. key={props.index}
  509. ref={r =>
  510. props.tabIndex === props.index
  511. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  512. : null
  513. }
  514. tabIndex={props.tabIndex === props.index ? 0 : -1}
  515. className="TraceRow"
  516. onClick={e => props.onRowClick(e, props.index, props.node)}
  517. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  518. style={{
  519. top: props.style.top,
  520. height: props.style.height,
  521. }}
  522. >
  523. <div
  524. className="TraceLeftColumn"
  525. ref={r =>
  526. props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
  527. }
  528. style={{
  529. width: props.viewManager.columns.list.width * 100 + '%',
  530. }}
  531. >
  532. <div
  533. className="TraceLeftColumnInner"
  534. style={{
  535. paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
  536. }}
  537. >
  538. <div
  539. className={`TraceChildrenCountWrapper ${
  540. props.node.isOrphaned ? 'Orphaned' : ''
  541. }`}
  542. >
  543. <Connectors node={props.node} viewManager={props.viewManager} />
  544. {props.node.children.length > 0 ? (
  545. <ChildrenCountButton
  546. expanded={props.node.expanded || props.node.zoomedIn}
  547. onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
  548. >
  549. {COUNT_FORMATTER.format(props.node.children.length)}{' '}
  550. </ChildrenCountButton>
  551. ) : null}
  552. </div>
  553. <ProjectBadge project={props.projects[props.node.value.project_slug]} />
  554. <span className="TraceOperation">{props.node.value['transaction.op']}</span>
  555. <strong className="TraceEmDash"> — </strong>
  556. <span>{props.node.value.transaction}</span>
  557. </div>
  558. {props.node.canFetchData ? (
  559. <Tooltip
  560. title={
  561. props.node.zoomedIn
  562. ? t('Hide the span waterfall for this transaction')
  563. : t('Load the span waterfall for this transaction')
  564. }
  565. position="top"
  566. skipWrapper
  567. delay={400}
  568. >
  569. <IconZoom
  570. className="IconZoom"
  571. isZoomIn={!props.node.zoomedIn}
  572. onClick={e => props.onZoomIn(e, props.node, !props.node.zoomedIn)}
  573. />
  574. </Tooltip>
  575. ) : null}
  576. </div>
  577. <div
  578. ref={r =>
  579. props.viewManager.registerColumnRef(
  580. 'span_list',
  581. r,
  582. virtualizedIndex,
  583. props.node
  584. )
  585. }
  586. className="TraceRightColumn"
  587. style={{
  588. width: props.viewManager.columns.span_list.width * 100 + '%',
  589. backgroundColor:
  590. props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
  591. }}
  592. >
  593. <TraceBar
  594. virtualizedIndex={virtualizedIndex}
  595. viewManager={props.viewManager}
  596. color={pickBarColor(props.node.value['transaction.op'])}
  597. node_space={props.node.space}
  598. />
  599. </div>
  600. </div>
  601. );
  602. }
  603. if (isSpanNode(props.node)) {
  604. return (
  605. <div
  606. key={props.index}
  607. ref={r =>
  608. props.tabIndex === props.index
  609. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  610. : null
  611. }
  612. tabIndex={props.tabIndex === props.index ? 0 : -1}
  613. className="TraceRow"
  614. onClick={e => props.onRowClick(e, props.index, props.node)}
  615. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  616. style={{
  617. top: props.style.top,
  618. height: props.style.height,
  619. }}
  620. >
  621. <div
  622. className="TraceLeftColumn"
  623. ref={r =>
  624. props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
  625. }
  626. style={{
  627. width: props.viewManager.columns.list.width * 100 + '%',
  628. }}
  629. >
  630. <div
  631. className="TraceLeftColumnInner"
  632. style={{
  633. paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
  634. }}
  635. >
  636. <div
  637. className={`TraceChildrenCountWrapper ${
  638. props.node.isOrphaned ? 'Orphaned' : ''
  639. }`}
  640. >
  641. <Connectors node={props.node} viewManager={props.viewManager} />
  642. {props.node.children.length > 0 ? (
  643. <ChildrenCountButton
  644. expanded={props.node.expanded || props.node.zoomedIn}
  645. onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
  646. >
  647. {COUNT_FORMATTER.format(props.node.children.length)}{' '}
  648. </ChildrenCountButton>
  649. ) : null}
  650. </div>
  651. <span className="TraceOperation">{props.node.value.op ?? '<unknown>'}</span>
  652. <strong className="TraceEmDash"> — </strong>
  653. <span className="TraceDescription" title={props.node.value.description}>
  654. {!props.node.value.description
  655. ? 'unknown'
  656. : props.node.value.description.length > 100
  657. ? props.node.value.description.slice(0, 100).trim() + '\u2026'
  658. : props.node.value.description}
  659. </span>
  660. </div>
  661. {props.node.canFetchData ? (
  662. <Tooltip
  663. title={
  664. props.node.zoomedIn
  665. ? t('Hide the span waterfall for this transaction')
  666. : t('Load the span waterfall for this transaction')
  667. }
  668. position="top"
  669. skipWrapper
  670. delay={400}
  671. >
  672. <IconZoom
  673. className="IconZoom"
  674. isZoomIn={!props.node.zoomedIn}
  675. onClick={e => props.onZoomIn(e, props.node, !props.node.zoomedIn)}
  676. />
  677. </Tooltip>
  678. ) : null}
  679. </div>
  680. <div
  681. ref={r =>
  682. props.viewManager.registerColumnRef(
  683. 'span_list',
  684. r,
  685. virtualizedIndex,
  686. props.node
  687. )
  688. }
  689. className="TraceRightColumn"
  690. style={{
  691. width: props.viewManager.columns.span_list.width * 100 + '%',
  692. backgroundColor:
  693. props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
  694. }}
  695. >
  696. <TraceBar
  697. virtualizedIndex={virtualizedIndex}
  698. viewManager={props.viewManager}
  699. color={pickBarColor(props.node.value.op)}
  700. node_space={props.node.space}
  701. />
  702. </div>
  703. </div>
  704. );
  705. }
  706. if (isMissingInstrumentationNode(props.node)) {
  707. return (
  708. <div
  709. key={props.index}
  710. ref={r =>
  711. props.tabIndex === props.index
  712. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  713. : null
  714. }
  715. tabIndex={props.tabIndex === props.index ? 0 : -1}
  716. className="TraceRow"
  717. onClick={e => props.onRowClick(e, props.index, props.node)}
  718. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  719. style={{
  720. top: props.style.top,
  721. height: props.style.height,
  722. }}
  723. >
  724. <div
  725. className="TraceLeftColumn"
  726. ref={r =>
  727. props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
  728. }
  729. style={{
  730. width: props.viewManager.columns.list.width * 100 + '%',
  731. }}
  732. >
  733. <div
  734. className="TraceLeftColumnInner"
  735. style={{
  736. paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
  737. }}
  738. >
  739. <div className="TraceChildrenCountWrapper">
  740. <Connectors node={props.node} viewManager={props.viewManager} />
  741. </div>
  742. <span className="TraceOperation">{t('Missing instrumentation')}</span>
  743. </div>
  744. </div>
  745. <div
  746. ref={r =>
  747. props.viewManager.registerColumnRef(
  748. 'span_list',
  749. r,
  750. virtualizedIndex,
  751. props.node
  752. )
  753. }
  754. className="TraceRightColumn"
  755. style={{
  756. width: props.viewManager.columns.span_list.width * 100 + '%',
  757. backgroundColor:
  758. props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
  759. }}
  760. >
  761. <TraceBar
  762. virtualizedIndex={virtualizedIndex}
  763. viewManager={props.viewManager}
  764. color={pickBarColor('missing-instrumentation')}
  765. node_space={props.node.space}
  766. />
  767. </div>
  768. </div>
  769. );
  770. }
  771. if (isTraceNode(props.node)) {
  772. return (
  773. <div
  774. key={props.index}
  775. ref={r =>
  776. props.tabIndex === props.index
  777. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  778. : null
  779. }
  780. tabIndex={props.tabIndex === props.index ? 0 : -1}
  781. className="TraceRow"
  782. onClick={e => props.onRowClick(e, props.index, props.node)}
  783. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  784. style={{
  785. top: props.style.top,
  786. height: props.style.height,
  787. }}
  788. >
  789. <div
  790. className="TraceLeftColumn"
  791. ref={r =>
  792. props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
  793. }
  794. style={{
  795. width: props.viewManager.columns.list.width * 100 + '%',
  796. }}
  797. >
  798. <div
  799. className="TraceLeftColumnInner"
  800. style={{
  801. paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
  802. }}
  803. >
  804. <div className="TraceChildrenCountWrapper Root">
  805. <Connectors node={props.node} viewManager={props.viewManager} />
  806. {props.node.children.length > 0 ? (
  807. <ChildrenCountButton
  808. expanded={props.node.expanded || props.node.zoomedIn}
  809. onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
  810. >
  811. {COUNT_FORMATTER.format(props.node.children.length)}{' '}
  812. </ChildrenCountButton>
  813. ) : null}
  814. </div>
  815. <span className="TraceOperation">{t('Trace')}</span>
  816. <strong className="TraceEmDash"> — </strong>
  817. <span className="TraceDescription">{props.trace_id}</span>
  818. </div>
  819. </div>
  820. <div
  821. ref={r =>
  822. props.viewManager.registerColumnRef(
  823. 'span_list',
  824. r,
  825. virtualizedIndex,
  826. props.node
  827. )
  828. }
  829. className="TraceRightColumn"
  830. style={{
  831. width: props.viewManager.columns.span_list.width * 100 + '%',
  832. backgroundColor:
  833. props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
  834. }}
  835. >
  836. {' '}
  837. <TraceBar
  838. virtualizedIndex={virtualizedIndex}
  839. viewManager={props.viewManager}
  840. color={pickBarColor('missing-instrumentation')}
  841. node_space={props.node.space}
  842. />
  843. </div>
  844. </div>
  845. );
  846. }
  847. if (isTraceErrorNode(props.node)) {
  848. return (
  849. <div
  850. key={props.index}
  851. ref={r =>
  852. props.tabIndex === props.index
  853. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  854. : null
  855. }
  856. tabIndex={props.tabIndex === props.index ? 0 : -1}
  857. className="TraceRow"
  858. onClick={e => props.onRowClick(e, props.index, props.node)}
  859. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  860. style={{
  861. top: props.style.top,
  862. height: props.style.height,
  863. }}
  864. >
  865. <div
  866. className="TraceLeftColumn"
  867. ref={r =>
  868. props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
  869. }
  870. style={{
  871. width: props.viewManager.columns.list.width * 100 + '%',
  872. }}
  873. >
  874. <div
  875. className="TraceLeftColumnInner"
  876. style={{
  877. paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
  878. }}
  879. >
  880. <div className="TraceChildrenCountWrapper">
  881. <Connectors node={props.node} viewManager={props.viewManager} />
  882. {props.node.children.length > 0 ? (
  883. <ChildrenCountButton
  884. expanded={props.node.expanded || props.node.zoomedIn}
  885. onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
  886. >
  887. {COUNT_FORMATTER.format(props.node.children.length)}{' '}
  888. </ChildrenCountButton>
  889. ) : null}
  890. </div>
  891. <ProjectBadge project={props.projects[props.node.value.project_slug]} />
  892. <Link
  893. className="Errored Link"
  894. onClick={e => e.stopPropagation()}
  895. to={generateIssueEventTarget(props.node.value, props.organization)}
  896. >
  897. <span className="TraceOperation">{t('Error')}</span>
  898. <strong className="TraceEmDash"> — </strong>
  899. <span className="TraceDescription">{props.node.value.title}</span>
  900. </Link>
  901. </div>
  902. </div>
  903. <div
  904. ref={r =>
  905. props.viewManager.registerColumnRef(
  906. 'span_list',
  907. r,
  908. virtualizedIndex,
  909. props.node
  910. )
  911. }
  912. className="TraceRightColumn"
  913. style={{
  914. width: props.viewManager.columns.span_list.width * 100 + '%',
  915. backgroundColor:
  916. props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
  917. }}
  918. >
  919. {typeof props.node.value.timestamp === 'number' ? (
  920. <div
  921. className="ErrorIconBorder"
  922. style={{
  923. transform: `translateX(${props.viewManager.computeTransformXFromTimestamp(
  924. props.node.value.timestamp * 1000
  925. )}px)`,
  926. }}
  927. >
  928. <IconFire color="errorText" size="xs" />
  929. </div>
  930. ) : null}
  931. </div>
  932. </div>
  933. );
  934. }
  935. return null;
  936. }
  937. function RenderPlaceholderRow(props: {
  938. index: number;
  939. node: TraceTreeNode<TraceTree.NodeValue>;
  940. projects: Record<Project['slug'], Project>;
  941. startIndex: number;
  942. style: React.CSSProperties;
  943. theme: Theme;
  944. viewManager: VirtualizedViewManager;
  945. }) {
  946. return (
  947. <div
  948. className="TraceRow"
  949. style={{
  950. top: props.style.top,
  951. height: props.style.height,
  952. pointerEvents: 'none',
  953. color: props.theme.subText,
  954. paddingLeft: space(1),
  955. }}
  956. >
  957. <div
  958. className="TraceLeftColumn"
  959. style={{width: props.viewManager.columns.list.width * 100 + '%'}}
  960. >
  961. <div
  962. className="TraceLeftColumnInner"
  963. style={{
  964. paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
  965. }}
  966. >
  967. <div
  968. className={`TraceChildrenCountWrapper ${isTraceNode(props.node) ? 'Root' : ''}`}
  969. >
  970. <Connectors node={props.node} viewManager={props.viewManager} />
  971. {props.node.children.length > 0 ? (
  972. <ChildrenCountButton
  973. expanded={props.node.expanded || props.node.zoomedIn}
  974. onClick={() => void 0}
  975. >
  976. {COUNT_FORMATTER.format(props.node.children.length)}{' '}
  977. </ChildrenCountButton>
  978. ) : null}
  979. </div>
  980. <Placeholder
  981. className="Placeholder"
  982. height="12px"
  983. width={randomBetween(20, 80) + '%'}
  984. style={{
  985. transition: 'all 30s ease-out',
  986. }}
  987. />
  988. </div>
  989. </div>
  990. <div
  991. className="TraceRightColumn"
  992. style={{
  993. width: props.viewManager.columns.span_list.width * 100 + '%',
  994. backgroundColor:
  995. props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
  996. }}
  997. >
  998. <Placeholder
  999. className="Placeholder"
  1000. height="12px"
  1001. width={randomBetween(20, 80) + '%'}
  1002. style={{
  1003. transition: 'all 30s ease-out',
  1004. transform: `translate(${randomBetween(0, 200) + 'px'}, 0)`,
  1005. }}
  1006. />
  1007. </div>
  1008. </div>
  1009. );
  1010. }
  1011. function randomBetween(min: number, max: number) {
  1012. return Math.floor(Math.random() * (max - min + 1) + min);
  1013. }
  1014. function Connectors(props: {
  1015. node: TraceTreeNode<TraceTree.NodeValue>;
  1016. viewManager: VirtualizedViewManager;
  1017. }) {
  1018. const showVerticalConnector =
  1019. ((props.node.expanded || props.node.zoomedIn) && props.node.children.length > 0) ||
  1020. (props.node.value && isParentAutogroupedNode(props.node));
  1021. // If the tail node of the collapsed node has no children,
  1022. // we don't want to render the vertical connector as no children
  1023. // are being rendered as the chain is entirely collapsed
  1024. const hideVerticalConnector =
  1025. showVerticalConnector &&
  1026. props.node.value &&
  1027. props.node instanceof ParentAutogroupNode &&
  1028. !props.node.tail.children.length;
  1029. return (
  1030. <Fragment>
  1031. {/*
  1032. @TODO count of rendered connectors could be % 3 as we can
  1033. have up to 3 connectors per node, 1 div, 1 before and 1 after
  1034. */}
  1035. {props.node.connectors.map((c, i) => {
  1036. return (
  1037. <div
  1038. key={i}
  1039. style={{
  1040. left: -(
  1041. Math.abs(Math.abs(c) - props.node.depth) *
  1042. props.viewManager.row_depth_padding
  1043. ),
  1044. }}
  1045. data-connector={c}
  1046. className={`TraceVerticalConnector ${c < 0 ? 'Orphaned' : ''}`}
  1047. />
  1048. );
  1049. })}
  1050. {showVerticalConnector && !hideVerticalConnector ? (
  1051. <div className="TraceExpandedVerticalConnector" />
  1052. ) : null}
  1053. {props.node.isLastChild ? (
  1054. <div className="TraceVerticalLastChildConnector" />
  1055. ) : (
  1056. <div className="TraceVerticalConnector" />
  1057. )}
  1058. </Fragment>
  1059. );
  1060. }
  1061. function ProjectBadge(props: {project: Project}) {
  1062. return <ProjectAvatar project={props.project} />;
  1063. }
  1064. function ChildrenCountButton(props: {
  1065. children: React.ReactNode;
  1066. expanded: boolean;
  1067. onClick: (e: React.MouseEvent) => void;
  1068. }) {
  1069. return (
  1070. <button className="TraceChildrenCount" onClick={props.onClick}>
  1071. {props.children}
  1072. <IconChevron
  1073. size="xs"
  1074. direction={props.expanded ? 'up' : 'down'}
  1075. style={{marginLeft: 2}}
  1076. />
  1077. </button>
  1078. );
  1079. }
  1080. interface TraceBarProps {
  1081. color: string;
  1082. node_space: [number, number] | null;
  1083. viewManager: VirtualizedViewManager;
  1084. virtualizedIndex: number;
  1085. duration?: number;
  1086. }
  1087. type SiblingAutogroupedBarProps = Omit<TraceBarProps, 'node_space' | 'duration'> & {
  1088. node: TraceTreeNode<TraceTree.NodeValue>;
  1089. };
  1090. // Render collapsed representation of sibling autogrouping, using multiple bars for when
  1091. // there are gaps between siblings.
  1092. function SiblingAutogroupedBar(props: SiblingAutogroupedBarProps) {
  1093. const bars: React.ReactNode[] = [];
  1094. // Start and end represents the earliest start_timestamp and the latest
  1095. // end_timestamp for a set of overlapping siblings.
  1096. let start = isSpanNode(props.node.children[0])
  1097. ? props.node.children[0].value.start_timestamp
  1098. : Number.POSITIVE_INFINITY;
  1099. let end = isSpanNode(props.node.children[0])
  1100. ? props.node.children[0].value.timestamp
  1101. : Number.NEGATIVE_INFINITY;
  1102. let totalDuration = 0;
  1103. for (let i = 0; i < props.node.children.length; i++) {
  1104. const node = props.node.children[i];
  1105. if (!isSpanNode(node)) {
  1106. throw new TypeError('Invalid type of autogrouped child');
  1107. }
  1108. const hasGap = node.value.start_timestamp > end;
  1109. if (!(hasGap || node.isLastChild)) {
  1110. start = Math.min(start, node.value.start_timestamp);
  1111. end = Math.max(end, node.value.timestamp);
  1112. continue;
  1113. }
  1114. // Render a bar for already collapsed set.
  1115. totalDuration += end - start;
  1116. bars.push(
  1117. <TraceBar
  1118. virtualizedIndex={props.virtualizedIndex}
  1119. viewManager={props.viewManager}
  1120. color={props.color}
  1121. node_space={[start, end - start]}
  1122. duration={!hasGap ? totalDuration : undefined}
  1123. />
  1124. );
  1125. if (hasGap) {
  1126. // Start a new set.
  1127. start = node.value.start_timestamp;
  1128. end = node.value.timestamp;
  1129. // Render a bar if the sibling with a gap is the last sibling.
  1130. if (node.isLastChild) {
  1131. totalDuration += end - start;
  1132. bars.push(
  1133. <TraceBar
  1134. virtualizedIndex={props.virtualizedIndex}
  1135. viewManager={props.viewManager}
  1136. color={props.color}
  1137. duration={totalDuration}
  1138. node_space={[start, end - start]}
  1139. />
  1140. );
  1141. }
  1142. }
  1143. }
  1144. return <Fragment>{bars}</Fragment>;
  1145. }
  1146. function TraceBar(props: TraceBarProps) {
  1147. if (!props.node_space) {
  1148. return null;
  1149. }
  1150. const duration = getDuration(props.node_space[1] / 1000, 2, true);
  1151. const spanTransform = props.viewManager.computeSpanCSSMatrixTransform(props.node_space);
  1152. const [inside, textTransform] = props.viewManager.computeSpanTextPlacement(
  1153. props.node_space,
  1154. duration
  1155. );
  1156. return (
  1157. <Fragment>
  1158. <div
  1159. ref={r =>
  1160. props.viewManager.registerSpanBarRef(
  1161. r,
  1162. props.node_space!,
  1163. props.virtualizedIndex
  1164. )
  1165. }
  1166. className="TraceBar"
  1167. style={{
  1168. transform: `matrix(${spanTransform.join(',')})`,
  1169. backgroundColor: props.color,
  1170. }}
  1171. onDoubleClick={e => {
  1172. e.stopPropagation();
  1173. props.viewManager.onZoomIntoSpace(props.node_space!);
  1174. }}
  1175. />
  1176. <div
  1177. ref={r =>
  1178. props.viewManager.registerSpanBarTextRef(
  1179. r,
  1180. duration,
  1181. props.node_space!,
  1182. props.virtualizedIndex
  1183. )
  1184. }
  1185. className="TraceBarDuration"
  1186. style={{
  1187. color: inside ? 'white' : '',
  1188. transform: `translate(${textTransform ?? 0}px, 0)`,
  1189. }}
  1190. >
  1191. {duration}
  1192. </div>
  1193. </Fragment>
  1194. );
  1195. }
  1196. /**
  1197. * This is a wrapper around the Trace component to apply styles
  1198. * to the trace tree. It exists because we _do not_ want to trigger
  1199. * emotion's css parsing logic as it is very slow and will cause
  1200. * the scrolling to flicker.
  1201. */
  1202. const TraceStylingWrapper = styled('div')`
  1203. overflow: hidden;
  1204. position: relative;
  1205. box-shadow: 0 0 0 1px ${p => p.theme.border};
  1206. border-radius: ${space(0.5)};
  1207. padding-top: 24px;
  1208. &:before {
  1209. content: '';
  1210. position: absolute;
  1211. left: 0;
  1212. top: 0;
  1213. width: 100%;
  1214. height: 22px;
  1215. background-color: ${p => p.theme.backgroundSecondary};
  1216. border-bottom: 1px solid ${p => p.theme.border};
  1217. }
  1218. .IconZoom {
  1219. height: 16px;
  1220. width: 18px;
  1221. background: ${p => p.theme.background};
  1222. padding: 1px;
  1223. border: 1px solid ${p => p.theme.border};
  1224. border-radius: ${space(0.5)};
  1225. position: absolute;
  1226. right: ${space(0.5)};
  1227. }
  1228. &.Loading {
  1229. .TraceRow {
  1230. .TraceLeftColumnInner {
  1231. width: 100%;
  1232. }
  1233. }
  1234. .TraceRightColumn {
  1235. background-color: transparent !important;
  1236. }
  1237. .TraceDivider {
  1238. pointer-events: none;
  1239. }
  1240. }
  1241. .TraceIndicatorContainer {
  1242. overflow: hidden;
  1243. width: 100%;
  1244. height: 100%;
  1245. position: absolute;
  1246. right: 0;
  1247. top: 0;
  1248. }
  1249. .TraceIndicator {
  1250. z-index: 1;
  1251. width: 3px;
  1252. height: 100%;
  1253. top: 0;
  1254. position: absolute;
  1255. .TraceIndicatorLabel {
  1256. min-width: 34px;
  1257. text-align: center;
  1258. position: absolute;
  1259. font-size: ${p => p.theme.fontSizeExtraSmall};
  1260. font-weight: bold;
  1261. color: ${p => p.theme.textColor};
  1262. background-color: ${p => p.theme.background};
  1263. border-radius: ${p => p.theme.borderRadius};
  1264. border: 1px solid ${p => p.theme.border};
  1265. padding: ${space(0.25)};
  1266. display: inline-block;
  1267. line-height: 1;
  1268. margin-top: 2px;
  1269. white-space: nowrap;
  1270. }
  1271. .TraceIndicatorLine {
  1272. width: 1px;
  1273. height: 100%;
  1274. top: 20px;
  1275. position: absolute;
  1276. left: 50%;
  1277. transform: translateX(-2px);
  1278. background: repeating-linear-gradient(
  1279. to bottom,
  1280. transparent 0 4px,
  1281. ${p => p.theme.textColor} 4px 8px
  1282. )
  1283. 80%/2px 100% no-repeat;
  1284. }
  1285. }
  1286. .TraceRow {
  1287. display: flex;
  1288. align-items: center;
  1289. position: absolute;
  1290. width: 100%;
  1291. transition: none;
  1292. font-size: ${p => p.theme.fontSizeSmall};
  1293. .Errored {
  1294. color: ${p => p.theme.error};
  1295. }
  1296. .Link {
  1297. &:hover {
  1298. color: ${p => p.theme.blue300};
  1299. }
  1300. }
  1301. .ErrorIconBorder {
  1302. position: absolute;
  1303. margin: ${space(0.25)};
  1304. left: -12px;
  1305. background: ${p => p.theme.background};
  1306. width: ${space(3)};
  1307. height: ${space(3)};
  1308. border: 1px solid ${p => p.theme.error};
  1309. border-radius: 50%;
  1310. display: flex;
  1311. align-items: center;
  1312. justify-content: center;
  1313. }
  1314. &:hover {
  1315. background-color: ${p => p.theme.backgroundSecondary};
  1316. }
  1317. &:focus {
  1318. transition: none;
  1319. background-color: ${p => p.theme.backgroundTertiary};
  1320. outline: none;
  1321. }
  1322. &.Autogrouped {
  1323. color: ${p => p.theme.blue300};
  1324. .TraceDescription {
  1325. font-weight: bold;
  1326. }
  1327. .TraceChildrenCountWrapper {
  1328. button {
  1329. color: ${p => p.theme.white};
  1330. background-color: ${p => p.theme.blue300};
  1331. }
  1332. }
  1333. }
  1334. }
  1335. .TraceLeftColumn {
  1336. height: 100%;
  1337. white-space: nowrap;
  1338. display: flex;
  1339. align-items: center;
  1340. overflow: hidden;
  1341. will-change: width;
  1342. position: relative;
  1343. .TraceLeftColumnInner {
  1344. height: 100%;
  1345. white-space: nowrap;
  1346. display: flex;
  1347. align-items: center;
  1348. will-change: transform;
  1349. transform-origin: left center;
  1350. transform: translateX(var(--column-translate-x));
  1351. }
  1352. }
  1353. .TraceRightColumn {
  1354. height: 100%;
  1355. overflow: hidden;
  1356. position: relative;
  1357. display: flex;
  1358. align-items: center;
  1359. will-change: width;
  1360. z-index: 1;
  1361. }
  1362. .TraceBar {
  1363. position: absolute;
  1364. height: 64%;
  1365. width: 100%;
  1366. background-color: black;
  1367. transform-origin: left center;
  1368. }
  1369. .TraceBarDuration {
  1370. display: inline-block;
  1371. transform-origin: left center;
  1372. font-size: ${p => p.theme.fontSizeExtraSmall};
  1373. color: ${p => p.theme.gray300};
  1374. white-space: nowrap;
  1375. font-variant-numeric: tabular-nums;
  1376. position: absolute;
  1377. transition: color 0.1s ease-in-out;
  1378. }
  1379. .TraceChildrenCount {
  1380. height: 16px;
  1381. white-space: nowrap;
  1382. min-width: 30px;
  1383. display: flex;
  1384. align-items: center;
  1385. justify-content: center;
  1386. border-radius: 99px;
  1387. padding: 0px ${space(0.5)};
  1388. transition: all 0.15s ease-in-out;
  1389. background: ${p => p.theme.background};
  1390. border: 2px solid ${p => p.theme.border};
  1391. line-height: 0;
  1392. z-index: 1;
  1393. font-size: 10px;
  1394. box-shadow: ${p => p.theme.dropShadowLight};
  1395. margin-right: ${space(1)};
  1396. svg {
  1397. width: 7px;
  1398. transition: none;
  1399. }
  1400. }
  1401. .TraceChildrenCountWrapper {
  1402. display: flex;
  1403. justify-content: flex-end;
  1404. align-items: center;
  1405. min-width: 44px;
  1406. height: 100%;
  1407. position: relative;
  1408. button {
  1409. transition: none;
  1410. }
  1411. &.Orphaned {
  1412. .TraceVerticalConnector,
  1413. .TraceVerticalLastChildConnector,
  1414. .TraceExpandedVerticalConnector {
  1415. border-left: 2px dashed ${p => p.theme.border};
  1416. }
  1417. &::before {
  1418. border-bottom: 2px dashed ${p => p.theme.border};
  1419. }
  1420. }
  1421. &.Root {
  1422. &:before,
  1423. .TraceVerticalLastChildConnector {
  1424. visibility: hidden;
  1425. }
  1426. }
  1427. &::before {
  1428. content: '';
  1429. display: block;
  1430. width: 50%;
  1431. height: 2px;
  1432. border-bottom: 2px solid ${p => p.theme.border};
  1433. position: absolute;
  1434. left: 0;
  1435. top: 50%;
  1436. transform: translateY(-50%);
  1437. }
  1438. &::after {
  1439. content: '';
  1440. background-color: ${p => p.theme.border};
  1441. border-radius: 50%;
  1442. height: 6px;
  1443. width: 6px;
  1444. position: absolute;
  1445. left: 50%;
  1446. top: 50%;
  1447. transform: translateY(-50%);
  1448. }
  1449. }
  1450. .TraceVerticalConnector {
  1451. position: absolute;
  1452. left: 0;
  1453. top: 0;
  1454. bottom: 0;
  1455. height: 100%;
  1456. width: 2px;
  1457. border-left: 2px solid ${p => p.theme.border};
  1458. &.Orphaned {
  1459. border-left: 2px dashed ${p => p.theme.border};
  1460. }
  1461. }
  1462. .TraceVerticalLastChildConnector {
  1463. position: absolute;
  1464. left: 0;
  1465. top: 0;
  1466. bottom: 0;
  1467. height: 50%;
  1468. width: 2px;
  1469. border-left: 2px solid ${p => p.theme.border};
  1470. border-bottom-left-radius: 4px;
  1471. }
  1472. .TraceExpandedVerticalConnector {
  1473. position: absolute;
  1474. bottom: 0;
  1475. height: 50%;
  1476. left: 50%;
  1477. width: 2px;
  1478. border-left: 2px solid ${p => p.theme.border};
  1479. }
  1480. .TraceOperation {
  1481. margin-left: ${space(0.5)};
  1482. text-overflow: ellipsis;
  1483. white-space: nowrap;
  1484. font-weight: bold;
  1485. }
  1486. .TraceEmDash {
  1487. margin-left: ${space(0.5)};
  1488. margin-right: ${space(0.5)};
  1489. }
  1490. .TraceDescription {
  1491. white-space: nowrap;
  1492. }
  1493. `;
  1494. const LoadingContainer = styled('div')`
  1495. display: flex;
  1496. justify-content: center;
  1497. align-items: center;
  1498. flex-direction: column;
  1499. left: 50%;
  1500. top: 50%;
  1501. transform: translate(-50%, -50%);
  1502. position: absolute;
  1503. height: auto;
  1504. font-size: ${p => p.theme.fontSizeMedium};
  1505. color: ${p => p.theme.gray300};
  1506. z-index: 30;
  1507. padding: 24px;
  1508. background-color: ${p => p.theme.background};
  1509. border-radius: ${p => p.theme.borderRadius};
  1510. border: 1px solid ${p => p.theme.border};
  1511. `;
  1512. function TraceLoading() {
  1513. return (
  1514. <LoadingContainer>
  1515. <NoMarginIndicator size={24}>
  1516. <div>{t('Assembling the trace')}</div>
  1517. </NoMarginIndicator>
  1518. </LoadingContainer>
  1519. );
  1520. }
  1521. const NoMarginIndicator = styled(LoadingIndicator)`
  1522. margin: 0;
  1523. `;