content.tsx 15 KB

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