trace.tsx 44 KB

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