trace.tsx 72 KB

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