trace.tsx 70 KB

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