index.tsx 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. import type React from 'react';
  2. import {
  3. Fragment,
  4. useCallback,
  5. useEffect,
  6. useLayoutEffect,
  7. useMemo,
  8. useReducer,
  9. useRef,
  10. useState,
  11. } from 'react';
  12. import {flushSync} from 'react-dom';
  13. import styled from '@emotion/styled';
  14. import * as Sentry from '@sentry/react';
  15. import * as qs from 'query-string';
  16. import {addSuccessMessage} from 'sentry/actionCreators/indicator';
  17. import {Button} from 'sentry/components/button';
  18. import useFeedbackWidget from 'sentry/components/feedback/widget/useFeedbackWidget';
  19. import LoadingIndicator from 'sentry/components/loadingIndicator';
  20. import NoProjectMessage from 'sentry/components/noProjectMessage';
  21. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  22. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  23. import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
  24. import {t, tct} from 'sentry/locale';
  25. import {space} from 'sentry/styles/space';
  26. import type {EventTransaction} from 'sentry/types/event';
  27. import type {Organization} from 'sentry/types/organization';
  28. import type {Project} from 'sentry/types/project';
  29. import {trackAnalytics} from 'sentry/utils/analytics';
  30. import {browserHistory} from 'sentry/utils/browserHistory';
  31. import EventView from 'sentry/utils/discover/eventView';
  32. import type {TraceSplitResults} from 'sentry/utils/performance/quickTrace/types';
  33. import {
  34. cancelAnimationTimeout,
  35. requestAnimationTimeout,
  36. } from 'sentry/utils/profiling/hooks/useVirtualizedTree/virtualizedTreeUtils';
  37. import type {UseApiQueryResult} from 'sentry/utils/queryClient';
  38. import {decodeScalar} from 'sentry/utils/queryString';
  39. import type RequestError from 'sentry/utils/requestError/requestError';
  40. import {capitalize} from 'sentry/utils/string/capitalize';
  41. import useApi from 'sentry/utils/useApi';
  42. import type {DispatchingReducerMiddleware} from 'sentry/utils/useDispatchingReducer';
  43. import useOrganization from 'sentry/utils/useOrganization';
  44. import usePageFilters from 'sentry/utils/usePageFilters';
  45. import {useParams} from 'sentry/utils/useParams';
  46. import useProjects from 'sentry/utils/useProjects';
  47. import type {ReplayTrace} from 'sentry/views/replays/detail/trace/useReplayTraces';
  48. import type {ReplayRecord} from 'sentry/views/replays/types';
  49. import {useTrace} from './traceApi/useTrace';
  50. import {type TraceMetaQueryResults, useTraceMeta} from './traceApi/useTraceMeta';
  51. import {useTraceRootEvent} from './traceApi/useTraceRootEvent';
  52. import {useTraceTree} from './traceApi/useTraceTree';
  53. import {TraceDrawer} from './traceDrawer/traceDrawer';
  54. import {TraceShape, TraceTree} from './traceModels/traceTree';
  55. import type {TraceTreeNode} from './traceModels/traceTreeNode';
  56. import {
  57. TraceEventPriority,
  58. type TraceEvents,
  59. TraceScheduler,
  60. } from './traceRenderers/traceScheduler';
  61. import {TraceView as TraceViewModel} from './traceRenderers/traceView';
  62. import {
  63. type ViewManagerScrollAnchor,
  64. VirtualizedViewManager,
  65. } from './traceRenderers/virtualizedViewManager';
  66. import {
  67. searchInTraceTreeText,
  68. searchInTraceTreeTokens,
  69. } from './traceSearch/traceSearchEvaluator';
  70. import {TraceSearchInput} from './traceSearch/traceSearchInput';
  71. import {parseTraceSearch} from './traceSearch/traceTokenConverter';
  72. import {
  73. DEFAULT_TRACE_VIEW_PREFERENCES,
  74. loadTraceViewPreferences,
  75. } from './traceState/tracePreferences';
  76. import {
  77. TraceStateProvider,
  78. useTraceState,
  79. useTraceStateDispatch,
  80. useTraceStateEmitter,
  81. } from './traceState/traceStateProvider';
  82. import {Trace} from './trace';
  83. import {traceAnalytics} from './traceAnalytics';
  84. import {
  85. isAutogroupedNode,
  86. isParentAutogroupedNode,
  87. isSiblingAutogroupedNode,
  88. isTraceNode,
  89. } from './traceGuards';
  90. import {TraceMetaDataHeader} from './traceHeader';
  91. import {TracePreferencesDropdown} from './tracePreferencesDropdown';
  92. import {TraceShortcuts} from './traceShortcutsModal';
  93. import type {TraceReducer, TraceReducerState} from './traceState';
  94. import {
  95. traceNodeAdjacentAnalyticsProperties,
  96. traceNodeAnalyticsName,
  97. } from './traceTreeAnalytics';
  98. import TraceTypeWarnings from './traceTypeWarnings';
  99. import {useTraceOnLoad} from './useTraceOnLoad';
  100. import {useTraceQueryParamStateSync} from './useTraceQueryParamStateSync';
  101. import {useTraceScrollToPath} from './useTraceScrollToPath';
  102. function logTraceMetadata(
  103. tree: TraceTree,
  104. projects: Project[],
  105. organization: Organization
  106. ) {
  107. switch (tree.shape) {
  108. case TraceShape.BROKEN_SUBTRACES:
  109. case TraceShape.EMPTY_TRACE:
  110. case TraceShape.MULTIPLE_ROOTS:
  111. case TraceShape.ONE_ROOT:
  112. case TraceShape.NO_ROOT:
  113. case TraceShape.ONLY_ERRORS:
  114. case TraceShape.BROWSER_MULTIPLE_ROOTS:
  115. traceAnalytics.trackTraceMetadata(tree, projects, organization);
  116. break;
  117. default: {
  118. Sentry.captureMessage('Unknown trace type');
  119. }
  120. }
  121. }
  122. export function TraceView() {
  123. const params = useParams<{traceSlug?: string}>();
  124. const organization = useOrganization();
  125. const traceSlug = useMemo(() => {
  126. const slug = params.traceSlug?.trim() ?? '';
  127. // null and undefined are not valid trace slugs, but they can be passed
  128. // in the URL and need to check for their string coerced values.
  129. if (!slug || slug === 'null' || slug === 'undefined') {
  130. Sentry.withScope(scope => {
  131. scope.setFingerprint(['trace-null-slug']);
  132. Sentry.captureMessage(`Trace slug is empty`);
  133. });
  134. }
  135. return slug;
  136. }, [params.traceSlug]);
  137. const queryParams = useMemo(() => {
  138. const normalizedParams = normalizeDateTimeParams(qs.parse(location.search), {
  139. allowAbsolutePageDatetime: true,
  140. });
  141. const start = decodeScalar(normalizedParams.start);
  142. const timestamp: string | undefined = decodeScalar(normalizedParams.timestamp);
  143. const end = decodeScalar(normalizedParams.end);
  144. const statsPeriod = decodeScalar(normalizedParams.statsPeriod);
  145. const numberTimestamp = timestamp ? Number(timestamp) : undefined;
  146. return {start, end, statsPeriod, timestamp: numberTimestamp, useSpans: 1};
  147. }, []);
  148. const traceEventView = useMemo(() => {
  149. const {start, end, statsPeriod, timestamp} = queryParams;
  150. let startTimeStamp = start;
  151. let endTimeStamp = end;
  152. // If timestamp exists in the query params, we want to use it to set the start and end time
  153. // with a buffer of 1.5 days, for retrieving events belonging to the trace.
  154. if (typeof timestamp === 'number') {
  155. const buffer = 36 * 60 * 60 * 1000; // 1.5 days in milliseconds
  156. const dateFromTimestamp = new Date(timestamp * 1000);
  157. startTimeStamp = new Date(dateFromTimestamp.getTime() - buffer).toISOString();
  158. endTimeStamp = new Date(dateFromTimestamp.getTime() + buffer).toISOString();
  159. }
  160. return EventView.fromSavedQuery({
  161. id: undefined,
  162. name: `Events with Trace ID ${traceSlug}`,
  163. fields: ['title', 'event.type', 'project', 'timestamp'],
  164. orderby: '-timestamp',
  165. query: `trace:${traceSlug}`,
  166. projects: [ALL_ACCESS_PROJECTS],
  167. version: 2,
  168. start: startTimeStamp,
  169. end: endTimeStamp,
  170. range: !(startTimeStamp || endTimeStamp) ? statsPeriod : undefined,
  171. });
  172. }, [queryParams, traceSlug]);
  173. const preferences = useMemo(
  174. () =>
  175. loadTraceViewPreferences('trace-view-preferences') ||
  176. DEFAULT_TRACE_VIEW_PREFERENCES,
  177. []
  178. );
  179. const meta = useTraceMeta([{traceSlug, timestamp: queryParams.timestamp}]);
  180. const trace = useTrace({traceSlug, timestamp: queryParams.timestamp});
  181. const rootEvent = useTraceRootEvent(trace.data ?? null);
  182. const tree = useTraceTree({traceSlug, trace, meta, replay: null});
  183. const title = useMemo(() => {
  184. return `${t('Trace Details')} - ${traceSlug}`;
  185. }, [traceSlug]);
  186. return (
  187. <SentryDocumentTitle title={title} orgSlug={organization.slug}>
  188. <TraceStateProvider
  189. initialPreferences={preferences}
  190. preferencesStorageKey="trace-view-preferences"
  191. >
  192. <NoProjectMessage organization={organization}>
  193. <TraceExternalLayout>
  194. <TraceMetaDataHeader
  195. rootEventResults={rootEvent}
  196. tree={tree}
  197. metaResults={meta}
  198. organization={organization}
  199. traceSlug={traceSlug}
  200. traceEventView={traceEventView}
  201. />
  202. <TraceInnerLayout>
  203. <TraceViewWaterfall
  204. tree={tree}
  205. trace={trace}
  206. meta={meta}
  207. replay={null}
  208. rootEvent={rootEvent}
  209. traceSlug={traceSlug}
  210. traceEventView={traceEventView}
  211. organization={organization}
  212. source="performance"
  213. isEmbedded={false}
  214. />
  215. </TraceInnerLayout>
  216. </TraceExternalLayout>
  217. </NoProjectMessage>
  218. </TraceStateProvider>
  219. </SentryDocumentTitle>
  220. );
  221. }
  222. const TRACE_TAB: TraceReducerState['tabs']['tabs'][0] = {
  223. node: 'trace',
  224. label: t('Trace'),
  225. };
  226. const VITALS_TAB: TraceReducerState['tabs']['tabs'][0] = {
  227. node: 'vitals',
  228. label: t('Vitals'),
  229. };
  230. type TraceViewWaterfallProps = {
  231. isEmbedded: boolean;
  232. meta: TraceMetaQueryResults;
  233. organization: Organization;
  234. replay: ReplayRecord | null;
  235. rootEvent: UseApiQueryResult<EventTransaction, RequestError>;
  236. source: string;
  237. trace: UseApiQueryResult<TraceSplitResults<TraceTree.Transaction>, RequestError>;
  238. traceEventView: EventView;
  239. traceSlug: string | undefined;
  240. tree: TraceTree;
  241. replayTraces?: ReplayTrace[];
  242. /**
  243. * Ignore eventId or path query parameters and use the provided node.
  244. * Must be set at component mount, no reactivity
  245. */
  246. scrollToNode?: {eventId?: string; path?: TraceTree.NodePath[]};
  247. };
  248. export function TraceViewWaterfall(props: TraceViewWaterfallProps) {
  249. const api = useApi();
  250. const filters = usePageFilters();
  251. const {projects} = useProjects();
  252. const organization = useOrganization();
  253. const traceState = useTraceState();
  254. const traceDispatch = useTraceStateDispatch();
  255. const traceStateEmitter = useTraceStateEmitter();
  256. const [forceRender, rerender] = useReducer(x => (x + 1) % Number.MAX_SAFE_INTEGER, 0);
  257. const traceView = useMemo(() => new TraceViewModel(), []);
  258. const traceScheduler = useMemo(() => new TraceScheduler(), []);
  259. const projectsRef = useRef<Project[]>(projects);
  260. projectsRef.current = projects;
  261. const scrollQueueRef = useTraceScrollToPath(props.scrollToNode);
  262. const forceRerender = useCallback(() => {
  263. flushSync(rerender);
  264. }, []);
  265. useEffect(() => {
  266. trackAnalytics('performance_views.trace_view_v1_page_load', {
  267. organization: props.organization,
  268. source: props.source,
  269. });
  270. }, [props.organization, props.source]);
  271. const previouslyFocusedNodeRef = useRef<TraceTreeNode<TraceTree.NodeValue> | null>(
  272. null
  273. );
  274. const previouslyScrolledToNodeRef = useRef<TraceTreeNode<TraceTree.NodeValue> | null>(
  275. null
  276. );
  277. useEffect(() => {
  278. if (!props.replayTraces?.length || props.tree?.type !== 'trace') {
  279. return undefined;
  280. }
  281. const cleanup = props.tree.fetchAdditionalTraces({
  282. api,
  283. filters,
  284. replayTraces: props.replayTraces,
  285. organization: props.organization,
  286. urlParams: qs.parse(location.search),
  287. rerender: forceRerender,
  288. meta: props.meta,
  289. });
  290. return () => cleanup();
  291. // eslint-disable-next-line react-hooks/exhaustive-deps
  292. }, [props.tree, props.replayTraces]);
  293. // Assign the trace state to a ref so we can access it without re-rendering
  294. const traceStateRef = useRef<TraceReducerState>(traceState);
  295. traceStateRef.current = traceState;
  296. const traceStatePreferencesRef = useRef<
  297. Pick<TraceReducerState['preferences'], 'autogroup' | 'missing_instrumentation'>
  298. >(traceState.preferences);
  299. traceStatePreferencesRef.current = traceState.preferences;
  300. // Initialize the view manager right after the state reducer
  301. const viewManager = useMemo(() => {
  302. return new VirtualizedViewManager(
  303. {
  304. list: {width: traceState.preferences.list.width},
  305. span_list: {width: 1 - traceState.preferences.list.width},
  306. },
  307. traceScheduler,
  308. traceView
  309. );
  310. // We only care about initial state when we initialize the view manager
  311. // eslint-disable-next-line react-hooks/exhaustive-deps
  312. }, []);
  313. useLayoutEffect(() => {
  314. const onTraceViewChange: TraceEvents['set trace view'] = view => {
  315. traceView.setTraceView(view);
  316. viewManager.enqueueFOVQueryParamSync(traceView);
  317. };
  318. const onPhysicalSpaceChange: TraceEvents['set container physical space'] =
  319. container => {
  320. traceView.setTracePhysicalSpace(container, [
  321. 0,
  322. 0,
  323. container[2] * viewManager.columns.span_list.width,
  324. container[3],
  325. ]);
  326. };
  327. const onTraceSpaceChange: TraceEvents['initialize trace space'] = view => {
  328. traceView.setTraceSpace(view);
  329. };
  330. // These handlers have high priority because they are responsible for
  331. // updating the view coordinates. If we update them first, then any components downstream
  332. // that rely on the view coordinates will be in sync with the view.
  333. traceScheduler.on('set trace view', onTraceViewChange, TraceEventPriority.HIGH);
  334. traceScheduler.on('set trace space', onTraceSpaceChange, TraceEventPriority.HIGH);
  335. traceScheduler.on(
  336. 'set container physical space',
  337. onPhysicalSpaceChange,
  338. TraceEventPriority.HIGH
  339. );
  340. traceScheduler.on(
  341. 'initialize trace space',
  342. onTraceSpaceChange,
  343. TraceEventPriority.HIGH
  344. );
  345. return () => {
  346. traceScheduler.off('set trace view', onTraceViewChange);
  347. traceScheduler.off('set trace space', onTraceSpaceChange);
  348. traceScheduler.off('set container physical space', onPhysicalSpaceChange);
  349. traceScheduler.off('initialize trace space', onTraceSpaceChange);
  350. };
  351. }, [traceScheduler, traceView, viewManager]);
  352. // Initialize the tabs reducer when the tree initializes
  353. useLayoutEffect(() => {
  354. return traceDispatch({
  355. type: 'set roving count',
  356. items: props.tree.list.length - 1,
  357. });
  358. }, [props.tree.list.length, traceDispatch]);
  359. // Initialize the tabs reducer when the tree initializes
  360. useLayoutEffect(() => {
  361. if (props.tree.type !== 'trace') {
  362. return;
  363. }
  364. const newTabs = [TRACE_TAB];
  365. if (props.tree.vitals.size > 0) {
  366. const types = Array.from(props.tree.vital_types.values());
  367. const label = types.length > 1 ? t('Vitals') : capitalize(types[0]) + ' Vitals';
  368. newTabs.push({
  369. ...VITALS_TAB,
  370. label,
  371. });
  372. }
  373. if (props.tree.profiled_events.size > 0) {
  374. newTabs.push({
  375. node: 'profiles',
  376. label: 'Profiles',
  377. });
  378. }
  379. traceDispatch({
  380. type: 'initialize tabs reducer',
  381. payload: {
  382. current_tab: traceStateRef?.current?.tabs?.tabs?.[0],
  383. tabs: newTabs,
  384. last_clicked_tab: null,
  385. },
  386. });
  387. // We only want to update the tabs when the tree changes
  388. // eslint-disable-next-line react-hooks/exhaustive-deps
  389. }, [props.tree]);
  390. const searchingRaf = useRef<{id: number | null} | null>(null);
  391. const onTraceSearch = useCallback(
  392. (
  393. query: string,
  394. activeNode: TraceTreeNode<TraceTree.NodeValue> | null,
  395. behavior: 'track result' | 'persist'
  396. ) => {
  397. if (searchingRaf.current?.id) {
  398. window.cancelAnimationFrame(searchingRaf.current.id);
  399. searchingRaf.current = null;
  400. }
  401. function done([matches, lookup, activeNodeSearchResult]) {
  402. // If the previous node is still in the results set, we want to keep it
  403. if (activeNodeSearchResult) {
  404. traceDispatch({
  405. type: 'set results',
  406. results: matches,
  407. resultsLookup: lookup,
  408. resultIteratorIndex: activeNodeSearchResult?.resultIteratorIndex,
  409. resultIndex: activeNodeSearchResult?.resultIndex,
  410. previousNode: activeNodeSearchResult,
  411. node: activeNode,
  412. });
  413. return;
  414. }
  415. if (activeNode && behavior === 'persist') {
  416. traceDispatch({
  417. type: 'set results',
  418. results: matches,
  419. resultsLookup: lookup,
  420. resultIteratorIndex: undefined,
  421. resultIndex: undefined,
  422. previousNode: null,
  423. node: activeNode,
  424. });
  425. return;
  426. }
  427. const resultIndex: number | undefined = matches?.[0]?.index;
  428. const resultIteratorIndex: number | undefined = matches?.[0] ? 0 : undefined;
  429. const node: TraceTreeNode<TraceTree.NodeValue> | null = matches?.[0]?.value;
  430. traceDispatch({
  431. type: 'set results',
  432. results: matches,
  433. resultsLookup: lookup,
  434. resultIteratorIndex: resultIteratorIndex,
  435. resultIndex: resultIndex,
  436. previousNode: activeNodeSearchResult,
  437. node,
  438. });
  439. }
  440. const tokens = parseTraceSearch(query);
  441. if (tokens) {
  442. searchingRaf.current = searchInTraceTreeTokens(
  443. props.tree,
  444. tokens,
  445. activeNode,
  446. done
  447. );
  448. } else {
  449. searchingRaf.current = searchInTraceTreeText(props.tree, query, activeNode, done);
  450. }
  451. },
  452. [traceDispatch, props.tree]
  453. );
  454. // We need to heavily debounce query string updates because the rest of the app is so slow
  455. // to rerender that it causes the search to drop frames on every keystroke...
  456. const QUERY_STRING_STATE_DEBOUNCE = 300;
  457. const queryStringAnimationTimeoutRef = useRef<{id: number} | null>(null);
  458. const setRowAsFocused = useCallback(
  459. (
  460. node: TraceTreeNode<TraceTree.NodeValue> | null,
  461. event: React.MouseEvent<HTMLElement> | null,
  462. resultsLookup: Map<TraceTreeNode<TraceTree.NodeValue>, number>,
  463. index: number | null,
  464. debounce: number = QUERY_STRING_STATE_DEBOUNCE
  465. ) => {
  466. // sync query string with the clicked node
  467. if (node) {
  468. if (queryStringAnimationTimeoutRef.current) {
  469. cancelAnimationTimeout(queryStringAnimationTimeoutRef.current);
  470. }
  471. queryStringAnimationTimeoutRef.current = requestAnimationTimeout(() => {
  472. const currentQueryStringPath = qs.parse(location.search).node;
  473. const nextNodePath = TraceTree.PathToNode(node);
  474. // Updating the query string with the same path is problematic because it causes
  475. // the entire sentry app to rerender, which is enough to cause jank and drop frames
  476. if (JSON.stringify(currentQueryStringPath) === JSON.stringify(nextNodePath)) {
  477. return;
  478. }
  479. const {eventId: _eventId, ...query} = qs.parse(location.search);
  480. browserHistory.replace({
  481. pathname: location.pathname,
  482. query: {
  483. ...query,
  484. node: nextNodePath,
  485. },
  486. });
  487. queryStringAnimationTimeoutRef.current = null;
  488. }, debounce);
  489. if (resultsLookup.has(node) && typeof index === 'number') {
  490. traceDispatch({
  491. type: 'set search iterator index',
  492. resultIndex: index,
  493. resultIteratorIndex: resultsLookup.get(node)!,
  494. });
  495. }
  496. if (isTraceNode(node)) {
  497. traceDispatch({type: 'activate tab', payload: TRACE_TAB.node});
  498. return;
  499. }
  500. traceDispatch({
  501. type: 'activate tab',
  502. payload: node,
  503. pin_previous: event?.metaKey,
  504. });
  505. }
  506. },
  507. [traceDispatch]
  508. );
  509. const onRowClick = useCallback(
  510. (
  511. node: TraceTreeNode<TraceTree.NodeValue>,
  512. event: React.MouseEvent<HTMLElement>,
  513. index: number
  514. ) => {
  515. trackAnalytics('trace.trace_layout.span_row_click', {
  516. organization,
  517. num_children: node.children.length,
  518. type: traceNodeAnalyticsName(node),
  519. project_platform:
  520. projects.find(p => p.slug === node.metadata.project_slug)?.platform || 'other',
  521. ...traceNodeAdjacentAnalyticsProperties(node),
  522. });
  523. if (traceStateRef.current.preferences.drawer.minimized) {
  524. traceDispatch({type: 'minimize drawer', payload: false});
  525. }
  526. setRowAsFocused(node, event, traceStateRef.current.search.resultsLookup, null, 0);
  527. if (traceStateRef.current.search.resultsLookup.has(node)) {
  528. const idx = traceStateRef.current.search.resultsLookup.get(node)!;
  529. traceDispatch({
  530. type: 'set search iterator index',
  531. resultIndex: index,
  532. resultIteratorIndex: idx,
  533. });
  534. } else if (traceStateRef.current.search.resultIteratorIndex !== null) {
  535. traceDispatch({type: 'clear search iterator index'});
  536. }
  537. traceDispatch({
  538. type: 'set roving index',
  539. action_source: 'click',
  540. index,
  541. node,
  542. });
  543. },
  544. [setRowAsFocused, traceDispatch, organization, projects]
  545. );
  546. const scrollRowIntoView = useCallback(
  547. (
  548. node: TraceTreeNode<TraceTree.NodeValue>,
  549. index: number,
  550. anchor?: ViewManagerScrollAnchor,
  551. force?: boolean
  552. ) => {
  553. // Last node we scrolled to is the same as the node we want to scroll to
  554. if (previouslyScrolledToNodeRef.current === node && !force) {
  555. return;
  556. }
  557. // Always scroll to the row vertically
  558. viewManager.scrollToRow(index, anchor);
  559. if (viewManager.isOutsideOfView(node)) {
  560. viewManager.scrollRowIntoViewHorizontally(node, 0, 48, 'measured');
  561. }
  562. previouslyScrolledToNodeRef.current = node;
  563. },
  564. [viewManager]
  565. );
  566. const onScrollToNode = useCallback(
  567. (
  568. node: TraceTreeNode<TraceTree.NodeValue>
  569. ): Promise<TraceTreeNode<TraceTree.NodeValue> | null> => {
  570. return TraceTree.ExpandToPath(props.tree, TraceTree.PathToNode(node), {
  571. api,
  572. organization: props.organization,
  573. preferences: traceStatePreferencesRef.current,
  574. }).then(() => {
  575. const maybeNode = TraceTree.Find(props.tree.root, n => n === node);
  576. if (!maybeNode) {
  577. return null;
  578. }
  579. const index = TraceTree.EnforceVisibility(props.tree, maybeNode);
  580. if (index === -1) {
  581. return null;
  582. }
  583. scrollRowIntoView(maybeNode, index, 'center if outside', true);
  584. traceDispatch({
  585. type: 'set roving index',
  586. node: maybeNode,
  587. index: index,
  588. action_source: 'click',
  589. });
  590. if (traceStateRef.current.search.resultsLookup.has(maybeNode)) {
  591. traceDispatch({
  592. type: 'set search iterator index',
  593. resultIndex: index,
  594. resultIteratorIndex:
  595. traceStateRef.current.search.resultsLookup.get(maybeNode)!,
  596. });
  597. } else if (traceStateRef.current.search.resultIteratorIndex !== null) {
  598. traceDispatch({type: 'clear search iterator index'});
  599. }
  600. return maybeNode;
  601. });
  602. },
  603. [api, props.organization, scrollRowIntoView, props.tree, traceDispatch]
  604. );
  605. const onTabScrollToNode = useCallback(
  606. (
  607. node: TraceTreeNode<TraceTree.NodeValue>
  608. ): Promise<TraceTreeNode<TraceTree.NodeValue> | null> => {
  609. return onScrollToNode(node).then(maybeNode => {
  610. if (maybeNode) {
  611. setRowAsFocused(
  612. maybeNode,
  613. null,
  614. traceStateRef.current.search.resultsLookup,
  615. null,
  616. 0
  617. );
  618. }
  619. return maybeNode;
  620. });
  621. },
  622. [onScrollToNode, setRowAsFocused]
  623. );
  624. // Callback that is invoked when the trace loads and reaches its initialied state,
  625. // that is when the trace tree data and any data that the trace depends on is loaded,
  626. // but the trace is not yet rendered in the view.
  627. const onTraceLoad = useCallback(() => {
  628. logTraceMetadata(props.tree, projectsRef.current, props.organization);
  629. // The tree has the data fetched, but does not yet respect the user preferences.
  630. // We will autogroup and inject missing instrumentation if the preferences are set.
  631. // and then we will perform a search to find the node the user is interested in.
  632. const query = qs.parse(location.search);
  633. if (query.fov && typeof query.fov === 'string') {
  634. viewManager.maybeInitializeTraceViewFromQS(query.fov);
  635. }
  636. if (traceStateRef.current.preferences.missing_instrumentation) {
  637. TraceTree.DetectMissingInstrumentation(props.tree.root);
  638. }
  639. if (traceStateRef.current.preferences.autogroup.sibling) {
  640. TraceTree.AutogroupSiblingSpanNodes(props.tree.root);
  641. }
  642. if (traceStateRef.current.preferences.autogroup.parent) {
  643. TraceTree.AutogroupDirectChildrenSpanNodes(props.tree.root);
  644. }
  645. // Construct the visual representation of the tree
  646. props.tree.build();
  647. const eventId = scrollQueueRef.current?.eventId;
  648. const [type, path] = scrollQueueRef.current?.path?.[0]?.split('-') ?? [];
  649. scrollQueueRef.current = null;
  650. let node =
  651. (path === 'root' && props.tree.root.children[0]) ||
  652. (path && TraceTree.FindByID(props.tree.root, path)) ||
  653. (eventId && TraceTree.FindByID(props.tree.root, eventId)) ||
  654. null;
  655. // If the node points to a span, but we found an autogrouped node, then
  656. // perform another search inside the autogrouped node to find the more detailed
  657. // location of the span. This is necessary because the id of the autogrouped node
  658. // is in some cases inferred from the spans it contains and searching by the span id
  659. // just gives us the first match which may not be the one the user is looking for.
  660. if (node) {
  661. if (isAutogroupedNode(node) && type !== 'ag') {
  662. if (isParentAutogroupedNode(node)) {
  663. node = TraceTree.FindByID(node.head, eventId ?? path) ?? node;
  664. } else if (isSiblingAutogroupedNode(node)) {
  665. node = node.children.find(n => TraceTree.FindByID(n, eventId ?? path)) ?? node;
  666. }
  667. }
  668. }
  669. const index = node ? TraceTree.EnforceVisibility(props.tree, node) : -1;
  670. if (traceStateRef.current.search.query) {
  671. onTraceSearch(traceStateRef.current.search.query, node, 'persist');
  672. }
  673. if (index === -1 || !node) {
  674. const hasScrollComponent = !!(path || eventId);
  675. if (hasScrollComponent) {
  676. Sentry.withScope(scope => {
  677. scope.setFingerprint(['trace-view-scroll-to-node-error']);
  678. scope.captureMessage('Failed to scroll to node in trace tree');
  679. });
  680. }
  681. return;
  682. }
  683. // At load time, we want to scroll the row into view, but we need to wait for the view
  684. // to initialize before we can do that. We listen for the 'initialize virtualized list' and scroll
  685. // to the row in the view if it is not in view yet. If its in the view, then scroll to it immediately.
  686. traceScheduler.once('initialize virtualized list', () => {
  687. function onTargetRowMeasure() {
  688. if (!node || !viewManager.row_measurer.cache.has(node)) {
  689. return;
  690. }
  691. viewManager.row_measurer.off('row measure end', onTargetRowMeasure);
  692. if (viewManager.isOutsideOfView(node)) {
  693. viewManager.scrollRowIntoViewHorizontally(node!, 0, 48, 'measured');
  694. }
  695. }
  696. viewManager.scrollToRow(index, 'center');
  697. viewManager.row_measurer.on('row measure end', onTargetRowMeasure);
  698. previouslyScrolledToNodeRef.current = node;
  699. setRowAsFocused(node, null, traceStateRef.current.search.resultsLookup, index);
  700. traceDispatch({
  701. type: 'set roving index',
  702. node: node,
  703. index: index,
  704. action_source: 'load',
  705. });
  706. });
  707. }, [
  708. setRowAsFocused,
  709. traceDispatch,
  710. onTraceSearch,
  711. viewManager,
  712. traceScheduler,
  713. scrollQueueRef,
  714. props.tree,
  715. props.organization,
  716. ]);
  717. // Setup the middleware for the trace reducer
  718. useLayoutEffect(() => {
  719. const beforeTraceNextStateDispatch: DispatchingReducerMiddleware<
  720. typeof TraceReducer
  721. >['before next state'] = (prevState, nextState, action) => {
  722. // This effect is responsible fo syncing the keyboard interactions with the search results,
  723. // we observe the changes to the roving tab index and search results and react by syncing the state.
  724. const {node: nextRovingNode, index: nextRovingTabIndex} = nextState.rovingTabIndex;
  725. const {resultIndex: nextSearchResultIndex} = nextState.search;
  726. if (
  727. nextRovingNode &&
  728. action.type === 'set roving index' &&
  729. action.action_source !== 'click' &&
  730. typeof nextRovingTabIndex === 'number' &&
  731. prevState.rovingTabIndex.node !== nextRovingNode
  732. ) {
  733. // When the roving tabIndex updates mark the node as focused and sync search results
  734. setRowAsFocused(
  735. nextRovingNode,
  736. null,
  737. nextState.search.resultsLookup,
  738. nextRovingTabIndex
  739. );
  740. if (action.type === 'set roving index' && action.action_source === 'keyboard') {
  741. scrollRowIntoView(nextRovingNode, nextRovingTabIndex, undefined);
  742. }
  743. if (nextState.search.resultsLookup.has(nextRovingNode)) {
  744. const idx = nextState.search.resultsLookup.get(nextRovingNode)!;
  745. traceDispatch({
  746. type: 'set search iterator index',
  747. resultIndex: nextRovingTabIndex,
  748. resultIteratorIndex: idx,
  749. });
  750. } else if (nextState.search.resultIteratorIndex !== null) {
  751. traceDispatch({type: 'clear search iterator index'});
  752. }
  753. } else if (
  754. typeof nextSearchResultIndex === 'number' &&
  755. prevState.search.resultIndex !== nextSearchResultIndex &&
  756. action.type !== 'set search iterator index'
  757. ) {
  758. // If the search result index changes, mark the node as focused and scroll it into view
  759. const nextNode = props.tree.list[nextSearchResultIndex];
  760. setRowAsFocused(
  761. nextNode,
  762. null,
  763. nextState.search.resultsLookup,
  764. nextSearchResultIndex
  765. );
  766. scrollRowIntoView(nextNode, nextSearchResultIndex, 'center if outside');
  767. }
  768. };
  769. traceStateEmitter.on('before next state', beforeTraceNextStateDispatch);
  770. return () => {
  771. traceStateEmitter.off('before next state', beforeTraceNextStateDispatch);
  772. };
  773. }, [
  774. props.tree,
  775. onTraceSearch,
  776. traceStateEmitter,
  777. traceDispatch,
  778. setRowAsFocused,
  779. scrollRowIntoView,
  780. ]);
  781. // Setup the middleware for the view manager and store the list width as a preference
  782. useLayoutEffect(() => {
  783. function onDividerResizeEnd(list_width: number) {
  784. traceDispatch({
  785. type: 'set list width',
  786. payload: list_width,
  787. });
  788. }
  789. traceScheduler.on('divider resize end', onDividerResizeEnd);
  790. return () => {
  791. traceScheduler.off('divider resize end', onDividerResizeEnd);
  792. };
  793. }, [traceScheduler, traceDispatch]);
  794. const [traceGridRef, setTraceGridRef] = useState<HTMLElement | null>(null);
  795. // Memoized because it requires tree traversal
  796. const shape = useMemo(() => props.tree.shape, [props.tree]);
  797. useLayoutEffect(() => {
  798. if (props.tree.type !== 'trace') {
  799. return undefined;
  800. }
  801. traceScheduler.dispatch('initialize trace space', [
  802. props.tree.root.space[0],
  803. 0,
  804. props.tree.root.space[1],
  805. 1,
  806. ]);
  807. // Whenever the timeline changes, update the trace space and trigger a redraw
  808. const onTraceTimelineChange = (s: [number, number]) => {
  809. traceScheduler.dispatch('set trace space', [s[0], 0, s[1], 1]);
  810. };
  811. props.tree.on('trace timeline change', onTraceTimelineChange);
  812. return () => {
  813. props.tree.off('trace timeline change', onTraceTimelineChange);
  814. };
  815. }, [viewManager, traceScheduler, props.tree]);
  816. const onLoadScrollStatus = useTraceOnLoad({
  817. onTraceLoad,
  818. pathToNodeOrEventId: scrollQueueRef.current,
  819. tree: props.tree,
  820. });
  821. // Sync part of the state with the URL
  822. const traceQueryStateSync = useMemo(() => {
  823. return {search: traceState.search.query};
  824. }, [traceState.search.query]);
  825. useTraceQueryParamStateSync(traceQueryStateSync);
  826. const onAutogroupChange = useCallback(() => {
  827. const value = !traceState.preferences.autogroup.parent;
  828. if (!value) {
  829. let removeCount = 0;
  830. removeCount += TraceTree.RemoveSiblingAutogroupNodes(props.tree.root);
  831. removeCount += TraceTree.RemoveDirectChildrenAutogroupNodes(props.tree.root);
  832. addSuccessMessage(
  833. removeCount > 0
  834. ? tct('Autogrouping disabled, removed [count] autogroup spans', {
  835. count: removeCount,
  836. })
  837. : t('Autogrouping disabled')
  838. );
  839. } else {
  840. let autogroupCount = 0;
  841. autogroupCount += TraceTree.AutogroupSiblingSpanNodes(props.tree.root);
  842. autogroupCount += TraceTree.AutogroupDirectChildrenSpanNodes(props.tree.root);
  843. addSuccessMessage(
  844. autogroupCount > 0
  845. ? tct('Autogrouping enabled, detected [count] autogrouping spans', {
  846. count: autogroupCount,
  847. })
  848. : t('Autogrouping enabled')
  849. );
  850. }
  851. traceAnalytics.trackAutogroupingPreferenceChange(props.organization, value);
  852. props.tree.rebuild();
  853. traceDispatch({
  854. type: 'set autogrouping',
  855. payload: value,
  856. });
  857. }, [traceDispatch, traceState.preferences.autogroup, props.tree, props.organization]);
  858. const onMissingInstrumentationChange = useCallback(() => {
  859. const value = !traceState.preferences.missing_instrumentation;
  860. if (!value) {
  861. const removeCount = TraceTree.RemoveMissingInstrumentationNodes(props.tree.root);
  862. addSuccessMessage(
  863. removeCount > 0
  864. ? tct(
  865. 'Missing instrumentation disabled, removed [count] missing instrumentation spans',
  866. {
  867. count: removeCount,
  868. }
  869. )
  870. : t('Missing instrumentation disabled')
  871. );
  872. } else {
  873. const missingInstrumentationCount = TraceTree.DetectMissingInstrumentation(
  874. props.tree.root
  875. );
  876. addSuccessMessage(
  877. missingInstrumentationCount > 0
  878. ? tct(
  879. 'Missing instrumentation enabled, found [count] missing instrumentation spans',
  880. {
  881. count: missingInstrumentationCount,
  882. }
  883. )
  884. : t('Missing instrumentation enabled')
  885. );
  886. }
  887. traceAnalytics.trackMissingInstrumentationPreferenceChange(props.organization, value);
  888. props.tree.rebuild();
  889. traceDispatch({
  890. type: 'set missing instrumentation',
  891. payload: value,
  892. });
  893. }, [
  894. traceDispatch,
  895. traceState.preferences.missing_instrumentation,
  896. props.tree,
  897. props.organization,
  898. ]);
  899. return (
  900. <Fragment>
  901. <TraceTypeWarnings
  902. tree={props.tree}
  903. traceSlug={props.traceSlug}
  904. organization={organization}
  905. />
  906. <TraceToolbar>
  907. <TraceSearchInput onTraceSearch={onTraceSearch} organization={organization} />
  908. <TraceResetZoomButton
  909. viewManager={viewManager}
  910. organization={props.organization}
  911. />
  912. <TraceShortcuts />
  913. <TracePreferencesDropdown
  914. autogroup={
  915. traceState.preferences.autogroup.parent &&
  916. traceState.preferences.autogroup.sibling
  917. }
  918. missingInstrumentation={traceState.preferences.missing_instrumentation}
  919. onAutogroupChange={onAutogroupChange}
  920. onMissingInstrumentationChange={onMissingInstrumentationChange}
  921. />
  922. </TraceToolbar>
  923. <TraceGrid layout={traceState.preferences.layout} ref={setTraceGridRef}>
  924. <Trace
  925. trace={props.tree}
  926. rerender={rerender}
  927. trace_id={props.traceSlug}
  928. onRowClick={onRowClick}
  929. onTraceSearch={onTraceSearch}
  930. previouslyFocusedNodeRef={previouslyFocusedNodeRef}
  931. manager={viewManager}
  932. scheduler={traceScheduler}
  933. forceRerender={forceRender}
  934. isEmbedded={props.isEmbedded}
  935. isLoading={props.tree.type === 'loading' || onLoadScrollStatus === 'pending'}
  936. />
  937. {props.tree.type === 'loading' || onLoadScrollStatus === 'pending' ? (
  938. <TraceLoading />
  939. ) : props.tree.type === 'error' ? (
  940. <TraceError />
  941. ) : props.tree.type === 'empty' ? (
  942. <TraceEmpty />
  943. ) : null}
  944. <TraceDrawer
  945. replay={props.replay}
  946. meta={props.meta}
  947. traceType={shape}
  948. trace={props.tree}
  949. traceGridRef={traceGridRef}
  950. manager={viewManager}
  951. scheduler={traceScheduler}
  952. onTabScrollToNode={onTabScrollToNode}
  953. onScrollToNode={onScrollToNode}
  954. rootEventResults={props.rootEvent}
  955. traceEventView={props.traceEventView}
  956. />
  957. </TraceGrid>
  958. </Fragment>
  959. );
  960. }
  961. function TraceResetZoomButton(props: {
  962. organization: Organization;
  963. viewManager: VirtualizedViewManager;
  964. }) {
  965. const onResetZoom = useCallback(() => {
  966. traceAnalytics.trackResetZoom(props.organization);
  967. props.viewManager.resetZoom();
  968. }, [props.viewManager, props.organization]);
  969. return (
  970. <ResetZoomButton
  971. size="xs"
  972. onClick={onResetZoom}
  973. ref={props.viewManager.registerResetZoomRef}
  974. >
  975. {t('Reset Zoom')}
  976. </ResetZoomButton>
  977. );
  978. }
  979. const ResetZoomButton = styled(Button)`
  980. transition: opacity 0.2s 0.5s ease-in-out;
  981. &[disabled] {
  982. cursor: not-allowed;
  983. opacity: 0.65;
  984. }
  985. `;
  986. const TraceExternalLayout = styled('div')`
  987. display: flex;
  988. flex-direction: column;
  989. flex: 1 1 100%;
  990. ~ footer {
  991. display: none;
  992. }
  993. `;
  994. const TraceInnerLayout = styled('div')`
  995. display: flex;
  996. flex-direction: column;
  997. flex: 1 1 100%;
  998. padding: ${space(2)};
  999. background-color: ${p => p.theme.background};
  1000. `;
  1001. const TraceToolbar = styled('div')`
  1002. flex-grow: 0;
  1003. display: grid;
  1004. grid-template-columns: 1fr min-content min-content min-content;
  1005. gap: ${space(1)};
  1006. `;
  1007. const TraceGrid = styled('div')<{
  1008. layout: 'drawer bottom' | 'drawer left' | 'drawer right';
  1009. }>`
  1010. --info: ${p => p.theme.purple400};
  1011. --warning: ${p => p.theme.yellow300};
  1012. --debug: ${p => p.theme.blue300};
  1013. --error: ${p => p.theme.error};
  1014. --fatal: ${p => p.theme.error};
  1015. --default: ${p => p.theme.gray300};
  1016. --unknown: ${p => p.theme.gray300};
  1017. --profile: ${p => p.theme.purple300};
  1018. --autogrouped: ${p => p.theme.blue300};
  1019. --performance-issue: ${p => p.theme.blue300};
  1020. border: 1px solid ${p => p.theme.border};
  1021. flex: 1 1 100%;
  1022. display: grid;
  1023. border-radius: ${p => p.theme.borderRadius};
  1024. overflow: hidden;
  1025. position: relative;
  1026. /* false positive for grid layout */
  1027. /* stylelint-disable */
  1028. grid-template-areas: ${p =>
  1029. p.layout === 'drawer bottom'
  1030. ? `
  1031. 'trace'
  1032. 'drawer'
  1033. `
  1034. : p.layout === 'drawer left'
  1035. ? `'drawer trace'`
  1036. : `'trace drawer'`};
  1037. grid-template-columns: ${p =>
  1038. p.layout === 'drawer bottom'
  1039. ? '1fr'
  1040. : p.layout === 'drawer left'
  1041. ? 'min-content 1fr'
  1042. : '1fr min-content'};
  1043. grid-template-rows: 1fr auto;
  1044. `;
  1045. const LoadingContainer = styled('div')<{animate: boolean; error?: boolean}>`
  1046. display: flex;
  1047. justify-content: center;
  1048. align-items: center;
  1049. flex-direction: column;
  1050. left: 50%;
  1051. top: 50%;
  1052. position: absolute;
  1053. height: auto;
  1054. font-size: ${p => p.theme.fontSizeMedium};
  1055. color: ${p => p.theme.gray300};
  1056. z-index: 30;
  1057. padding: 24px;
  1058. background-color: ${p => p.theme.background};
  1059. border-radius: ${p => p.theme.borderRadius};
  1060. border: 1px solid ${p => p.theme.border};
  1061. transform-origin: 50% 50%;
  1062. transform: translate(-50%, -50%);
  1063. animation: ${p =>
  1064. p.animate
  1065. ? `${p.error ? 'showLoadingContainerShake' : 'showLoadingContainer'} 300ms cubic-bezier(0.61, 1, 0.88, 1) forwards`
  1066. : 'none'};
  1067. @keyframes showLoadingContainer {
  1068. from {
  1069. opacity: 0.6;
  1070. transform: scale(0.99) translate(-50%, -50%);
  1071. }
  1072. to {
  1073. opacity: 1;
  1074. transform: scale(1) translate(-50%, -50%);
  1075. }
  1076. }
  1077. @keyframes showLoadingContainerShake {
  1078. 0% {
  1079. transform: translate(-50%, -50%);
  1080. }
  1081. 25% {
  1082. transform: translate(-51%, -50%);
  1083. }
  1084. 75% {
  1085. transform: translate(-49%, -50%);
  1086. }
  1087. 100% {
  1088. transform: translate(-50%, -50%);
  1089. }
  1090. }
  1091. `;
  1092. function TraceLoading() {
  1093. return (
  1094. // Dont flash the animation on load because it's annoying
  1095. <LoadingContainer animate={false}>
  1096. <NoMarginIndicator size={24}>
  1097. <div>{t('Assembling the trace')}</div>
  1098. </NoMarginIndicator>
  1099. </LoadingContainer>
  1100. );
  1101. }
  1102. function TraceError() {
  1103. const linkref = useRef<HTMLAnchorElement>(null);
  1104. const feedback = useFeedbackWidget({buttonRef: linkref});
  1105. useEffect(() => {
  1106. traceAnalytics.trackFailedToFetchTraceState();
  1107. }, []);
  1108. return (
  1109. <LoadingContainer animate error>
  1110. <div>{t('Ughhhhh, we failed to load your trace...')}</div>
  1111. <div>
  1112. {t('Seeing this often? Send us ')}
  1113. {feedback ? (
  1114. <a href="#" ref={linkref}>
  1115. {t('feedback')}
  1116. </a>
  1117. ) : (
  1118. <a href="mailto:support@sentry.io?subject=Trace%20fails%20to%20load">
  1119. {t('feedback')}
  1120. </a>
  1121. )}
  1122. </div>
  1123. </LoadingContainer>
  1124. );
  1125. }
  1126. function TraceEmpty() {
  1127. const linkref = useRef<HTMLAnchorElement>(null);
  1128. const feedback = useFeedbackWidget({buttonRef: linkref});
  1129. useEffect(() => {
  1130. traceAnalytics.trackEmptyTraceState();
  1131. }, []);
  1132. return (
  1133. <LoadingContainer animate>
  1134. <div>{t('This trace does not contain any data?!')}</div>
  1135. <div>
  1136. {t('Seeing this often? Send us ')}
  1137. {feedback ? (
  1138. <a href="#" ref={linkref}>
  1139. {t('feedback')}
  1140. </a>
  1141. ) : (
  1142. <a href="mailto:support@sentry.io?subject=Trace%20does%20not%20contain%20data">
  1143. {t('feedback')}
  1144. </a>
  1145. )}
  1146. </div>
  1147. </LoadingContainer>
  1148. );
  1149. }
  1150. const NoMarginIndicator = styled(LoadingIndicator)`
  1151. margin: 0;
  1152. `;