content.tsx 14 KB

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