content.tsx 14 KB

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