content.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import Feature from 'sentry/components/acl/feature';
  5. import AsyncComponent from 'sentry/components/asyncComponent';
  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 {TransactionToProfileButton} from 'sentry/components/profiling/transactionToProfileButton';
  20. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  21. import {TagsTable} from 'sentry/components/tagsTable';
  22. import {IconOpen} from 'sentry/icons';
  23. import {t} from 'sentry/locale';
  24. import space from 'sentry/styles/space';
  25. import {Organization, Project} from 'sentry/types';
  26. import {Event, EventTag} from 'sentry/types/event';
  27. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  28. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  29. import 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 TraceMetaQuery, {
  36. TraceMetaQueryChildrenProps,
  37. } from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  38. import {QuickTraceQueryChildrenProps} from 'sentry/utils/performance/quickTrace/types';
  39. import {getTraceTimeRangeFromEvent} from 'sentry/utils/performance/quickTrace/utils';
  40. import Projects from 'sentry/utils/projects';
  41. import EventMetas from 'sentry/views/performance/transactionDetails/eventMetas';
  42. import {transactionSummaryRouteWithQuery} from 'sentry/views/performance/transactionSummary/utils';
  43. import DiscoverBreadcrumb from '../breadcrumb';
  44. import {generateTitle, getExpandedResults} from '../utils';
  45. import LinkedIssue from './linkedIssue';
  46. type Props = Pick<
  47. RouteComponentProps<{eventSlug: string}, {}>,
  48. 'params' | 'location' | 'route' | 'router'
  49. > & {
  50. eventSlug: string;
  51. eventView: EventView;
  52. organization: Organization;
  53. isHomepage?: boolean;
  54. };
  55. type State = {
  56. event: Event | undefined;
  57. isSidebarVisible: boolean;
  58. } & AsyncComponent['state'];
  59. class EventDetailsContent extends AsyncComponent<Props, State> {
  60. state: State = {
  61. // AsyncComponent state
  62. loading: true,
  63. reloading: false,
  64. error: false,
  65. errors: {},
  66. event: undefined,
  67. // local state
  68. isSidebarVisible: true,
  69. };
  70. toggleSidebar = () => {
  71. this.setState({isSidebarVisible: !this.state.isSidebarVisible});
  72. };
  73. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  74. const {organization, params, location, eventView} = this.props;
  75. const {eventSlug} = params;
  76. const query = eventView.getEventsAPIPayload(location);
  77. // Fields aren't used, reduce complexity by omitting from query entirely
  78. query.field = [];
  79. const url = `/organizations/${organization.slug}/events/${eventSlug}/`;
  80. // Get a specific event. This could be coming from
  81. // a paginated group or standalone event.
  82. return [['event', url, {query}]];
  83. }
  84. get projectId() {
  85. return this.props.eventSlug.split(':')[0];
  86. }
  87. generateTagUrl = (tag: EventTag) => {
  88. const {eventView, organization} = this.props;
  89. const {event} = this.state;
  90. if (!event) {
  91. return '';
  92. }
  93. const eventReference = {...event};
  94. if (eventReference.id) {
  95. delete (eventReference as any).id;
  96. }
  97. const tagKey = formatTagKey(tag.key);
  98. const nextView = getExpandedResults(eventView, {[tagKey]: tag.value}, eventReference);
  99. return nextView.getResultsViewUrlTarget(organization.slug);
  100. };
  101. renderBody() {
  102. const {event} = this.state;
  103. if (!event) {
  104. return <NotFound />;
  105. }
  106. return this.renderContent(event);
  107. }
  108. renderContent(event: Event) {
  109. const {organization, location, eventView, route, router, isHomepage} = this.props;
  110. const {isSidebarVisible} = this.state;
  111. // metrics
  112. trackAnalyticsEvent({
  113. eventKey: 'discover_v2.event_details',
  114. eventName: 'Discoverv2: Opened Event Details',
  115. event_type: event.type,
  116. organization_id: parseInt(organization.id, 10),
  117. });
  118. const transactionName = event.tags.find(tag => tag.key === 'transaction')?.value;
  119. const transactionSummaryTarget =
  120. event.type === 'transaction' && transactionName
  121. ? transactionSummaryRouteWithQuery({
  122. orgSlug: organization.slug,
  123. transaction: transactionName,
  124. projectID: event.projectID,
  125. query: location.query,
  126. })
  127. : null;
  128. const eventJsonUrl = `/api/0/projects/${organization.slug}/${this.projectId}/events/${event.eventID}/json/`;
  129. const hasProfilingFeature = organization.features.includes('profiling');
  130. const renderContent = (
  131. results?: QuickTraceQueryChildrenProps,
  132. metaResults?: TraceMetaQueryChildrenProps
  133. ) => (
  134. <Fragment>
  135. <Layout.Header>
  136. <Layout.HeaderContent>
  137. <DiscoverBreadcrumb
  138. eventView={eventView}
  139. event={event}
  140. organization={organization}
  141. location={location}
  142. isHomepage={isHomepage}
  143. />
  144. <EventHeader event={event} />
  145. </Layout.HeaderContent>
  146. <Layout.HeaderActions>
  147. <ButtonBar gap={1}>
  148. <Button onClick={this.toggleSidebar}>
  149. {isSidebarVisible ? 'Hide Details' : 'Show Details'}
  150. </Button>
  151. <Button
  152. icon={<IconOpen />}
  153. href={eventJsonUrl}
  154. external
  155. onClick={() =>
  156. trackAdvancedAnalyticsEvent(
  157. 'performance_views.event_details.json_button_click',
  158. {
  159. organization,
  160. }
  161. )
  162. }
  163. >
  164. {t('JSON')} (<FileSize bytes={event.size} />)
  165. </Button>
  166. {hasProfilingFeature && event.type === 'transaction' && (
  167. <TransactionToProfileButton
  168. orgId={organization.slug}
  169. projectId={this.projectId}
  170. transactionId={event.eventID}
  171. />
  172. )}
  173. {transactionSummaryTarget && (
  174. <Feature organization={organization} features={['performance-view']}>
  175. {({hasFeature}) => (
  176. <Button
  177. disabled={!hasFeature}
  178. priority="primary"
  179. to={transactionSummaryTarget}
  180. >
  181. {t('Go to Summary')}
  182. </Button>
  183. )}
  184. </Feature>
  185. )}
  186. </ButtonBar>
  187. </Layout.HeaderActions>
  188. </Layout.Header>
  189. <Layout.Body>
  190. <Layout.Main fullWidth>
  191. <EventMetas
  192. quickTrace={results ?? null}
  193. meta={metaResults?.meta ?? null}
  194. event={event}
  195. organization={organization}
  196. projectId={this.projectId}
  197. location={location}
  198. errorDest="discover"
  199. transactionDest="discover"
  200. />
  201. </Layout.Main>
  202. <Layout.Main fullWidth={!isSidebarVisible}>
  203. <Projects orgId={organization.slug} slugs={[this.projectId]}>
  204. {({projects, initiallyLoaded}) =>
  205. initiallyLoaded ? (
  206. <SpanEntryContext.Provider
  207. value={{
  208. getViewChildTransactionTarget: childTransactionProps => {
  209. const childTransactionLink = eventDetailsRoute({
  210. eventSlug: childTransactionProps.eventSlug,
  211. orgSlug: organization.slug,
  212. });
  213. return {
  214. pathname: childTransactionLink,
  215. query: eventView.generateQueryStringObject(),
  216. };
  217. },
  218. }}
  219. >
  220. <QuickTraceContext.Provider value={results}>
  221. <BorderlessEventEntries
  222. organization={organization}
  223. event={event}
  224. project={projects[0] as Project}
  225. location={location}
  226. showTagSummary={false}
  227. api={this.api}
  228. router={router}
  229. route={route}
  230. />
  231. </QuickTraceContext.Provider>
  232. </SpanEntryContext.Provider>
  233. ) : (
  234. <LoadingIndicator />
  235. )
  236. }
  237. </Projects>
  238. </Layout.Main>
  239. {isSidebarVisible && (
  240. <Layout.Side>
  241. <EventVitals event={event} />
  242. {(organization.features.includes('dashboards-mep') ||
  243. organization.features.includes('mep-rollout-flag')) && (
  244. <EventCustomPerformanceMetrics
  245. event={event}
  246. location={location}
  247. organization={organization}
  248. />
  249. )}
  250. {event.groupID && (
  251. <LinkedIssue groupId={event.groupID} eventId={event.eventID} />
  252. )}
  253. <TagsTable
  254. generateUrl={this.generateTagUrl}
  255. event={event}
  256. query={eventView.query}
  257. />
  258. </Layout.Side>
  259. )}
  260. </Layout.Body>
  261. </Fragment>
  262. );
  263. const hasQuickTraceView = organization.features.includes('performance-view');
  264. if (hasQuickTraceView) {
  265. const traceId = event.contexts?.trace?.trace_id ?? '';
  266. const {start, end} = getTraceTimeRangeFromEvent(event);
  267. return (
  268. <TraceMetaQuery
  269. location={location}
  270. orgSlug={organization.slug}
  271. traceId={traceId}
  272. start={start}
  273. end={end}
  274. >
  275. {metaResults => (
  276. <QuickTraceQuery
  277. event={event}
  278. location={location}
  279. orgSlug={organization.slug}
  280. >
  281. {results => renderContent(results, metaResults)}
  282. </QuickTraceQuery>
  283. )}
  284. </TraceMetaQuery>
  285. );
  286. }
  287. return renderContent();
  288. }
  289. renderError(error: Error) {
  290. const notFound = Object.values(this.state.errors).find(
  291. resp => resp && resp.status === 404
  292. );
  293. const permissionDenied = Object.values(this.state.errors).find(
  294. resp => resp && resp.status === 403
  295. );
  296. if (notFound) {
  297. return <NotFound />;
  298. }
  299. if (permissionDenied) {
  300. return (
  301. <LoadingError message={t('You do not have permission to view that event.')} />
  302. );
  303. }
  304. return super.renderError(error, true);
  305. }
  306. getEventSlug = (): string => {
  307. const {eventSlug} = this.props.params;
  308. if (typeof eventSlug === 'string') {
  309. return eventSlug.trim();
  310. }
  311. return '';
  312. };
  313. renderComponent() {
  314. const {eventView, organization} = this.props;
  315. const {event} = this.state;
  316. const eventSlug = this.getEventSlug();
  317. const projectSlug = eventSlug.split(':')[0];
  318. const title = generateTitle({eventView, event, organization});
  319. return (
  320. <SentryDocumentTitle
  321. title={title}
  322. orgSlug={organization.slug}
  323. projectSlug={projectSlug}
  324. >
  325. {super.renderComponent() as React.ReactChild}
  326. </SentryDocumentTitle>
  327. );
  328. }
  329. }
  330. const EventHeader = ({event}: {event: Event}) => {
  331. const message = getMessage(event);
  332. return (
  333. <EventHeaderContainer data-test-id="event-header">
  334. <TitleWrapper>
  335. <StyledEventOrGroupTitle data={event} />
  336. </TitleWrapper>
  337. {message && (
  338. <MessageWrapper>
  339. <EventMessage message={message} />
  340. </MessageWrapper>
  341. )}
  342. </EventHeaderContainer>
  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;