content.tsx 14 KB

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