content.tsx 13 KB

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