trace.tsx 45 KB

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