content.tsx 14 KB

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