trace.tsx 68 KB

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