trace.tsx 67 KB

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