content.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. import {useState} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import Feature from 'sentry/components/acl/feature';
  5. import Alert from 'sentry/components/alert';
  6. import {Button} from 'sentry/components/button';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import NotFound from 'sentry/components/errors/notFound';
  9. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  10. import EventCustomPerformanceMetrics from 'sentry/components/events/eventCustomPerformanceMetrics';
  11. import {BorderlessEventEntries} from 'sentry/components/events/eventEntries';
  12. import EventMessage from 'sentry/components/events/eventMessage';
  13. import EventVitals from 'sentry/components/events/eventVitals';
  14. import * as SpanEntryContext from 'sentry/components/events/interfaces/spans/context';
  15. import FileSize from 'sentry/components/fileSize';
  16. import * as Layout from 'sentry/components/layouts/thirds';
  17. import LoadingError from 'sentry/components/loadingError';
  18. import LoadingIndicator from 'sentry/components/loadingIndicator';
  19. import {TransactionProfileIdProvider} from 'sentry/components/profiling/transactionProfileIdProvider';
  20. import {TransactionToProfileButton} from 'sentry/components/profiling/transactionToProfileButton';
  21. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  22. import {TagsTable} from 'sentry/components/tagsTable';
  23. import {IconOpen} from 'sentry/icons';
  24. import {t} from 'sentry/locale';
  25. import {space} from 'sentry/styles/space';
  26. import type {Organization, Project} from 'sentry/types';
  27. import type {Event, EventTag} from 'sentry/types/event';
  28. import {trackAnalytics} from 'sentry/utils/analytics';
  29. import type EventView from 'sentry/utils/discover/eventView';
  30. import {formatTagKey} from 'sentry/utils/discover/fields';
  31. import {eventDetailsRoute} from 'sentry/utils/discover/urls';
  32. import {getMessage} from 'sentry/utils/events';
  33. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  34. import QuickTraceQuery from 'sentry/utils/performance/quickTrace/quickTraceQuery';
  35. import type {TraceMetaQueryChildrenProps} from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  36. import TraceMetaQuery from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  37. import type {QuickTraceQueryChildrenProps} from 'sentry/utils/performance/quickTrace/types';
  38. import {
  39. getTraceTimeRangeFromEvent,
  40. isTransaction,
  41. } from 'sentry/utils/performance/quickTrace/utils';
  42. import Projects from 'sentry/utils/projects';
  43. import {useApiQuery} from 'sentry/utils/queryClient';
  44. import TraceDetailsRouting from 'sentry/views/performance/traceDetails/TraceDetailsRouting';
  45. import EventMetas from 'sentry/views/performance/transactionDetails/eventMetas';
  46. import {transactionSummaryRouteWithQuery} from 'sentry/views/performance/transactionSummary/utils';
  47. import {ProfileGroupProvider} from 'sentry/views/profiling/profileGroupProvider';
  48. import {ProfileContext, ProfilesProvider} from 'sentry/views/profiling/profilesProvider';
  49. import DiscoverBreadcrumb from '../breadcrumb';
  50. import {generateTitle, getExpandedResults} from '../utils';
  51. import LinkedIssue from './linkedIssue';
  52. type Props = Pick<RouteComponentProps<{eventSlug: string}, {}>, 'params' | 'location'> & {
  53. eventSlug: string;
  54. eventView: EventView;
  55. organization: Organization;
  56. isHomepage?: boolean;
  57. };
  58. function EventHeader({event}: {event: Event}) {
  59. const message = getMessage(event);
  60. return (
  61. <EventHeaderContainer data-test-id="event-header">
  62. <TitleWrapper>
  63. <StyledEventOrGroupTitle data={event} />
  64. </TitleWrapper>
  65. {message && (
  66. <MessageWrapper>
  67. <EventMessage message={message} type={event.type} />
  68. </MessageWrapper>
  69. )}
  70. </EventHeaderContainer>
  71. );
  72. }
  73. function EventDetailsContent(props: Props) {
  74. const [isSidebarVisible, setIsSidebarVisible] = useState<boolean>(true);
  75. const projectId = props.eventSlug.split(':')[0];
  76. const {
  77. data: event,
  78. isLoading,
  79. error,
  80. } = useApiQuery<Event>(
  81. [`/organizations/${props.organization.slug}/events/${props.eventSlug}/`],
  82. {staleTime: 2 * 60 * 1000} // 2 minutes in milliseonds
  83. );
  84. const generateTagUrl = (tag: EventTag) => {
  85. const {eventView, organization, isHomepage} = props;
  86. if (!event) {
  87. return '';
  88. }
  89. const eventReference = {...event};
  90. if (eventReference.id) {
  91. delete (eventReference as any).id;
  92. }
  93. const tagKey = formatTagKey(tag.key);
  94. const nextView = getExpandedResults(eventView, {[tagKey]: tag.value}, eventReference);
  95. return nextView.getResultsViewUrlTarget(organization.slug, isHomepage);
  96. };
  97. function renderContent() {
  98. if (!event) {
  99. return <NotFound />;
  100. }
  101. const {organization, location, eventView, isHomepage} = props;
  102. // metrics
  103. trackAnalytics('discover_v2.event_details', {
  104. event_type: event.type,
  105. organization,
  106. });
  107. const transactionName = event.tags.find(tag => tag.key === 'transaction')?.value;
  108. const transactionSummaryTarget =
  109. event.type === 'transaction' && transactionName
  110. ? transactionSummaryRouteWithQuery({
  111. orgSlug: organization.slug,
  112. transaction: transactionName,
  113. projectID: event.projectID,
  114. query: location.query,
  115. })
  116. : null;
  117. const eventJsonUrl = `/api/0/projects/${organization.slug}/${projectId}/events/${event.eventID}/json/`;
  118. const hasProfilingFeature = organization.features.includes('profiling');
  119. const profileId = isTransaction(event) ? event.contexts?.profile?.profile_id : null;
  120. const render = (
  121. results?: QuickTraceQueryChildrenProps,
  122. metaResults?: TraceMetaQueryChildrenProps
  123. ) => {
  124. return (
  125. <TransactionProfileIdProvider
  126. projectId={event.projectID}
  127. transactionId={event.type === 'transaction' ? event.id : undefined}
  128. timestamp={event.dateReceived}
  129. >
  130. <Layout.Header>
  131. <Layout.HeaderContent>
  132. <DiscoverBreadcrumb
  133. eventView={eventView}
  134. event={event}
  135. organization={organization}
  136. location={location}
  137. isHomepage={isHomepage}
  138. />
  139. <EventHeader event={event} />
  140. </Layout.HeaderContent>
  141. <Layout.HeaderActions>
  142. <ButtonBar gap={1}>
  143. <Button size="sm" onClick={() => setIsSidebarVisible(prev => !prev)}>
  144. {isSidebarVisible ? 'Hide Details' : 'Show Details'}
  145. </Button>
  146. <Button
  147. size="sm"
  148. icon={<IconOpen />}
  149. href={eventJsonUrl}
  150. external
  151. onClick={() =>
  152. trackAnalytics('performance_views.event_details.json_button_click', {
  153. organization,
  154. })
  155. }
  156. >
  157. {t('JSON')} (<FileSize bytes={event.size} />)
  158. </Button>
  159. {hasProfilingFeature && event.type === 'transaction' && (
  160. <TransactionToProfileButton event={event} projectSlug={projectId} />
  161. )}
  162. {transactionSummaryTarget && (
  163. <Feature organization={organization} features="performance-view">
  164. {({hasFeature}) => (
  165. <Button
  166. size="sm"
  167. disabled={!hasFeature}
  168. priority="primary"
  169. to={transactionSummaryTarget}
  170. >
  171. {t('Go to Summary')}
  172. </Button>
  173. )}
  174. </Feature>
  175. )}
  176. </ButtonBar>
  177. </Layout.HeaderActions>
  178. </Layout.Header>
  179. <Layout.Body>
  180. <Layout.Main fullWidth>
  181. <EventMetas
  182. quickTrace={results ?? null}
  183. meta={metaResults?.meta ?? null}
  184. event={event}
  185. organization={organization}
  186. projectId={projectId}
  187. location={location}
  188. errorDest="discover"
  189. transactionDest="discover"
  190. />
  191. </Layout.Main>
  192. <Layout.Main fullWidth={!isSidebarVisible}>
  193. <Projects orgId={organization.slug} slugs={[projectId]}>
  194. {({projects, initiallyLoaded}) =>
  195. initiallyLoaded ? (
  196. <SpanEntryContext.Provider
  197. value={{
  198. getViewChildTransactionTarget: childTransactionProps => {
  199. const childTransactionLink = eventDetailsRoute({
  200. eventSlug: childTransactionProps.eventSlug,
  201. orgSlug: organization.slug,
  202. });
  203. return {
  204. pathname: childTransactionLink,
  205. query: eventView.generateQueryStringObject(),
  206. };
  207. },
  208. }}
  209. >
  210. <QuickTraceContext.Provider value={results}>
  211. {hasProfilingFeature ? (
  212. <ProfilesProvider
  213. orgSlug={organization.slug}
  214. projectSlug={projectId}
  215. profileId={profileId || ''}
  216. >
  217. <ProfileContext.Consumer>
  218. {profiles => (
  219. <ProfileGroupProvider
  220. type="flamechart"
  221. input={
  222. profiles?.type === 'resolved' ? profiles.data : null
  223. }
  224. traceID={profileId || ''}
  225. >
  226. <BorderlessEventEntries
  227. organization={organization}
  228. event={event}
  229. project={projects[0] as Project}
  230. showTagSummary={false}
  231. />
  232. </ProfileGroupProvider>
  233. )}
  234. </ProfileContext.Consumer>
  235. </ProfilesProvider>
  236. ) : (
  237. <BorderlessEventEntries
  238. organization={organization}
  239. event={event}
  240. project={projects[0] as Project}
  241. showTagSummary={false}
  242. />
  243. )}
  244. </QuickTraceContext.Provider>
  245. </SpanEntryContext.Provider>
  246. ) : (
  247. <LoadingIndicator />
  248. )
  249. }
  250. </Projects>
  251. </Layout.Main>
  252. {isSidebarVisible && (
  253. <Layout.Side>
  254. <EventVitals event={event} />
  255. <EventCustomPerformanceMetrics
  256. event={event}
  257. location={location}
  258. organization={organization}
  259. isHomepage={isHomepage}
  260. />
  261. {event.groupID && (
  262. <LinkedIssue groupId={event.groupID} eventId={event.eventID} />
  263. )}
  264. <TagsTable
  265. generateUrl={generateTagUrl}
  266. event={event}
  267. query={eventView.query}
  268. />
  269. </Layout.Side>
  270. )}
  271. </Layout.Body>
  272. </TransactionProfileIdProvider>
  273. );
  274. };
  275. const hasQuickTraceView = organization.features.includes('performance-view');
  276. if (hasQuickTraceView) {
  277. const traceId = event.contexts?.trace?.trace_id ?? '';
  278. const {start, end} = getTraceTimeRangeFromEvent(event);
  279. return (
  280. <TraceDetailsRouting event={event}>
  281. <TraceMetaQuery
  282. location={location}
  283. orgSlug={organization.slug}
  284. traceId={traceId}
  285. start={start}
  286. end={end}
  287. >
  288. {metaResults => (
  289. <QuickTraceQuery
  290. event={event}
  291. location={location}
  292. orgSlug={organization.slug}
  293. >
  294. {results => render(results, metaResults)}
  295. </QuickTraceQuery>
  296. )}
  297. </TraceMetaQuery>
  298. </TraceDetailsRouting>
  299. );
  300. }
  301. return render();
  302. }
  303. if (isLoading) {
  304. return <LoadingIndicator />;
  305. }
  306. if (error) {
  307. const notFound = error.status === 404;
  308. const permissionDenied = error.status === 403;
  309. if (notFound) {
  310. return <NotFound />;
  311. }
  312. if (permissionDenied) {
  313. return (
  314. <LoadingError message={t('You do not have permission to view that event.')} />
  315. );
  316. }
  317. return (
  318. <Alert type="error" showIcon>
  319. {error.message}
  320. </Alert>
  321. );
  322. }
  323. const getEventSlug = (): string => {
  324. const {eventSlug} = props.params;
  325. if (typeof eventSlug === 'string') {
  326. return eventSlug.trim();
  327. }
  328. return '';
  329. };
  330. const {eventView, organization} = props;
  331. const eventSlug = getEventSlug();
  332. const projectSlug = eventSlug.split(':')[0];
  333. const title = generateTitle({eventView, event, organization});
  334. return (
  335. <SentryDocumentTitle
  336. title={title}
  337. orgSlug={organization.slug}
  338. projectSlug={projectSlug}
  339. >
  340. {renderContent() as React.ReactChild}
  341. </SentryDocumentTitle>
  342. );
  343. }
  344. const EventHeaderContainer = styled('div')`
  345. max-width: ${p => p.theme.breakpoints.small};
  346. `;
  347. const TitleWrapper = styled('div')`
  348. margin-top: 20px;
  349. `;
  350. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  351. font-size: ${p => p.theme.headerFontSize};
  352. `;
  353. const MessageWrapper = styled('div')`
  354. margin-top: ${space(1)};
  355. `;
  356. export default EventDetailsContent;