generalInfo.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import {Fragment, useMemo} from 'react';
  2. import Link from 'sentry/components/links/link';
  3. import LoadingIndicator from 'sentry/components/loadingIndicator';
  4. import {useReplayContext} from 'sentry/components/replays/replayContext';
  5. import {Tooltip} from 'sentry/components/tooltip';
  6. import {t, tn} from 'sentry/locale';
  7. import type {EventTransaction} from 'sentry/types/event';
  8. import type {Organization} from 'sentry/types/organization';
  9. import getDuration from 'sentry/utils/duration/getDuration';
  10. import {getShortEventId} from 'sentry/utils/events';
  11. import type {
  12. TraceErrorOrIssue,
  13. TraceFullDetailed,
  14. TraceSplitResults,
  15. } from 'sentry/utils/performance/quickTrace/types';
  16. import type {UseApiQueryResult} from 'sentry/utils/queryClient';
  17. import type RequestError from 'sentry/utils/requestError/requestError';
  18. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  19. import {useParams} from 'sentry/utils/useParams';
  20. import {SpanTimeRenderer} from 'sentry/views/traces/fieldRenderers';
  21. import {isTraceNode} from '../../../guards';
  22. import type {TraceMetaQueryResults} from '../../../traceApi/useTraceMeta';
  23. import type {TraceTree, TraceTreeNode} from '../../../traceModels/traceTree';
  24. import {type SectionCardKeyValueList, TraceDrawerComponents} from '../../details/styles';
  25. type GeneralInfoProps = {
  26. metaResults: TraceMetaQueryResults;
  27. node: TraceTreeNode<TraceTree.NodeValue>;
  28. organization: Organization;
  29. rootEventResults: UseApiQueryResult<EventTransaction, RequestError>;
  30. traces: TraceSplitResults<TraceFullDetailed> | null;
  31. tree: TraceTree;
  32. };
  33. export function GeneralInfo(props: GeneralInfoProps) {
  34. const params = useParams<{traceSlug?: string}>();
  35. const {replay} = useReplayContext();
  36. const traceNode = props.tree.root.children[0];
  37. const uniqueErrorIssues = useMemo(() => {
  38. if (!traceNode) {
  39. return [];
  40. }
  41. const unique: TraceErrorOrIssue[] = [];
  42. const seenIssues: Set<number> = new Set();
  43. for (const issue of traceNode.errors) {
  44. if (seenIssues.has(issue.issue_id)) {
  45. continue;
  46. }
  47. seenIssues.add(issue.issue_id);
  48. unique.push(issue);
  49. }
  50. return unique;
  51. }, [traceNode]);
  52. const uniquePerformanceIssues = useMemo(() => {
  53. if (!traceNode) {
  54. return [];
  55. }
  56. const unique: TraceErrorOrIssue[] = [];
  57. const seenIssues: Set<number> = new Set();
  58. for (const issue of traceNode.performance_issues) {
  59. if (seenIssues.has(issue.issue_id)) {
  60. continue;
  61. }
  62. seenIssues.add(issue.issue_id);
  63. unique.push(issue);
  64. }
  65. return unique;
  66. }, [traceNode]);
  67. const uniqueIssuesCount = uniqueErrorIssues.length + uniquePerformanceIssues.length;
  68. const traceSlug = useMemo(() => {
  69. return params.traceSlug?.trim() ?? '';
  70. }, [params.traceSlug]);
  71. const isLoading = useMemo(() => {
  72. return (
  73. props.metaResults.isLoading ||
  74. (props.rootEventResults.isLoading && props.rootEventResults.fetchStatus !== 'idle')
  75. );
  76. }, [
  77. props.metaResults.isLoading,
  78. props.rootEventResults.isLoading,
  79. props.rootEventResults.fetchStatus,
  80. ]);
  81. if (isLoading) {
  82. return (
  83. <TraceDrawerComponents.SectionCard
  84. items={[
  85. {
  86. key: 'trace_general_loading',
  87. subject: t('Loading...'),
  88. subjectNode: null,
  89. value: <LoadingIndicator size={30} />,
  90. },
  91. ]}
  92. title={t('General')}
  93. />
  94. );
  95. }
  96. if (!(traceNode && isTraceNode(traceNode))) {
  97. throw new Error('Expected a trace node');
  98. }
  99. if (
  100. props.traces?.transactions.length === 0 &&
  101. props.traces.orphan_errors.length === 0
  102. ) {
  103. return null;
  104. }
  105. const replay_id = props.rootEventResults?.data?.contexts?.replay?.replay_id;
  106. const browser = props.rootEventResults?.data?.contexts?.browser;
  107. const items: SectionCardKeyValueList = [];
  108. // Hide trace_id inside replays because a replay could be connected to multiple traces.
  109. if (!replay) {
  110. items.push({
  111. key: 'trace_id',
  112. subject: t('Trace ID'),
  113. value: <TraceDrawerComponents.CopyableCardValueWithLink value={traceSlug} />,
  114. });
  115. }
  116. items.push(
  117. {
  118. key: 'events',
  119. subject: t('Events'),
  120. value: props.metaResults.data
  121. ? props.metaResults.data.transactions + props.metaResults.data.errors
  122. : '\u2014',
  123. },
  124. {
  125. key: 'issues',
  126. subject: t('Issues'),
  127. value: (
  128. <Tooltip
  129. title={
  130. uniqueIssuesCount > 0 ? (
  131. <Fragment>
  132. <div>
  133. {tn('%s error issue', '%s error issues', uniqueErrorIssues.length)}
  134. </div>
  135. <div>
  136. {tn(
  137. '%s performance issue',
  138. '%s performance issues',
  139. uniquePerformanceIssues.length
  140. )}
  141. </div>
  142. </Fragment>
  143. ) : null
  144. }
  145. showUnderline
  146. position="bottom"
  147. >
  148. {uniqueIssuesCount > 0 ? (
  149. <TraceDrawerComponents.IssuesLink node={props.node}>
  150. {uniqueIssuesCount}
  151. </TraceDrawerComponents.IssuesLink>
  152. ) : uniqueIssuesCount === 0 ? (
  153. 0
  154. ) : (
  155. '\u2014'
  156. )}
  157. </Tooltip>
  158. ),
  159. },
  160. {
  161. key: 'start_timestamp',
  162. subject: t('Start Timestamp'),
  163. value: traceNode.space?.[1] ? (
  164. <SpanTimeRenderer timestamp={traceNode.space?.[0]} tooltipShowSeconds />
  165. ) : (
  166. '\u2014'
  167. ),
  168. },
  169. {
  170. key: 'total_duration',
  171. subject: t('Total Duration'),
  172. value: traceNode.space?.[1]
  173. ? getDuration(traceNode.space[1] / 1000, 2, true)
  174. : '\u2014',
  175. },
  176. {
  177. key: 'user',
  178. subject: t('User'),
  179. value:
  180. props.rootEventResults?.data?.user?.email ??
  181. props.rootEventResults?.data?.user?.name ??
  182. '\u2014',
  183. },
  184. {
  185. key: 'browser',
  186. subject: t('Browser'),
  187. value: browser ? browser.name + ' ' + browser.version : '\u2014',
  188. }
  189. );
  190. // Hide replay preview if we are already in a replay page.
  191. if (replay_id && !replay) {
  192. items.push({
  193. key: 'replay_id',
  194. subject: t('Replay ID'),
  195. value: (
  196. <Link
  197. to={normalizeUrl(
  198. `/organizations/${props.organization.slug}/replays/${replay_id}/`
  199. )}
  200. >
  201. {getShortEventId(replay_id)}
  202. </Link>
  203. ),
  204. });
  205. }
  206. return (
  207. <TraceDrawerComponents.SectionCard
  208. items={items}
  209. title={t('General')}
  210. disableTruncate
  211. />
  212. );
  213. }