content.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. const transactionName = event.tags.find(tag => tag.key === 'transaction')?.value;
  104. const transactionSummaryTarget =
  105. event.type === 'transaction' && transactionName
  106. ? transactionSummaryRouteWithQuery({
  107. orgSlug: organization.slug,
  108. transaction: transactionName,
  109. projectID: event.projectID,
  110. query: location.query,
  111. })
  112. : null;
  113. const eventJsonUrl = `/api/0/projects/${organization.slug}/${projectId}/events/${event.eventID}/json/`;
  114. const hasProfilingFeature = organization.features.includes('profiling');
  115. const profileId = isTransaction(event) ? event.contexts?.profile?.profile_id : null;
  116. const render = (
  117. results?: QuickTraceQueryChildrenProps,
  118. metaResults?: TraceMetaQueryChildrenProps
  119. ) => {
  120. return (
  121. <TransactionProfileIdProvider
  122. projectId={event.projectID}
  123. transactionId={event.type === 'transaction' ? event.id : undefined}
  124. timestamp={event.dateReceived}
  125. >
  126. <Layout.Header>
  127. <Layout.HeaderContent>
  128. <DiscoverBreadcrumb
  129. eventView={eventView}
  130. event={event}
  131. organization={organization}
  132. location={location}
  133. isHomepage={isHomepage}
  134. />
  135. <EventHeader event={event} />
  136. </Layout.HeaderContent>
  137. <Layout.HeaderActions>
  138. <ButtonBar gap={1}>
  139. <Button size="sm" onClick={() => setIsSidebarVisible(prev => !prev)}>
  140. {isSidebarVisible ? 'Hide Details' : 'Show Details'}
  141. </Button>
  142. <Button
  143. size="sm"
  144. icon={<IconOpen />}
  145. href={eventJsonUrl}
  146. external
  147. onClick={() =>
  148. trackAnalytics('performance_views.event_details.json_button_click', {
  149. organization,
  150. })
  151. }
  152. >
  153. {t('JSON')} (<FileSize bytes={event.size} />)
  154. </Button>
  155. {hasProfilingFeature && event.type === 'transaction' && (
  156. <TransactionToProfileButton event={event} projectSlug={projectId} />
  157. )}
  158. {transactionSummaryTarget && (
  159. <Feature organization={organization} features="performance-view">
  160. {({hasFeature}) => (
  161. <Button
  162. size="sm"
  163. disabled={!hasFeature}
  164. priority="primary"
  165. to={transactionSummaryTarget}
  166. >
  167. {t('Go to Summary')}
  168. </Button>
  169. )}
  170. </Feature>
  171. )}
  172. </ButtonBar>
  173. </Layout.HeaderActions>
  174. </Layout.Header>
  175. <Layout.Body>
  176. <Layout.Main fullWidth>
  177. <EventMetas
  178. quickTrace={results ?? null}
  179. meta={metaResults?.meta ?? null}
  180. event={event}
  181. organization={organization}
  182. projectId={projectId}
  183. location={location}
  184. errorDest="discover"
  185. transactionDest="discover"
  186. />
  187. </Layout.Main>
  188. <Layout.Main fullWidth={!isSidebarVisible}>
  189. <Projects orgId={organization.slug} slugs={[projectId]}>
  190. {({projects, initiallyLoaded}) =>
  191. initiallyLoaded ? (
  192. <SpanEntryContext.Provider
  193. value={{
  194. getViewChildTransactionTarget: childTransactionProps => {
  195. const childTransactionLink = eventDetailsRoute({
  196. eventSlug: childTransactionProps.eventSlug,
  197. orgSlug: organization.slug,
  198. });
  199. return {
  200. pathname: childTransactionLink,
  201. query: eventView.generateQueryStringObject(),
  202. };
  203. },
  204. }}
  205. >
  206. <QuickTraceContext.Provider value={results}>
  207. {hasProfilingFeature ? (
  208. <ProfilesProvider
  209. orgSlug={organization.slug}
  210. projectSlug={projectId}
  211. profileId={profileId || ''}
  212. >
  213. <ProfileContext.Consumer>
  214. {profiles => (
  215. <ProfileGroupProvider
  216. type="flamechart"
  217. input={
  218. profiles?.type === 'resolved' ? profiles.data : null
  219. }
  220. traceID={profileId || ''}
  221. >
  222. <BorderlessEventEntries
  223. organization={organization}
  224. event={event}
  225. project={projects[0] as Project}
  226. showTagSummary={false}
  227. />
  228. </ProfileGroupProvider>
  229. )}
  230. </ProfileContext.Consumer>
  231. </ProfilesProvider>
  232. ) : (
  233. <BorderlessEventEntries
  234. organization={organization}
  235. event={event}
  236. project={projects[0] as Project}
  237. showTagSummary={false}
  238. />
  239. )}
  240. </QuickTraceContext.Provider>
  241. </SpanEntryContext.Provider>
  242. ) : (
  243. <LoadingIndicator />
  244. )
  245. }
  246. </Projects>
  247. </Layout.Main>
  248. {isSidebarVisible && (
  249. <Layout.Side>
  250. <EventVitals event={event} />
  251. <EventCustomPerformanceMetrics
  252. event={event}
  253. location={location}
  254. organization={organization}
  255. isHomepage={isHomepage}
  256. />
  257. {event.groupID && (
  258. <LinkedIssue groupId={event.groupID} eventId={event.eventID} />
  259. )}
  260. <TagsTable
  261. generateUrl={generateTagUrl}
  262. event={event}
  263. query={eventView.query}
  264. />
  265. </Layout.Side>
  266. )}
  267. </Layout.Body>
  268. </TransactionProfileIdProvider>
  269. );
  270. };
  271. const hasQuickTraceView = organization.features.includes('performance-view');
  272. if (hasQuickTraceView) {
  273. const traceId = event.contexts?.trace?.trace_id ?? '';
  274. const {start, end} = getTraceTimeRangeFromEvent(event);
  275. return (
  276. <TraceDetailsRouting event={event}>
  277. <TraceMetaQuery
  278. location={location}
  279. orgSlug={organization.slug}
  280. traceId={traceId}
  281. start={start}
  282. end={end}
  283. >
  284. {metaResults => (
  285. <QuickTraceQuery
  286. event={event}
  287. location={location}
  288. orgSlug={organization.slug}
  289. skipLight={false}
  290. >
  291. {results => render(results, metaResults)}
  292. </QuickTraceQuery>
  293. )}
  294. </TraceMetaQuery>
  295. </TraceDetailsRouting>
  296. );
  297. }
  298. return render();
  299. }
  300. if (isLoading) {
  301. return <LoadingIndicator />;
  302. }
  303. if (error) {
  304. const notFound = error.status === 404;
  305. const permissionDenied = error.status === 403;
  306. if (notFound) {
  307. return <NotFound />;
  308. }
  309. if (permissionDenied) {
  310. return (
  311. <LoadingError message={t('You do not have permission to view that event.')} />
  312. );
  313. }
  314. return (
  315. <Alert type="error" showIcon>
  316. {error.message}
  317. </Alert>
  318. );
  319. }
  320. const getEventSlug = (): string => {
  321. const {eventSlug} = props.params;
  322. if (typeof eventSlug === 'string') {
  323. return eventSlug.trim();
  324. }
  325. return '';
  326. };
  327. const {eventView, organization} = props;
  328. const eventSlug = getEventSlug();
  329. const projectSlug = eventSlug.split(':')[0];
  330. const title = generateTitle({eventView, event, organization});
  331. return (
  332. <SentryDocumentTitle
  333. title={title}
  334. orgSlug={organization.slug}
  335. projectSlug={projectSlug}
  336. >
  337. {renderContent() as React.ReactChild}
  338. </SentryDocumentTitle>
  339. );
  340. }
  341. const EventHeaderContainer = styled('div')`
  342. max-width: ${p => p.theme.breakpoints.small};
  343. `;
  344. const TitleWrapper = styled('div')`
  345. margin-top: 20px;
  346. `;
  347. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  348. font-size: ${p => p.theme.headerFontSize};
  349. `;
  350. const MessageWrapper = styled('div')`
  351. margin-top: ${space(1)};
  352. `;
  353. export default EventDetailsContent;