generalInfo.tsx 5.7 KB

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