trace.tsx 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386
  1. import type React from 'react';
  2. import {
  3. Fragment,
  4. useCallback,
  5. useEffect,
  6. useLayoutEffect,
  7. useMemo,
  8. useRef,
  9. useState,
  10. } from 'react';
  11. import {browserHistory} from 'react-router';
  12. import {type Theme, useTheme} from '@emotion/react';
  13. import styled from '@emotion/styled';
  14. import * as Sentry from '@sentry/react';
  15. import {PlatformIcon} from 'platformicons';
  16. import * as qs from 'query-string';
  17. import LoadingIndicator from 'sentry/components/loadingIndicator';
  18. import Placeholder from 'sentry/components/placeholder';
  19. import {t} from 'sentry/locale';
  20. import type {Organization, PlatformKey, Project} from 'sentry/types';
  21. import {getDuration} from 'sentry/utils/formatters';
  22. import type {
  23. TraceError,
  24. TracePerformanceIssue,
  25. } from 'sentry/utils/performance/quickTrace/types';
  26. import {clamp} from 'sentry/utils/profiling/colors/utils';
  27. import useApi from 'sentry/utils/useApi';
  28. import useOrganization from 'sentry/utils/useOrganization';
  29. import useProjects from 'sentry/utils/useProjects';
  30. import {
  31. getRovingIndexActionFromEvent,
  32. type RovingTabIndexAction,
  33. type RovingTabIndexUserActions,
  34. } from 'sentry/views/performance/newTraceDetails/rovingTabIndex';
  35. import type {
  36. TraceSearchAction,
  37. TraceSearchState,
  38. } from 'sentry/views/performance/newTraceDetails/traceSearch';
  39. import {
  40. isAutogroupedNode,
  41. isMissingInstrumentationNode,
  42. isParentAutogroupedNode,
  43. isSpanNode,
  44. isTraceErrorNode,
  45. isTraceNode,
  46. isTransactionNode,
  47. } from './guards';
  48. import {
  49. makeTraceNodeBarColor,
  50. ParentAutogroupNode,
  51. type TraceTree,
  52. type TraceTreeNode,
  53. } from './traceTree';
  54. import {
  55. useVirtualizedList,
  56. type VirtualizedRow,
  57. type VirtualizedViewManager,
  58. } from './virtualizedViewManager';
  59. function Chevron(props: {direction: 'up' | 'down' | 'left'}) {
  60. return (
  61. <svg
  62. viewBox="0 0 16 16"
  63. style={{
  64. transition: 'transform 120ms ease-in-out',
  65. transform: `rotate(${props.direction === 'up' ? 0 : props.direction === 'down' ? 180 : -90}deg)`,
  66. }}
  67. >
  68. <path d="M14,11.75a.74.74,0,0,1-.53-.22L8,6.06,2.53,11.53a.75.75,0,0,1-1.06-1.06l6-6a.75.75,0,0,1,1.06,0l6,6a.75.75,0,0,1,0,1.06A.74.74,0,0,1,14,11.75Z" />
  69. </svg>
  70. );
  71. }
  72. function Fire() {
  73. return (
  74. <svg viewBox="0 0 16 16">
  75. <path d="M8.08,15.92A6.58,6.58,0,0,1,1.51,9.34a4.88,4.88,0,0,1,2.2-4.25.74.74,0,0,1,1,.34,6,6,0,0,1,4-5.3A.74.74,0,0,1,9.4.22a.73.73,0,0,1,.33.61v.31A15.07,15.07,0,0,0,10,4.93a3.72,3.72,0,0,1,2.3-1.7.74.74,0,0,1,.66.12.75.75,0,0,1,.3.6A6.21,6.21,0,0,0,14,6.79a5.78,5.78,0,0,1,.68,2.55A6.58,6.58,0,0,1,8.08,15.92ZM3.59,7.23A4.25,4.25,0,0,0,3,9.34a5.07,5.07,0,1,0,10.14,0,4.6,4.6,0,0,0-.54-1.94,8,8,0,0,1-.76-2.32A2,2,0,0,0,11.07,7a.75.75,0,0,1-1.32.58C8.4,6,8.25,4.22,8.23,2c-2,1.29-2.15,3.58-2.09,5.85A7.52,7.52,0,0,1,6.14,9a.74.74,0,0,1-.46.63.77.77,0,0,1-.76-.11A4.56,4.56,0,0,1,3.59,7.23Z" />
  76. </svg>
  77. );
  78. }
  79. function Profile() {
  80. return (
  81. <svg viewBox="0 0 20 16">
  82. <path d="M15.25,0H.75C.33,0,0,.34,0,.75V5.59c0,.41,.34,.75,.75,.75h1.49v4.09c0,.41,.34,.75,.75,.75h1.73v4.09c0,.41,.34,.75,.75,.75h5.06c.41,0,.75-.34,.75-.75v-4.09h1.73c.41,0,.75-.34,.75-.75V6.34h1.49c.41,0,.75-.34,.75-.75V.75c0-.41-.34-.75-.75-.75Zm-5.47,14.52h-3.56v-3.34h3.56v3.34Zm2.48-4.84H3.74v-3.34H12.25v3.34Zm2.24-4.84H1.5V1.5H14.5v3.34Z" />
  83. </svg>
  84. );
  85. }
  86. function decodeScrollQueue(maybePath: unknown): TraceTree.NodePath[] | null {
  87. if (Array.isArray(maybePath)) {
  88. return maybePath;
  89. }
  90. if (typeof maybePath === 'string') {
  91. return [maybePath as TraceTree.NodePath];
  92. }
  93. return null;
  94. }
  95. const COUNT_FORMATTER = Intl.NumberFormat(undefined, {notation: 'compact'});
  96. const NO_ERRORS = [];
  97. interface RovingTabIndexState {
  98. index: number | null;
  99. items: number | null;
  100. node: TraceTreeNode<TraceTree.NodeValue> | null;
  101. }
  102. function computeNextIndexFromAction(
  103. current_index: number,
  104. action: RovingTabIndexUserActions,
  105. items: number
  106. ): number {
  107. switch (action) {
  108. case 'next':
  109. if (current_index === items) {
  110. return 0;
  111. }
  112. return current_index + 1;
  113. case 'previous':
  114. if (current_index === 0) {
  115. return items;
  116. }
  117. return current_index - 1;
  118. case 'last':
  119. return items;
  120. case 'first':
  121. return 0;
  122. default:
  123. throw new TypeError(`Invalid or not implemented reducer action - ${action}`);
  124. }
  125. }
  126. function maybeFocusRow(
  127. ref: HTMLDivElement | null,
  128. index: number,
  129. previouslyFocusedIndexRef: React.MutableRefObject<number | null>
  130. ) {
  131. if (!ref) return;
  132. if (index === previouslyFocusedIndexRef.current) return;
  133. ref.focus();
  134. previouslyFocusedIndexRef.current = index;
  135. }
  136. interface TraceProps {
  137. manager: VirtualizedViewManager;
  138. onRowClick: (
  139. node: TraceTreeNode<TraceTree.NodeValue> | null,
  140. event: React.MouseEvent<HTMLElement> | null
  141. ) => void;
  142. onTraceSearch: (query: string) => void;
  143. previouslyFocusedIndexRef: React.MutableRefObject<number | null>;
  144. roving_dispatch: React.Dispatch<RovingTabIndexAction>;
  145. roving_state: RovingTabIndexState;
  146. scrollQueueRef: React.MutableRefObject<{
  147. eventId?: string;
  148. path?: TraceTree.NodePath[];
  149. } | null>;
  150. searchResultsIteratorIndex: number | undefined;
  151. searchResultsMap: Map<TraceTreeNode<TraceTree.NodeValue>, number>;
  152. search_dispatch: React.Dispatch<TraceSearchAction>;
  153. search_state: TraceSearchState;
  154. trace: TraceTree;
  155. trace_id: string;
  156. }
  157. function Trace({
  158. trace,
  159. trace_id,
  160. roving_state,
  161. roving_dispatch,
  162. search_state,
  163. search_dispatch,
  164. onRowClick,
  165. manager,
  166. scrollQueueRef,
  167. searchResultsIteratorIndex,
  168. searchResultsMap,
  169. previouslyFocusedIndexRef,
  170. onTraceSearch,
  171. }: TraceProps) {
  172. const theme = useTheme();
  173. const api = useApi();
  174. const {projects} = useProjects();
  175. const organization = useOrganization();
  176. const containerRef = useRef<HTMLDivElement | null>(null);
  177. const [_rerender, setRender] = useState(0);
  178. const treePromiseStatusRef =
  179. useRef<Map<TraceTreeNode<TraceTree.NodeValue>, 'loading' | 'error' | 'success'>>();
  180. if (!treePromiseStatusRef.current) {
  181. treePromiseStatusRef.current = new Map();
  182. }
  183. const treeRef = useRef<TraceTree>(trace);
  184. treeRef.current = trace;
  185. if (
  186. trace.root.space &&
  187. (trace.root.space[0] !== manager.to_origin ||
  188. trace.root.space[1] !== manager.trace_space.width)
  189. ) {
  190. manager.initializeTraceSpace([trace.root.space[0], 0, trace.root.space[1], 1]);
  191. const maybeQueue = decodeScrollQueue(qs.parse(location.search).node);
  192. const maybeEventId = qs.parse(location.search)?.eventId;
  193. if (maybeQueue || maybeEventId) {
  194. scrollQueueRef.current = {
  195. eventId: maybeEventId as string,
  196. path: maybeQueue as TraceTreeNode<TraceTree.NodeValue>['path'],
  197. };
  198. }
  199. }
  200. const loadedRef = useRef(false);
  201. useEffect(() => {
  202. if (loadedRef.current) {
  203. return;
  204. }
  205. if (trace.type !== 'trace' || !manager) {
  206. return;
  207. }
  208. loadedRef.current = true;
  209. if (!scrollQueueRef.current) {
  210. if (search_state.query) {
  211. onTraceSearch(search_state.query);
  212. }
  213. return;
  214. }
  215. // Node path has higher specificity than eventId
  216. const promise = scrollQueueRef.current?.path
  217. ? manager.scrollToPath(
  218. trace,
  219. scrollQueueRef.current.path,
  220. () => setRender(a => (a + 1) % 2),
  221. {
  222. api,
  223. organization,
  224. }
  225. )
  226. : scrollQueueRef.current.eventId
  227. ? manager.scrollToEventID(
  228. scrollQueueRef?.current?.eventId,
  229. trace,
  230. () => setRender(a => (a + 1) % 2),
  231. {
  232. api,
  233. organization,
  234. }
  235. )
  236. : Promise.resolve(null);
  237. promise.then(maybeNode => {
  238. // Important to set scrollQueueRef.current to null and trigger a rerender
  239. // after the promise resolves as we show a loading state during scroll,
  240. // else the screen could jump around while we fetch span data
  241. scrollQueueRef.current = null;
  242. if (!maybeNode) {
  243. Sentry.captureMessage('Failled to find and scroll to node in tree');
  244. return;
  245. }
  246. if (maybeNode.node.space) {
  247. manager.animateViewTo(maybeNode.node.space);
  248. }
  249. onRowClick(maybeNode.node, null);
  250. roving_dispatch({
  251. type: 'set index',
  252. index: maybeNode.index,
  253. node: maybeNode.node,
  254. });
  255. manager.list?.scrollToRow(maybeNode.index, 'top');
  256. manager.scrollRowIntoViewHorizontally(maybeNode.node, 0, 12, 'exact');
  257. if (search_state.query) {
  258. onTraceSearch(search_state.query);
  259. }
  260. });
  261. }, [
  262. api,
  263. scrollQueueRef,
  264. organization,
  265. trace,
  266. trace_id,
  267. manager,
  268. search_state.query,
  269. onTraceSearch,
  270. onRowClick,
  271. roving_dispatch,
  272. ]);
  273. const previousSearchResultIndexRef = useRef<number | undefined>(
  274. search_state.resultIndex
  275. );
  276. useLayoutEffect(() => {
  277. if (previousSearchResultIndexRef.current === search_state.resultIndex) {
  278. return;
  279. }
  280. if (!manager.list) {
  281. return;
  282. }
  283. if (typeof search_state.resultIndex !== 'number') {
  284. return;
  285. }
  286. manager.scrollToRow(search_state.resultIndex);
  287. if (previousSearchResultIndexRef.current === undefined) {
  288. return;
  289. }
  290. const previousNode = treeRef.current.list[previousSearchResultIndexRef.current!];
  291. previousSearchResultIndexRef.current = search_state.resultIndex;
  292. if (previousNode) {
  293. const nextNode = treeRef.current.list[search_state.resultIndex];
  294. const offset =
  295. nextNode.depth >= previousNode.depth ? manager.trace_physical_space.width / 2 : 0;
  296. if (
  297. manager.isOutsideOfViewOnKeyDown(
  298. treeRef.current.list[search_state.resultIndex],
  299. offset
  300. )
  301. ) {
  302. manager.scrollRowIntoViewHorizontally(
  303. treeRef.current.list[search_state.resultIndex],
  304. 0,
  305. offset,
  306. 'measured'
  307. );
  308. }
  309. }
  310. }, [search_state.resultIndex, manager]);
  311. const handleZoomIn = useCallback(
  312. (
  313. event: React.MouseEvent,
  314. node: TraceTreeNode<TraceTree.NodeValue>,
  315. value: boolean
  316. ) => {
  317. if (!isTransactionNode(node) && !isSpanNode(node)) {
  318. throw new TypeError('Node must be a transaction or span');
  319. }
  320. event.stopPropagation();
  321. setRender(a => (a + 1) % 2);
  322. treeRef.current
  323. .zoomIn(node, value, {
  324. api,
  325. organization,
  326. })
  327. .then(() => {
  328. setRender(a => (a + 1) % 2);
  329. if (search_state.query) {
  330. onTraceSearch(search_state.query);
  331. }
  332. if (search_state.resultsLookup.has(node)) {
  333. const idx = search_state.resultsLookup.get(node)!;
  334. search_dispatch({
  335. type: 'set iterator index',
  336. resultIndex: search_state.results?.[idx]?.index!,
  337. resultIteratorIndex: idx,
  338. });
  339. } else {
  340. search_dispatch({type: 'clear iterator index'});
  341. }
  342. treePromiseStatusRef.current!.set(node, 'success');
  343. })
  344. .catch(_e => {
  345. treePromiseStatusRef.current!.set(node, 'error');
  346. });
  347. },
  348. [api, organization, search_state, search_dispatch, onTraceSearch]
  349. );
  350. const handleExpandNode = useCallback(
  351. (
  352. event: React.MouseEvent<Element>,
  353. node: TraceTreeNode<TraceTree.NodeValue>,
  354. value: boolean
  355. ) => {
  356. event.stopPropagation();
  357. treeRef.current.expand(node, value);
  358. setRender(a => (a + 1) % 2);
  359. if (search_state.query) {
  360. onTraceSearch(search_state.query);
  361. }
  362. if (search_state.resultsLookup.has(node)) {
  363. const idx = search_state.resultsLookup.get(node)!;
  364. search_dispatch({
  365. type: 'set iterator index',
  366. resultIndex: search_state.results?.[idx]?.index!,
  367. resultIteratorIndex: idx,
  368. });
  369. } else {
  370. search_dispatch({type: 'clear iterator index'});
  371. }
  372. },
  373. [search_state, search_dispatch, onTraceSearch]
  374. );
  375. const onVirtulizedRowClick = useCallback(
  376. (
  377. event: React.MouseEvent<HTMLElement>,
  378. index: number,
  379. node: TraceTreeNode<TraceTree.NodeValue>
  380. ) => {
  381. previousSearchResultIndexRef.current = index;
  382. previouslyFocusedIndexRef.current = index;
  383. const {eventId: _eventId, ...query} = qs.parse(location.search);
  384. browserHistory.replace({
  385. pathname: location.pathname,
  386. query: {
  387. ...query,
  388. node: node.path,
  389. },
  390. });
  391. onRowClick(node, event);
  392. roving_dispatch({type: 'set index', index, node});
  393. if (search_state.resultsLookup.has(node)) {
  394. const idx = search_state.resultsLookup.get(node)!;
  395. search_dispatch({
  396. type: 'set iterator index',
  397. resultIndex: index,
  398. resultIteratorIndex: idx,
  399. });
  400. } else {
  401. search_dispatch({type: 'clear iterator index'});
  402. }
  403. },
  404. [
  405. roving_dispatch,
  406. onRowClick,
  407. search_state,
  408. search_dispatch,
  409. previouslyFocusedIndexRef,
  410. previousSearchResultIndexRef,
  411. ]
  412. );
  413. const onRowKeyDown = useCallback(
  414. (
  415. event: React.KeyboardEvent,
  416. index: number,
  417. node: TraceTreeNode<TraceTree.NodeValue>
  418. ) => {
  419. if (!manager.list) {
  420. return;
  421. }
  422. const action = getRovingIndexActionFromEvent(event);
  423. if (action) {
  424. event.preventDefault();
  425. const nextIndex = computeNextIndexFromAction(
  426. index,
  427. action,
  428. treeRef.current.list.length - 1
  429. );
  430. manager.scrollToRow(nextIndex);
  431. roving_dispatch({type: 'set index', index: nextIndex, node});
  432. const nextNode = treeRef.current.list[nextIndex];
  433. const offset =
  434. nextNode.depth >= node.depth ? manager.trace_physical_space.width / 2 : 0;
  435. if (manager.isOutsideOfViewOnKeyDown(trace.list[nextIndex], offset)) {
  436. manager.scrollRowIntoViewHorizontally(trace.list[nextIndex], 0, offset);
  437. }
  438. if (search_state.resultsLookup.has(trace.list[nextIndex])) {
  439. const idx = search_state.resultsLookup.get(trace.list[nextIndex])!;
  440. search_dispatch({
  441. type: 'set iterator index',
  442. resultIndex: nextIndex,
  443. resultIteratorIndex: idx,
  444. });
  445. } else {
  446. search_dispatch({type: 'clear iterator index'});
  447. }
  448. }
  449. },
  450. [manager, roving_dispatch, search_state, search_dispatch, trace.list]
  451. );
  452. // @TODO this is the implementation of infinite scroll. Once the user
  453. // reaches the end of the list, we fetch more data. The data is not yet
  454. // being appended to the tree as we need to figure out UX for this.
  455. // onRowsRendered callback should be passed to the List component
  456. // const limitRef = useRef<number | null>(null);
  457. // if (limitRef.current === null) {
  458. // let decodedLimit = getTraceQueryParams(qs.parse(location.search)).limit;
  459. // if (typeof decodedLimit === 'string') {
  460. // decodedLimit = parseInt(decodedLimit, 2);
  461. // }
  462. // limitRef.current = decodedLimit;
  463. // }
  464. // const loadMoreRequestRef =
  465. // useRef<Promise<TraceSplitResults<TraceFullDetailed> | null> | null>(null);
  466. // const onRowsRendered = useCallback((rows: RenderedRows) => {
  467. // if (loadMoreRequestRef.current) {
  468. // // in flight request
  469. // return;
  470. // }
  471. // if (rows.stopIndex !== treeRef.current.list.length - 1) {
  472. // // not at the end
  473. // return;
  474. // }
  475. // if (
  476. // !loadMoreRequestRef.current &&
  477. // limitRef.current &&
  478. // rows.stopIndex === treeRef.current.list.length - 1
  479. // ) {
  480. // limitRef.current = limitRef.current + 500;
  481. // const promise = fetchTrace(api, {
  482. // traceId: trace_id,
  483. // orgSlug: organization.slug,
  484. // query: qs.stringify(getTraceQueryParams(location, {limit: limitRef.current})),
  485. // })
  486. // .then(data => {
  487. // return data;
  488. // })
  489. // .catch(e => {
  490. // return e;
  491. // });
  492. // loadMoreRequestRef.current = promise;
  493. // }
  494. // }, []);
  495. const projectLookup: Record<string, PlatformKey | undefined> = useMemo(() => {
  496. return projects.reduce<Record<Project['slug'], Project['platform']>>(
  497. (acc, project) => {
  498. acc[project.slug] = project.platform;
  499. return acc;
  500. },
  501. {}
  502. );
  503. }, [projects]);
  504. const render = useCallback(
  505. (n: VirtualizedRow) => {
  506. return trace.type !== 'trace' || scrollQueueRef.current ? (
  507. <RenderPlaceholderRow
  508. key={n.key}
  509. index={n.index}
  510. style={n.style}
  511. node={n.item}
  512. theme={theme}
  513. projects={projectLookup}
  514. manager={manager}
  515. />
  516. ) : (
  517. <RenderRow
  518. key={n.key}
  519. index={n.index}
  520. organization={organization}
  521. previouslyFocusedIndexRef={previouslyFocusedIndexRef}
  522. tabIndex={roving_state.index ?? -1}
  523. isSearchResult={searchResultsMap.has(n.item)}
  524. searchResultsIteratorIndex={searchResultsIteratorIndex}
  525. style={n.style}
  526. trace_id={trace_id}
  527. projects={projectLookup}
  528. node={n.item}
  529. manager={manager}
  530. theme={theme}
  531. onExpand={handleExpandNode}
  532. onZoomIn={handleZoomIn}
  533. onRowClick={onVirtulizedRowClick}
  534. onRowKeyDown={onRowKeyDown}
  535. />
  536. );
  537. },
  538. // we add _rerender as a dependency to trigger the virtualized list rerender
  539. // eslint-disable-next-line react-hooks/exhaustive-deps
  540. [
  541. handleExpandNode,
  542. handleZoomIn,
  543. manager,
  544. onVirtulizedRowClick,
  545. onRowKeyDown,
  546. organization,
  547. projectLookup,
  548. roving_state.index,
  549. searchResultsIteratorIndex,
  550. searchResultsMap,
  551. theme,
  552. trace_id,
  553. trace.type,
  554. _rerender,
  555. ]
  556. );
  557. const [scrollContainer, setScrollContainer] = useState<HTMLElement | null>(null);
  558. const virtualizedList = useVirtualizedList({
  559. manager,
  560. items: trace.list,
  561. container: scrollContainer,
  562. render,
  563. });
  564. return (
  565. <TraceStylingWrapper
  566. ref={r => {
  567. containerRef.current = r;
  568. manager.onContainerRef(r);
  569. }}
  570. className={`${trace.indicators.length > 0 ? 'WithIndicators' : ''} ${trace.type !== 'trace' || scrollQueueRef.current ? 'Loading' : ''}`}
  571. >
  572. <div className="TraceDivider" ref={r => manager?.registerDividerRef(r)} />
  573. <div
  574. className="TraceIndicatorContainer"
  575. ref={r => manager.registerIndicatorContainerRef(r)}
  576. >
  577. {trace.indicators.length > 0
  578. ? trace.indicators.map((indicator, i) => {
  579. return (
  580. <div
  581. key={i}
  582. ref={r => manager.registerIndicatorRef(r, i, indicator)}
  583. className="TraceIndicator"
  584. >
  585. <div className="TraceIndicatorLabel">{indicator.label}</div>
  586. <div className="TraceIndicatorLine" />
  587. </div>
  588. );
  589. })
  590. : null}
  591. {manager.interval_bars.map((_, i) => {
  592. const indicatorTimestamp = manager.intervals[i];
  593. const timestamp = manager.to_origin + indicatorTimestamp ?? 0;
  594. if (trace.type !== 'trace') {
  595. return null;
  596. }
  597. return (
  598. <div
  599. key={i}
  600. ref={r => manager.registerTimelineIndicatorRef(r, i)}
  601. className="TraceIndicator Timeline"
  602. style={{
  603. transform: `translate(${manager.computeTransformXFromTimestamp(timestamp)}px, 0)`,
  604. }}
  605. >
  606. <div className="TraceIndicatorLabel">
  607. {indicatorTimestamp > 0
  608. ? getDuration(
  609. (manager.trace_view.x + indicatorTimestamp) / 1000,
  610. 2,
  611. true
  612. )
  613. : '0s'}
  614. </div>
  615. <div className="TraceIndicatorLine" />
  616. </div>
  617. );
  618. })}
  619. </div>
  620. <div ref={r => setScrollContainer(r)}>
  621. <div>{virtualizedList.rendered}</div>
  622. </div>
  623. </TraceStylingWrapper>
  624. );
  625. }
  626. export default Trace;
  627. function RenderRow(props: {
  628. index: number;
  629. isSearchResult: boolean;
  630. manager: VirtualizedViewManager;
  631. node: TraceTreeNode<TraceTree.NodeValue>;
  632. onExpand: (
  633. event: React.MouseEvent<Element>,
  634. node: TraceTreeNode<TraceTree.NodeValue>,
  635. value: boolean
  636. ) => void;
  637. onRowClick: (
  638. event: React.MouseEvent<HTMLElement>,
  639. index: number,
  640. node: TraceTreeNode<TraceTree.NodeValue>
  641. ) => void;
  642. onRowKeyDown: (
  643. event: React.KeyboardEvent,
  644. index: number,
  645. node: TraceTreeNode<TraceTree.NodeValue>
  646. ) => void;
  647. onZoomIn: (
  648. event: React.MouseEvent<Element>,
  649. node: TraceTreeNode<TraceTree.NodeValue>,
  650. value: boolean
  651. ) => void;
  652. organization: Organization;
  653. previouslyFocusedIndexRef: React.MutableRefObject<number | null>;
  654. projects: Record<Project['slug'], Project['platform']>;
  655. searchResultsIteratorIndex: number | undefined;
  656. style: React.CSSProperties;
  657. tabIndex: number;
  658. theme: Theme;
  659. trace_id: string;
  660. }) {
  661. const virtualized_index = props.index - props.manager.start_virtualized_index;
  662. if (!props.node.value) {
  663. return null;
  664. }
  665. const rowSearchClassName = `${props.isSearchResult ? 'SearchResult' : ''} ${props.searchResultsIteratorIndex === props.index ? 'Highlight' : ''}`;
  666. if (isAutogroupedNode(props.node)) {
  667. return (
  668. <div
  669. key={props.index}
  670. ref={r =>
  671. props.tabIndex === props.index
  672. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  673. : null
  674. }
  675. tabIndex={props.tabIndex === props.index ? 0 : -1}
  676. className={`Autogrouped TraceRow ${rowSearchClassName} ${props.node.has_errors ? 'Errored' : ''}`}
  677. onClick={e => props.onRowClick(e, props.index, props.node)}
  678. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  679. style={{
  680. top: props.style.top,
  681. height: props.style.height,
  682. }}
  683. >
  684. <div
  685. className="TraceLeftColumn"
  686. ref={r =>
  687. props.manager.registerColumnRef('list', r, virtualized_index, props.node)
  688. }
  689. style={{
  690. width: props.manager.columns.list.width * 100 + '%',
  691. }}
  692. >
  693. <div
  694. className={`TraceLeftColumnInner`}
  695. style={{
  696. paddingLeft: props.node.depth * props.manager.row_depth_padding,
  697. }}
  698. >
  699. <div className="TraceChildrenCountWrapper">
  700. <Connectors node={props.node} manager={props.manager} />
  701. <ChildrenButton
  702. icon={
  703. props.node.expanded ? (
  704. <Chevron direction="up" />
  705. ) : (
  706. <Chevron direction="down" />
  707. )
  708. }
  709. status={props.node.fetchStatus}
  710. expanded={!props.node.expanded}
  711. onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
  712. errored={props.node.has_errors}
  713. >
  714. {COUNT_FORMATTER.format(props.node.groupCount)}
  715. </ChildrenButton>
  716. </div>
  717. <span className="TraceOperation">{t('Autogrouped')}</span>
  718. <strong className="TraceEmDash"> — </strong>
  719. <span className="TraceDescription">{props.node.value.autogrouped_by.op}</span>
  720. </div>
  721. </div>
  722. <div
  723. className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
  724. ref={r =>
  725. props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
  726. }
  727. style={{
  728. width: props.manager.columns.span_list.width * 100 + '%',
  729. }}
  730. onDoubleClick={e => {
  731. e.stopPropagation();
  732. props.manager.onZoomIntoSpace(props.node.space!);
  733. }}
  734. >
  735. <AutogroupedTraceBar
  736. virtualized_index={virtualized_index}
  737. manager={props.manager}
  738. color={makeTraceNodeBarColor(props.theme, props.node)}
  739. entire_space={props.node.space}
  740. node_spaces={props.node.autogroupedSegments}
  741. errors={props.node.errors}
  742. performance_issues={props.node.performance_issues}
  743. profiles={props.node.profiles}
  744. />
  745. <button
  746. ref={ref =>
  747. props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
  748. }
  749. className="TraceArrow"
  750. onClick={_e => {
  751. props.manager.onBringRowIntoView(props.node.space!);
  752. }}
  753. >
  754. <Chevron direction="left" />
  755. </button>
  756. </div>
  757. </div>
  758. );
  759. }
  760. if (isTransactionNode(props.node)) {
  761. const errored =
  762. props.node.value.errors.length > 0 ||
  763. props.node.value.performance_issues.length > 0;
  764. return (
  765. <div
  766. key={props.index}
  767. ref={r =>
  768. props.tabIndex === props.index
  769. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  770. : null
  771. }
  772. tabIndex={props.tabIndex === props.index ? 0 : -1}
  773. className={`TraceRow ${rowSearchClassName} ${errored ? 'Errored' : ''}`}
  774. onClick={e => props.onRowClick(e, props.index, props.node)}
  775. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  776. style={{
  777. top: props.style.top,
  778. height: props.style.height,
  779. }}
  780. >
  781. <div
  782. className="TraceLeftColumn"
  783. ref={r =>
  784. props.manager.registerColumnRef('list', r, virtualized_index, props.node)
  785. }
  786. style={{
  787. width: props.manager.columns.list.width * 100 + '%',
  788. }}
  789. >
  790. <div
  791. className={`TraceLeftColumnInner`}
  792. style={{
  793. paddingLeft: props.node.depth * props.manager.row_depth_padding,
  794. }}
  795. >
  796. <div
  797. className={`TraceChildrenCountWrapper ${
  798. props.node.isOrphaned ? 'Orphaned' : ''
  799. }
  800. `}
  801. >
  802. <Connectors node={props.node} manager={props.manager} />
  803. {props.node.children.length > 0 || props.node.canFetch ? (
  804. <ChildrenButton
  805. icon={
  806. props.node.canFetch && props.node.fetchStatus === 'idle' ? (
  807. '+'
  808. ) : props.node.canFetch && props.node.zoomedIn ? (
  809. <Chevron direction="down" />
  810. ) : (
  811. '+'
  812. )
  813. }
  814. status={props.node.fetchStatus}
  815. expanded={props.node.expanded || props.node.zoomedIn}
  816. onClick={e =>
  817. props.node.canFetch
  818. ? props.onZoomIn(e, props.node, !props.node.zoomedIn)
  819. : props.onExpand(e, props.node, !props.node.expanded)
  820. }
  821. errored={errored}
  822. >
  823. {props.node.children.length > 0
  824. ? COUNT_FORMATTER.format(props.node.children.length)
  825. : null}
  826. </ChildrenButton>
  827. ) : null}
  828. </div>
  829. <PlatformIcon
  830. platform={props.projects[props.node.value.project_slug] ?? 'default'}
  831. />
  832. <span className="TraceOperation">{props.node.value['transaction.op']}</span>
  833. <strong className="TraceEmDash"> — </strong>
  834. <span>{props.node.value.transaction}</span>
  835. </div>
  836. </div>
  837. <div
  838. ref={r =>
  839. props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
  840. }
  841. className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
  842. style={{
  843. width: props.manager.columns.span_list.width * 100 + '%',
  844. }}
  845. onDoubleClick={e => {
  846. e.stopPropagation();
  847. props.manager.onZoomIntoSpace(props.node.space!);
  848. }}
  849. >
  850. <TraceBar
  851. virtualized_index={virtualized_index}
  852. manager={props.manager}
  853. color={makeTraceNodeBarColor(props.theme, props.node)}
  854. node_space={props.node.space}
  855. errors={props.node.value.errors}
  856. performance_issues={props.node.value.performance_issues}
  857. profiles={props.node.profiles}
  858. />
  859. <button
  860. ref={ref =>
  861. props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
  862. }
  863. className="TraceArrow"
  864. onClick={_e => {
  865. props.manager.onBringRowIntoView(props.node.space!);
  866. }}
  867. >
  868. <Chevron direction="left" />
  869. </button>
  870. </div>
  871. </div>
  872. );
  873. }
  874. if (isSpanNode(props.node)) {
  875. const errored =
  876. props.node.errors.length > 0 || props.node.performance_issues.length > 0;
  877. return (
  878. <div
  879. key={props.index}
  880. ref={r =>
  881. props.tabIndex === props.index
  882. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  883. : null
  884. }
  885. tabIndex={props.tabIndex === props.index ? 0 : -1}
  886. className={`TraceRow ${rowSearchClassName} ${errored ? 'Errored' : ''}`}
  887. onClick={e => props.onRowClick(e, props.index, props.node)}
  888. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  889. style={{
  890. top: props.style.top,
  891. height: props.style.height,
  892. }}
  893. >
  894. <div
  895. className="TraceLeftColumn"
  896. ref={r =>
  897. props.manager.registerColumnRef('list', r, virtualized_index, props.node)
  898. }
  899. style={{
  900. width: props.manager.columns.list.width * 100 + '%',
  901. }}
  902. >
  903. <div
  904. className={`TraceLeftColumnInner`}
  905. style={{
  906. paddingLeft: props.node.depth * props.manager.row_depth_padding,
  907. }}
  908. >
  909. <div
  910. className={`TraceChildrenCountWrapper ${
  911. props.node.isOrphaned ? 'Orphaned' : ''
  912. }`}
  913. >
  914. <Connectors node={props.node} manager={props.manager} />
  915. {props.node.children.length > 0 || props.node.canFetch ? (
  916. <ChildrenButton
  917. icon={
  918. props.node.canFetch ? (
  919. '+'
  920. ) : props.node.expanded ? (
  921. <Chevron direction="up" />
  922. ) : (
  923. <Chevron direction="down" />
  924. )
  925. }
  926. status={props.node.fetchStatus}
  927. expanded={props.node.expanded || props.node.zoomedIn}
  928. onClick={e =>
  929. props.node.canFetch
  930. ? props.onZoomIn(e, props.node, !props.node.zoomedIn)
  931. : props.onExpand(e, props.node, !props.node.expanded)
  932. }
  933. errored={errored}
  934. >
  935. {props.node.children.length > 0
  936. ? COUNT_FORMATTER.format(props.node.children.length)
  937. : null}
  938. </ChildrenButton>
  939. ) : null}
  940. </div>
  941. <span className="TraceOperation">{props.node.value.op ?? '<unknown>'}</span>
  942. <strong className="TraceEmDash"> — </strong>
  943. <span className="TraceDescription" title={props.node.value.description}>
  944. {!props.node.value.description
  945. ? 'unknown'
  946. : props.node.value.description.length > 100
  947. ? props.node.value.description.slice(0, 100).trim() + '\u2026'
  948. : props.node.value.description}
  949. </span>
  950. </div>
  951. </div>
  952. <div
  953. ref={r =>
  954. props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
  955. }
  956. className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
  957. style={{
  958. width: props.manager.columns.span_list.width * 100 + '%',
  959. }}
  960. onDoubleClick={e => {
  961. e.stopPropagation();
  962. props.manager.onZoomIntoSpace(props.node.space!);
  963. }}
  964. >
  965. <TraceBar
  966. virtualized_index={virtualized_index}
  967. manager={props.manager}
  968. color={makeTraceNodeBarColor(props.theme, props.node)}
  969. node_space={props.node.space}
  970. errors={props.node.errors}
  971. performance_issues={props.node.performance_issues}
  972. profiles={NO_ERRORS}
  973. />
  974. <button
  975. ref={ref =>
  976. props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
  977. }
  978. className="TraceArrow"
  979. onClick={_e => {
  980. props.manager.onBringRowIntoView(props.node.space!);
  981. }}
  982. >
  983. <Chevron direction="left" />
  984. </button>
  985. </div>
  986. </div>
  987. );
  988. }
  989. if (isMissingInstrumentationNode(props.node)) {
  990. return (
  991. <div
  992. key={props.index}
  993. ref={r =>
  994. props.tabIndex === props.index
  995. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  996. : null
  997. }
  998. tabIndex={props.tabIndex === props.index ? 0 : -1}
  999. className={`TraceRow ${rowSearchClassName}`}
  1000. onClick={e => props.onRowClick(e, props.index, props.node)}
  1001. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  1002. style={{
  1003. top: props.style.top,
  1004. height: props.style.height,
  1005. }}
  1006. >
  1007. <div
  1008. className="TraceLeftColumn"
  1009. ref={r =>
  1010. props.manager.registerColumnRef('list', r, virtualized_index, props.node)
  1011. }
  1012. style={{
  1013. width: props.manager.columns.list.width * 100 + '%',
  1014. }}
  1015. >
  1016. <div
  1017. className="TraceLeftColumnInner"
  1018. style={{
  1019. paddingLeft: props.node.depth * props.manager.row_depth_padding,
  1020. }}
  1021. >
  1022. <div className="TraceChildrenCountWrapper">
  1023. <Connectors node={props.node} manager={props.manager} />
  1024. </div>
  1025. <span className="TraceOperation">{t('Missing instrumentation')}</span>
  1026. </div>
  1027. </div>
  1028. <div
  1029. ref={r =>
  1030. props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
  1031. }
  1032. className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
  1033. style={{
  1034. width: props.manager.columns.span_list.width * 100 + '%',
  1035. }}
  1036. onDoubleClick={e => {
  1037. e.stopPropagation();
  1038. props.manager.onZoomIntoSpace(props.node.space!);
  1039. }}
  1040. >
  1041. <TraceBar
  1042. virtualized_index={virtualized_index}
  1043. manager={props.manager}
  1044. color={makeTraceNodeBarColor(props.theme, props.node)}
  1045. node_space={props.node.space}
  1046. performance_issues={NO_ERRORS}
  1047. profiles={NO_ERRORS}
  1048. errors={NO_ERRORS}
  1049. />
  1050. <button
  1051. ref={ref =>
  1052. props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
  1053. }
  1054. className="TraceArrow"
  1055. onClick={_e => {
  1056. props.manager.onBringRowIntoView(props.node.space!);
  1057. }}
  1058. >
  1059. <Chevron direction="left" />
  1060. </button>
  1061. </div>
  1062. </div>
  1063. );
  1064. }
  1065. if (isTraceNode(props.node)) {
  1066. return (
  1067. <div
  1068. key={props.index}
  1069. ref={r =>
  1070. props.tabIndex === props.index
  1071. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  1072. : null
  1073. }
  1074. tabIndex={props.tabIndex === props.index ? 0 : -1}
  1075. className={`TraceRow ${rowSearchClassName} ${props.node.has_errors ? 'Errored' : ''}`}
  1076. onClick={e => props.onRowClick(e, props.index, props.node)}
  1077. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  1078. style={{
  1079. top: props.style.top,
  1080. height: props.style.height,
  1081. }}
  1082. >
  1083. <div
  1084. className="TraceLeftColumn"
  1085. ref={r =>
  1086. props.manager.registerColumnRef('list', r, virtualized_index, props.node)
  1087. }
  1088. style={{
  1089. width: props.manager.columns.list.width * 100 + '%',
  1090. }}
  1091. >
  1092. <div
  1093. className="TraceLeftColumnInner"
  1094. style={{
  1095. paddingLeft: props.node.depth * props.manager.row_depth_padding,
  1096. }}
  1097. >
  1098. <div className="TraceChildrenCountWrapper Root">
  1099. <Connectors node={props.node} manager={props.manager} />
  1100. {props.node.children.length > 0 || props.node.canFetch ? (
  1101. <ChildrenButton icon={''} status={'idle'} expanded onClick={() => void 0}>
  1102. {props.node.children.length > 0
  1103. ? COUNT_FORMATTER.format(props.node.children.length)
  1104. : null}
  1105. </ChildrenButton>
  1106. ) : null}
  1107. </div>
  1108. <span className="TraceOperation">{t('Trace')}</span>
  1109. <strong className="TraceEmDash"> — </strong>
  1110. <span className="TraceDescription">{props.trace_id}</span>
  1111. </div>
  1112. </div>
  1113. <div
  1114. ref={r =>
  1115. props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
  1116. }
  1117. className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
  1118. style={{
  1119. width: props.manager.columns.span_list.width * 100 + '%',
  1120. }}
  1121. onDoubleClick={e => {
  1122. e.stopPropagation();
  1123. props.manager.onZoomIntoSpace(props.node.space!);
  1124. }}
  1125. >
  1126. <TraceBar
  1127. virtualized_index={virtualized_index}
  1128. manager={props.manager}
  1129. color={makeTraceNodeBarColor(props.theme, props.node)}
  1130. node_space={props.node.space}
  1131. errors={NO_ERRORS}
  1132. performance_issues={NO_ERRORS}
  1133. profiles={NO_ERRORS}
  1134. />
  1135. <button
  1136. ref={ref =>
  1137. props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
  1138. }
  1139. className="TraceArrow"
  1140. onClick={_e => {
  1141. props.manager.onBringRowIntoView(props.node.space!);
  1142. }}
  1143. >
  1144. <Chevron direction="left" />
  1145. </button>
  1146. </div>
  1147. </div>
  1148. );
  1149. }
  1150. if (isTraceErrorNode(props.node)) {
  1151. return (
  1152. <div
  1153. key={props.index}
  1154. ref={r =>
  1155. props.tabIndex === props.index
  1156. ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
  1157. : null
  1158. }
  1159. tabIndex={props.tabIndex === props.index ? 0 : -1}
  1160. className={`TraceRow ${rowSearchClassName} Errored`}
  1161. onClick={e => props.onRowClick(e, props.index, props.node)}
  1162. onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
  1163. style={{
  1164. top: props.style.top,
  1165. height: props.style.height,
  1166. }}
  1167. >
  1168. <div
  1169. className="TraceLeftColumn"
  1170. ref={r =>
  1171. props.manager.registerColumnRef('list', r, virtualized_index, props.node)
  1172. }
  1173. style={{
  1174. width: props.manager.columns.list.width * 100 + '%',
  1175. }}
  1176. >
  1177. <div
  1178. className="TraceLeftColumnInner"
  1179. style={{
  1180. paddingLeft: props.node.depth * props.manager.row_depth_padding,
  1181. }}
  1182. >
  1183. <div className="TraceChildrenCountWrapper">
  1184. <Connectors node={props.node} manager={props.manager} />
  1185. </div>
  1186. <PlatformIcon
  1187. platform={props.projects[props.node.value.project_slug] ?? 'default'}
  1188. />
  1189. <span className="TraceOperation">{t('Error')}</span>
  1190. <strong className="TraceEmDash"> — </strong>
  1191. <span className="TraceDescription">{props.node.value.title}</span>
  1192. </div>
  1193. </div>
  1194. <div
  1195. ref={r =>
  1196. props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
  1197. }
  1198. className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
  1199. style={{
  1200. width: props.manager.columns.span_list.width * 100 + '%',
  1201. }}
  1202. onDoubleClick={e => {
  1203. e.stopPropagation();
  1204. props.manager.onZoomIntoSpace(props.node.space!);
  1205. }}
  1206. >
  1207. <InvisibleTraceBar
  1208. node_space={props.node.space}
  1209. manager={props.manager}
  1210. virtualizedIndex={virtualized_index}
  1211. >
  1212. {typeof props.node.value.timestamp === 'number' ? (
  1213. <div className="TraceError">
  1214. <Fire />
  1215. </div>
  1216. ) : null}
  1217. </InvisibleTraceBar>
  1218. </div>
  1219. </div>
  1220. );
  1221. }
  1222. return null;
  1223. }
  1224. function RenderPlaceholderRow(props: {
  1225. index: number;
  1226. manager: VirtualizedViewManager;
  1227. node: TraceTreeNode<TraceTree.NodeValue>;
  1228. projects: Record<Project['slug'], Project['platform']>;
  1229. style: React.CSSProperties;
  1230. theme: Theme;
  1231. }) {
  1232. return (
  1233. <div
  1234. key={props.index}
  1235. className="TraceRow"
  1236. style={{
  1237. top: props.style.top,
  1238. height: props.style.height,
  1239. pointerEvents: 'none',
  1240. color: props.theme.subText,
  1241. paddingLeft: 8,
  1242. }}
  1243. >
  1244. <div
  1245. className="TraceLeftColumn"
  1246. style={{width: props.manager.columns.list.width * 100 + '%'}}
  1247. >
  1248. <div
  1249. className="TraceLeftColumnInner"
  1250. style={{
  1251. paddingLeft: props.node.depth * props.manager.row_depth_padding,
  1252. }}
  1253. >
  1254. <div
  1255. className={`TraceChildrenCountWrapper ${isTraceNode(props.node) ? 'Root' : ''}`}
  1256. >
  1257. <Connectors node={props.node} manager={props.manager} />
  1258. {props.node.children.length > 0 || props.node.canFetch ? (
  1259. <ChildrenButton
  1260. icon="+"
  1261. status={props.node.fetchStatus}
  1262. expanded={props.node.expanded || props.node.zoomedIn}
  1263. onClick={() => void 0}
  1264. >
  1265. {props.node.children.length > 0
  1266. ? COUNT_FORMATTER.format(props.node.children.length)
  1267. : null}
  1268. </ChildrenButton>
  1269. ) : null}
  1270. </div>
  1271. <Placeholder
  1272. className="Placeholder"
  1273. height="12px"
  1274. width={randomBetween(20, 80) + '%'}
  1275. style={{
  1276. transition: 'all 30s ease-out',
  1277. }}
  1278. />
  1279. </div>
  1280. </div>
  1281. <div
  1282. className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
  1283. style={{
  1284. width: props.manager.columns.span_list.width * 100 + '%',
  1285. backgroundColor:
  1286. props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
  1287. }}
  1288. >
  1289. <Placeholder
  1290. className="Placeholder"
  1291. height="12px"
  1292. width={randomBetween(20, 80) + '%'}
  1293. style={{
  1294. transition: 'all 30s ease-out',
  1295. transform: `translate(${randomBetween(0, 200) + 'px'}, 0)`,
  1296. }}
  1297. />
  1298. </div>
  1299. </div>
  1300. );
  1301. }
  1302. function randomBetween(min: number, max: number) {
  1303. return Math.floor(Math.random() * (max - min + 1) + min);
  1304. }
  1305. function Connectors(props: {
  1306. manager: VirtualizedViewManager;
  1307. node: TraceTreeNode<TraceTree.NodeValue>;
  1308. }) {
  1309. const showVerticalConnector =
  1310. ((props.node.expanded || props.node.zoomedIn) && props.node.children.length > 0) ||
  1311. (props.node.value && isParentAutogroupedNode(props.node));
  1312. // If the tail node of the collapsed node has no children,
  1313. // we don't want to render the vertical connector as no children
  1314. // are being rendered as the chain is entirely collapsed
  1315. const hideVerticalConnector =
  1316. showVerticalConnector &&
  1317. props.node.value &&
  1318. props.node instanceof ParentAutogroupNode &&
  1319. !props.node.tail.children.length;
  1320. return (
  1321. <Fragment>
  1322. {props.node.connectors.map((c, i) => {
  1323. return (
  1324. <div
  1325. key={i}
  1326. style={{
  1327. left: -(
  1328. Math.abs(Math.abs(c) - props.node.depth) * props.manager.row_depth_padding
  1329. ),
  1330. }}
  1331. className={`TraceVerticalConnector ${c < 0 ? 'Orphaned' : ''}`}
  1332. />
  1333. );
  1334. })}
  1335. {showVerticalConnector && !hideVerticalConnector ? (
  1336. <div className="TraceExpandedVerticalConnector" />
  1337. ) : null}
  1338. {props.node.isLastChild ? (
  1339. <div className="TraceVerticalLastChildConnector" />
  1340. ) : (
  1341. <div className="TraceVerticalConnector" />
  1342. )}
  1343. </Fragment>
  1344. );
  1345. }
  1346. function ChildrenButton(props: {
  1347. children: React.ReactNode;
  1348. expanded: boolean;
  1349. icon: React.ReactNode;
  1350. onClick: (e: React.MouseEvent) => void;
  1351. status: TraceTreeNode<any>['fetchStatus'] | undefined;
  1352. errored?: boolean;
  1353. }) {
  1354. return (
  1355. <button
  1356. className={`TraceChildrenCount ${props.errored ? 'Errored' : ''}`}
  1357. onClick={props.onClick}
  1358. >
  1359. <div className="TraceChildrenCountContent">{props.children}</div>
  1360. <div className="TraceChildrenCountAction">
  1361. {props.icon}
  1362. {props.status === 'loading' ? (
  1363. <LoadingIndicator className="TraceActionsLoadingIndicator" size={8} />
  1364. ) : null}
  1365. </div>
  1366. </button>
  1367. );
  1368. }
  1369. interface TraceBarProps {
  1370. color: string;
  1371. errors: TraceTreeNode<TraceTree.Transaction>['value']['errors'];
  1372. manager: VirtualizedViewManager;
  1373. node_space: [number, number] | null;
  1374. performance_issues: TraceTreeNode<TraceTree.Transaction>['value']['performance_issues'];
  1375. profiles: TraceTreeNode<TraceTree.NodeValue>['profiles'];
  1376. virtualized_index: number;
  1377. }
  1378. function TraceBar(props: TraceBarProps) {
  1379. if (!props.node_space) {
  1380. return null;
  1381. }
  1382. const duration = getDuration(props.node_space[1] / 1000, 2, true);
  1383. const spanTransform = props.manager.computeSpanCSSMatrixTransform(props.node_space);
  1384. const [inside, textTransform] = props.manager.computeSpanTextPlacement(
  1385. props.node_space,
  1386. duration
  1387. );
  1388. return (
  1389. <Fragment>
  1390. <div
  1391. ref={r =>
  1392. props.manager.registerSpanBarRef(r, props.node_space!, props.virtualized_index)
  1393. }
  1394. className="TraceBar"
  1395. style={
  1396. {
  1397. transform: `matrix(${spanTransform.join(',')})`,
  1398. '--inverse-span-scale': 1 / spanTransform[0],
  1399. backgroundColor: props.color,
  1400. // unknown css variables cannot be part of the style object
  1401. } as React.CSSProperties
  1402. }
  1403. >
  1404. {props.profiles.length > 0 ? (
  1405. <Profiles
  1406. node_space={props.node_space}
  1407. profiles={props.profiles}
  1408. manager={props.manager}
  1409. />
  1410. ) : null}
  1411. {props.errors.length > 0 ? (
  1412. <Errors
  1413. node_space={props.node_space}
  1414. errors={props.errors}
  1415. manager={props.manager}
  1416. />
  1417. ) : null}
  1418. {props.performance_issues.length > 0 ? (
  1419. <PerformanceIssues
  1420. node_space={props.node_space}
  1421. performance_issues={props.performance_issues}
  1422. manager={props.manager}
  1423. />
  1424. ) : null}
  1425. </div>
  1426. <div
  1427. ref={r =>
  1428. props.manager.registerSpanBarTextRef(
  1429. r,
  1430. duration,
  1431. props.node_space!,
  1432. props.virtualized_index
  1433. )
  1434. }
  1435. className="TraceBarDuration"
  1436. style={{
  1437. color: inside ? 'white' : '',
  1438. transform: `translate(${textTransform ?? 0}px, 0)`,
  1439. }}
  1440. >
  1441. {duration}
  1442. </div>
  1443. </Fragment>
  1444. );
  1445. }
  1446. interface InvisibleTraceBarProps {
  1447. children: React.ReactNode;
  1448. manager: VirtualizedViewManager;
  1449. node_space: [number, number] | null;
  1450. virtualizedIndex: number;
  1451. }
  1452. function InvisibleTraceBar(props: InvisibleTraceBarProps) {
  1453. if (!props.node_space || !props.children) {
  1454. return null;
  1455. }
  1456. const transform = `translateX(${props.manager.computeTransformXFromTimestamp(props.node_space[0])}px)`;
  1457. return (
  1458. <div
  1459. ref={r =>
  1460. props.manager.registerInvisibleBarRef(
  1461. r,
  1462. props.node_space!,
  1463. props.virtualizedIndex
  1464. )
  1465. }
  1466. className="TraceBar Invisible"
  1467. style={{
  1468. transform,
  1469. }}
  1470. onDoubleClick={e => {
  1471. e.stopPropagation();
  1472. props.manager.onZoomIntoSpace(props.node_space!);
  1473. }}
  1474. >
  1475. {props.children}
  1476. </div>
  1477. );
  1478. }
  1479. interface PerformanceIssuesProps {
  1480. manager: VirtualizedViewManager;
  1481. node_space: [number, number] | null;
  1482. performance_issues: TracePerformanceIssue[];
  1483. }
  1484. function PerformanceIssues(props: PerformanceIssuesProps) {
  1485. return (
  1486. <Fragment>
  1487. {props.performance_issues.map((issue, _i) => {
  1488. const timestamp = issue.start * 1e3;
  1489. // Clamp the issue timestamp to the span's timestamp
  1490. const left = props.manager.computeRelativeLeftPositionFromOrigin(
  1491. clamp(
  1492. timestamp,
  1493. props.node_space![0],
  1494. props.node_space![0] + props.node_space![1]
  1495. ),
  1496. props.node_space!
  1497. );
  1498. const max_width = 100 - left;
  1499. const issue_duration = (issue.end - issue.start) * 1e3;
  1500. const width = clamp((issue_duration / props.node_space![1]) * 100, 0, max_width);
  1501. return (
  1502. <div
  1503. key={issue.event_id}
  1504. className="TracePerformanceIssue"
  1505. style={{left: left * 100 + '%', width: width + '%'}}
  1506. >
  1507. <div className="TraceError" style={{left: 0}}>
  1508. <Fire />
  1509. </div>
  1510. </div>
  1511. );
  1512. })}
  1513. </Fragment>
  1514. );
  1515. }
  1516. interface ErrorsProps {
  1517. errors: TraceError[];
  1518. manager: VirtualizedViewManager;
  1519. node_space: [number, number] | null;
  1520. }
  1521. function Errors(props: ErrorsProps) {
  1522. if (!props.errors.length) {
  1523. return null;
  1524. }
  1525. return (
  1526. <Fragment>
  1527. {props.errors.map((error, _i) => {
  1528. const timestamp = error.timestamp ? error.timestamp * 1e3 : props.node_space![0];
  1529. // Clamp the error timestamp to the span's timestamp
  1530. const left = props.manager.computeRelativeLeftPositionFromOrigin(
  1531. clamp(
  1532. timestamp,
  1533. props.node_space![0],
  1534. props.node_space![0] + props.node_space![1]
  1535. ),
  1536. props.node_space!
  1537. );
  1538. return (
  1539. <div
  1540. key={error.event_id}
  1541. className="TraceError"
  1542. style={{left: left * 100 + '%'}}
  1543. >
  1544. <Fire />
  1545. </div>
  1546. );
  1547. })}
  1548. </Fragment>
  1549. );
  1550. }
  1551. interface ProfilesProps {
  1552. manager: VirtualizedViewManager;
  1553. node_space: [number, number] | null;
  1554. profiles: TraceTree.Profile[];
  1555. }
  1556. function Profiles(props: ProfilesProps) {
  1557. if (!props.profiles.length) {
  1558. return null;
  1559. }
  1560. return (
  1561. <Fragment>
  1562. {props.profiles.map((profile, _i) => {
  1563. const timestamp = profile.space[0];
  1564. // Clamp the profile timestamp to the span's timestamp
  1565. const left = props.manager.computeRelativeLeftPositionFromOrigin(
  1566. clamp(
  1567. timestamp,
  1568. props.node_space![0],
  1569. props.node_space![0] + props.node_space![1]
  1570. ),
  1571. props.node_space!
  1572. );
  1573. return (
  1574. <div
  1575. key={profile.profile_id}
  1576. className="TraceProfile"
  1577. style={{left: left * 100 + '%'}}
  1578. >
  1579. <Profile />
  1580. </div>
  1581. );
  1582. })}
  1583. </Fragment>
  1584. );
  1585. }
  1586. interface AutogroupedTraceBarProps {
  1587. color: string;
  1588. entire_space: [number, number] | null;
  1589. errors: TraceTreeNode<TraceTree.Transaction>['value']['errors'];
  1590. manager: VirtualizedViewManager;
  1591. node_spaces: [number, number][];
  1592. performance_issues: TraceTreeNode<TraceTree.Transaction>['value']['performance_issues'];
  1593. profiles: TraceTreeNode<TraceTree.NodeValue>['profiles'];
  1594. virtualized_index: number;
  1595. }
  1596. function AutogroupedTraceBar(props: AutogroupedTraceBarProps) {
  1597. if (props.node_spaces && props.node_spaces.length <= 1) {
  1598. return (
  1599. <TraceBar
  1600. color={props.color}
  1601. node_space={props.entire_space}
  1602. manager={props.manager}
  1603. virtualized_index={props.virtualized_index}
  1604. errors={props.errors}
  1605. performance_issues={props.performance_issues}
  1606. profiles={props.profiles}
  1607. />
  1608. );
  1609. }
  1610. if (!props.node_spaces || !props.entire_space) {
  1611. return null;
  1612. }
  1613. const duration = getDuration(props.entire_space[1] / 1000, 2, true);
  1614. const spanTransform = props.manager.computeSpanCSSMatrixTransform(props.entire_space);
  1615. const [inside, textTransform] = props.manager.computeSpanTextPlacement(
  1616. props.entire_space,
  1617. duration
  1618. );
  1619. return (
  1620. <Fragment>
  1621. <div
  1622. ref={r =>
  1623. props.manager.registerSpanBarRef(
  1624. r,
  1625. props.entire_space!,
  1626. props.virtualized_index
  1627. )
  1628. }
  1629. className="TraceBar Invisible"
  1630. style={{
  1631. transform: `matrix(${spanTransform.join(',')})`,
  1632. backgroundColor: props.color,
  1633. }}
  1634. >
  1635. {props.node_spaces.map((node_space, i) => {
  1636. const width = node_space[1] / props.entire_space![1];
  1637. const left = props.manager.computeRelativeLeftPositionFromOrigin(
  1638. node_space[0],
  1639. props.entire_space!
  1640. );
  1641. return (
  1642. <div
  1643. key={i}
  1644. className="TraceBar"
  1645. style={{
  1646. left: `${left * 1000}%`,
  1647. width: `${width * 100}%`,
  1648. backgroundColor: props.color,
  1649. }}
  1650. />
  1651. );
  1652. })}
  1653. {props.profiles.length > 0 ? (
  1654. <Profiles
  1655. node_space={props.entire_space}
  1656. profiles={props.profiles}
  1657. manager={props.manager}
  1658. />
  1659. ) : null}
  1660. {props.errors.length > 0 ? (
  1661. <Errors
  1662. node_space={props.entire_space}
  1663. errors={props.errors}
  1664. manager={props.manager}
  1665. />
  1666. ) : null}
  1667. {props.performance_issues.length > 0 ? (
  1668. <PerformanceIssues
  1669. node_space={props.entire_space}
  1670. performance_issues={props.performance_issues}
  1671. manager={props.manager}
  1672. />
  1673. ) : null}
  1674. </div>
  1675. <div
  1676. ref={r =>
  1677. props.manager.registerSpanBarTextRef(
  1678. r,
  1679. duration,
  1680. props.entire_space!,
  1681. props.virtualized_index
  1682. )
  1683. }
  1684. className="TraceBarDuration"
  1685. style={{
  1686. color: inside ? 'white' : '',
  1687. transform: `translate(${textTransform ?? 0}px, 0)`,
  1688. }}
  1689. >
  1690. {duration}
  1691. </div>
  1692. </Fragment>
  1693. );
  1694. }
  1695. /**
  1696. * This is a wrapper around the Trace component to apply styles
  1697. * to the trace tree. It exists because we _do not_ want to trigger
  1698. * emotion's css parsing logic as it is very slow and will cause
  1699. * the scrolling to flicker.
  1700. */
  1701. const TraceStylingWrapper = styled('div')`
  1702. margin: auto;
  1703. overscroll-behavior: none;
  1704. box-shadow: 0 0 0 1px ${p => p.theme.border};
  1705. position: absolute;
  1706. left: 0;
  1707. top: 0;
  1708. width: 100%;
  1709. height: 100%;
  1710. grid-area: trace;
  1711. padding-top: 26px;
  1712. &.WithIndicators {
  1713. padding-top: 44px;
  1714. &:before {
  1715. height: 44px;
  1716. }
  1717. .TraceIndicator.Timeline {
  1718. .TraceIndicatorLabel {
  1719. top: 26px;
  1720. }
  1721. .TraceIndicatorLine {
  1722. top: 30px;
  1723. }
  1724. }
  1725. }
  1726. &:before {
  1727. content: '';
  1728. position: absolute;
  1729. left: 0;
  1730. top: 0;
  1731. width: 100%;
  1732. height: 26px;
  1733. background-color: ${p => p.theme.backgroundSecondary};
  1734. border-bottom: 1px solid ${p => p.theme.border};
  1735. }
  1736. &.Loading {
  1737. .TraceRow {
  1738. .TraceLeftColumnInner {
  1739. width: 100%;
  1740. }
  1741. }
  1742. .TraceRightColumn {
  1743. background-color: transparent !important;
  1744. }
  1745. .TraceDivider {
  1746. pointer-events: none;
  1747. }
  1748. }
  1749. .TraceDivider {
  1750. position: absolute;
  1751. height: 100%;
  1752. background-color: transparent;
  1753. top: 0;
  1754. cursor: col-resize;
  1755. z-index: 10;
  1756. &:before {
  1757. content: '';
  1758. position: absolute;
  1759. width: 1px;
  1760. height: 100%;
  1761. background-color: ${p => p.theme.border};
  1762. left: 50%;
  1763. }
  1764. &:hover {
  1765. &:before {
  1766. background-color: ${p => p.theme.purple300};
  1767. }
  1768. }
  1769. }
  1770. .TraceIndicatorContainer {
  1771. overflow: hidden;
  1772. width: 100%;
  1773. height: 100%;
  1774. position: absolute;
  1775. right: 0;
  1776. top: 0;
  1777. }
  1778. .TraceIndicator {
  1779. z-index: 1;
  1780. width: 3px;
  1781. height: 100%;
  1782. top: 0;
  1783. position: absolute;
  1784. .TraceIndicatorLabel {
  1785. min-width: 34px;
  1786. text-align: center;
  1787. position: absolute;
  1788. font-size: ${p => p.theme.fontSizeExtraSmall};
  1789. font-weight: bold;
  1790. color: ${p => p.theme.textColor};
  1791. background-color: ${p => p.theme.background};
  1792. border-radius: ${p => p.theme.borderRadius};
  1793. border: 1px solid ${p => p.theme.border};
  1794. padding: 2px;
  1795. display: inline-block;
  1796. line-height: 1;
  1797. margin-top: 2px;
  1798. white-space: nowrap;
  1799. }
  1800. .TraceIndicatorLine {
  1801. width: 1px;
  1802. height: 100%;
  1803. top: 20px;
  1804. position: absolute;
  1805. left: 50%;
  1806. transform: translateX(-2px);
  1807. background: repeating-linear-gradient(
  1808. to bottom,
  1809. transparent 0 4px,
  1810. ${p => p.theme.textColor} 4px 8px
  1811. )
  1812. 80%/2px 100% no-repeat;
  1813. }
  1814. &.Timeline {
  1815. opacity: 1;
  1816. z-index: 1;
  1817. pointer-events: none;
  1818. .TraceIndicatorLabel {
  1819. font-weight: normal;
  1820. min-width: 0;
  1821. top: 8px;
  1822. width: auto;
  1823. border: none;
  1824. background-color: transparent;
  1825. color: ${p => p.theme.subText};
  1826. }
  1827. .TraceIndicatorLine {
  1828. background: ${p => p.theme.translucentGray100};
  1829. top: 8px;
  1830. }
  1831. }
  1832. }
  1833. .TraceRow {
  1834. display: flex;
  1835. align-items: center;
  1836. position: absolute;
  1837. height: 24px;
  1838. width: 100%;
  1839. transition: none;
  1840. font-size: ${p => p.theme.fontSizeSmall};
  1841. .TraceError {
  1842. position: absolute;
  1843. top: 50%;
  1844. transform: translate(-50%, -50%) scaleX(var(--inverse-span-scale));
  1845. background: ${p => p.theme.background};
  1846. width: 18px !important;
  1847. height: 18px !important;
  1848. background-color: ${p => p.theme.error};
  1849. border-radius: 50%;
  1850. display: flex;
  1851. align-items: center;
  1852. justify-content: center;
  1853. svg {
  1854. fill: ${p => p.theme.white};
  1855. }
  1856. }
  1857. .TraceProfile {
  1858. position: absolute;
  1859. top: 50%;
  1860. transform: translate(-50%, -50%) scaleX(var(--inverse-span-scale));
  1861. background: ${p => p.theme.background};
  1862. width: 18px !important;
  1863. height: 18px !important;
  1864. background-color: ${p => p.theme.purple300};
  1865. border-radius: 50%;
  1866. display: flex;
  1867. align-items: center;
  1868. justify-content: center;
  1869. svg {
  1870. fill: ${p => p.theme.white};
  1871. }
  1872. }
  1873. .TracePerformanceIssue {
  1874. position: absolute;
  1875. top: 0;
  1876. display: flex;
  1877. align-items: center;
  1878. justify-content: flex-start;
  1879. background-color: ${p => p.theme.error};
  1880. height: 16px;
  1881. }
  1882. .TraceRightColumn.Odd {
  1883. background-color: ${p => p.theme.backgroundSecondary};
  1884. }
  1885. &:hover {
  1886. background-color: ${p => p.theme.backgroundSecondary};
  1887. }
  1888. &.Highlight {
  1889. box-shadow: inset 0 0 0 1px ${p => p.theme.blue200} !important;
  1890. .TraceLeftColumn {
  1891. box-shadow: inset 0px 0 0px 1px ${p => p.theme.blue200} !important;
  1892. }
  1893. }
  1894. &.Highlight,
  1895. &:focus {
  1896. outline: none;
  1897. background-color: ${p => p.theme.backgroundTertiary};
  1898. .TraceRightColumn.Odd {
  1899. background-color: transparent !important;
  1900. }
  1901. }
  1902. &:focus,
  1903. &[tabindex='0'] {
  1904. background-color: ${p => p.theme.backgroundTertiary};
  1905. box-shadow: inset 0 0 0 1px ${p => p.theme.blue300} !important;
  1906. .TraceLeftColumn {
  1907. box-shadow: inset 0px 0 0px 1px ${p => p.theme.blue300} !important;
  1908. }
  1909. .TraceRightColumn.Odd {
  1910. background-color: transparent !important;
  1911. }
  1912. }
  1913. &.Errored {
  1914. color: ${p => p.theme.error};
  1915. .TraceChildrenCount {
  1916. border: 2px solid ${p => p.theme.error};
  1917. }
  1918. &:focus,
  1919. &[tabindex='0'] {
  1920. box-shadow: inset 0 0 0 1px ${p => p.theme.red300} !important;
  1921. .TraceLeftColumn {
  1922. box-shadow: inset 0px 0 0px 1px ${p => p.theme.red300} !important;
  1923. }
  1924. }
  1925. }
  1926. &.SearchResult {
  1927. background-color: ${p => p.theme.yellow100};
  1928. .TraceRightColumn {
  1929. background-color: transparent;
  1930. }
  1931. }
  1932. &.Autogrouped {
  1933. color: ${p => p.theme.blue300};
  1934. &.Errored {
  1935. .TraceChildrenCount {
  1936. background-color: ${p => p.theme.error} !important;
  1937. }
  1938. }
  1939. .TraceDescription {
  1940. font-weight: bold;
  1941. }
  1942. .TraceChildrenCountWrapper {
  1943. button {
  1944. color: ${p => p.theme.white};
  1945. background-color: ${p => p.theme.blue300};
  1946. }
  1947. svg {
  1948. fill: ${p => p.theme.white};
  1949. }
  1950. }
  1951. }
  1952. }
  1953. .TraceLeftColumn {
  1954. height: 100%;
  1955. white-space: nowrap;
  1956. display: flex;
  1957. align-items: center;
  1958. overflow: hidden;
  1959. will-change: width;
  1960. box-shadow: inset 1px 0 0px 0px transparent;
  1961. .TraceLeftColumnInner {
  1962. height: 100%;
  1963. white-space: nowrap;
  1964. display: flex;
  1965. align-items: center;
  1966. will-change: transform;
  1967. transform-origin: left center;
  1968. img {
  1969. width: 16px;
  1970. height: 16px;
  1971. }
  1972. }
  1973. }
  1974. .TraceRightColumn {
  1975. height: 100%;
  1976. overflow: hidden;
  1977. position: relative;
  1978. display: flex;
  1979. align-items: center;
  1980. will-change: width;
  1981. z-index: 1;
  1982. cursor: pointer;
  1983. &:hover {
  1984. .TraceArrow.Visible {
  1985. opacity: 1;
  1986. transition: 300ms 300ms ease-out;
  1987. pointer-events: auto;
  1988. }
  1989. }
  1990. }
  1991. .TraceBar {
  1992. position: absolute;
  1993. height: 16px;
  1994. width: 100%;
  1995. background-color: black;
  1996. transform-origin: left center;
  1997. &.Invisible {
  1998. background-color: transparent !important;
  1999. > div {
  2000. height: 100%;
  2001. }
  2002. .TraceError {
  2003. top: -1px;
  2004. transform: translate(-50%, 0);
  2005. }
  2006. }
  2007. svg {
  2008. width: 14px;
  2009. height: 14px;
  2010. }
  2011. }
  2012. .TraceArrow {
  2013. position: absolute;
  2014. pointer-events: none;
  2015. top: 0;
  2016. width: 14px;
  2017. height: 24px;
  2018. opacity: 0;
  2019. background-color: transparent;
  2020. border: none;
  2021. transition: 60ms ease-out;
  2022. font-size: ${p => p.theme.fontSizeMedium};
  2023. color: ${p => p.theme.subText};
  2024. padding: 0 2px;
  2025. display: flex;
  2026. align-items: center;
  2027. &.Left {
  2028. left: 0;
  2029. }
  2030. &.Right {
  2031. right: 0;
  2032. transform: rotate(180deg);
  2033. }
  2034. }
  2035. .TraceBarDuration {
  2036. display: inline-block;
  2037. transform-origin: left center;
  2038. font-size: ${p => p.theme.fontSizeExtraSmall};
  2039. color: ${p => p.theme.gray300};
  2040. white-space: nowrap;
  2041. font-variant-numeric: tabular-nums;
  2042. position: absolute;
  2043. transition: color 0.1s ease-in-out;
  2044. }
  2045. .TraceChildrenCount {
  2046. height: 16px;
  2047. white-space: nowrap;
  2048. min-width: 30px;
  2049. display: flex;
  2050. align-items: center;
  2051. justify-content: center;
  2052. border-radius: 99px;
  2053. padding: 0px 4px;
  2054. transition: all 0.15s ease-in-out;
  2055. background: ${p => p.theme.background};
  2056. border: 2px solid ${p => p.theme.border};
  2057. line-height: 0;
  2058. z-index: 1;
  2059. font-size: 10px;
  2060. box-shadow: ${p => p.theme.dropShadowLight};
  2061. margin-right: 8px;
  2062. .TraceChildrenCountContent {
  2063. + .TraceChildrenCountAction {
  2064. margin-left: 2px;
  2065. }
  2066. }
  2067. .TraceChildrenCountAction {
  2068. position: relative;
  2069. display: flex;
  2070. align-items: center;
  2071. justify-content: center;
  2072. }
  2073. .TraceActionsLoadingIndicator {
  2074. margin: 0;
  2075. position: absolute;
  2076. top: 50%;
  2077. left: 50%;
  2078. transform: translate(-50%, -50%);
  2079. background-color: ${p => p.theme.background};
  2080. animation: show 0.1s ease-in-out forwards;
  2081. @keyframes show {
  2082. from {
  2083. opacity: 0;
  2084. transform: translate(-50%, -50%) scale(0.86);
  2085. }
  2086. to {
  2087. opacity: 1;
  2088. transform: translate(-50%, -50%) scale(1);
  2089. }
  2090. }
  2091. .loading-indicator {
  2092. border-width: 2px;
  2093. }
  2094. .loading-message {
  2095. display: none;
  2096. }
  2097. }
  2098. svg {
  2099. width: 7px;
  2100. transition: none;
  2101. }
  2102. }
  2103. .TraceChildrenCountWrapper {
  2104. display: flex;
  2105. justify-content: flex-end;
  2106. align-items: center;
  2107. min-width: 44px;
  2108. height: 100%;
  2109. position: relative;
  2110. button {
  2111. transition: none;
  2112. }
  2113. &.Orphaned {
  2114. .TraceVerticalConnector,
  2115. .TraceVerticalLastChildConnector,
  2116. .TraceExpandedVerticalConnector {
  2117. border-left: 2px dashed ${p => p.theme.border};
  2118. }
  2119. &::before {
  2120. border-bottom: 2px dashed ${p => p.theme.border};
  2121. }
  2122. }
  2123. &.Root {
  2124. &:before,
  2125. .TraceVerticalLastChildConnector {
  2126. visibility: hidden;
  2127. }
  2128. }
  2129. &::before {
  2130. content: '';
  2131. display: block;
  2132. width: 50%;
  2133. height: 2px;
  2134. border-bottom: 2px solid ${p => p.theme.border};
  2135. position: absolute;
  2136. left: 0;
  2137. top: 50%;
  2138. transform: translateY(-50%);
  2139. }
  2140. &::after {
  2141. content: '';
  2142. background-color: ${p => p.theme.border};
  2143. border-radius: 50%;
  2144. height: 6px;
  2145. width: 6px;
  2146. position: absolute;
  2147. left: 50%;
  2148. top: 50%;
  2149. transform: translateY(-50%);
  2150. }
  2151. }
  2152. .TraceVerticalConnector {
  2153. position: absolute;
  2154. left: 0;
  2155. top: 0;
  2156. bottom: 0;
  2157. height: 100%;
  2158. width: 2px;
  2159. border-left: 2px solid ${p => p.theme.border};
  2160. &.Orphaned {
  2161. border-left: 2px dashed ${p => p.theme.border};
  2162. }
  2163. }
  2164. .TraceVerticalLastChildConnector {
  2165. position: absolute;
  2166. left: 0;
  2167. top: 0;
  2168. bottom: 0;
  2169. height: 50%;
  2170. width: 2px;
  2171. border-left: 2px solid ${p => p.theme.border};
  2172. border-bottom-left-radius: 4px;
  2173. }
  2174. .TraceExpandedVerticalConnector {
  2175. position: absolute;
  2176. bottom: 0;
  2177. height: 50%;
  2178. left: 50%;
  2179. width: 2px;
  2180. border-left: 2px solid ${p => p.theme.border};
  2181. }
  2182. .TraceOperation {
  2183. margin-left: 4px;
  2184. text-overflow: ellipsis;
  2185. white-space: nowrap;
  2186. font-weight: bold;
  2187. }
  2188. .TraceEmDash {
  2189. margin-left: 4px;
  2190. margin-right: 4px;
  2191. }
  2192. .TraceDescription {
  2193. white-space: nowrap;
  2194. }
  2195. `;