trace.tsx 73 KB

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