content.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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 {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. } & AsyncComponent['state'];
  60. class EventDetailsContent extends AsyncComponent<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<AsyncComponent['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. {(organization.features.includes('dashboards-mep') ||
  267. organization.features.includes('mep-rollout-flag')) && (
  268. <EventCustomPerformanceMetrics
  269. event={event}
  270. location={location}
  271. organization={organization}
  272. isHomepage={isHomepage}
  273. />
  274. )}
  275. {event.groupID && (
  276. <LinkedIssue groupId={event.groupID} eventId={event.eventID} />
  277. )}
  278. <TagsTable
  279. generateUrl={this.generateTagUrl}
  280. event={event}
  281. query={eventView.query}
  282. />
  283. </Layout.Side>
  284. )}
  285. </Layout.Body>
  286. </TransactionProfileIdProvider>
  287. );
  288. const hasQuickTraceView = organization.features.includes('performance-view');
  289. if (hasQuickTraceView) {
  290. const traceId = event.contexts?.trace?.trace_id ?? '';
  291. const {start, end} = getTraceTimeRangeFromEvent(event);
  292. return (
  293. <TraceMetaQuery
  294. location={location}
  295. orgSlug={organization.slug}
  296. traceId={traceId}
  297. start={start}
  298. end={end}
  299. >
  300. {metaResults => (
  301. <QuickTraceQuery
  302. event={event}
  303. location={location}
  304. orgSlug={organization.slug}
  305. >
  306. {results => renderContent(results, metaResults)}
  307. </QuickTraceQuery>
  308. )}
  309. </TraceMetaQuery>
  310. );
  311. }
  312. return renderContent();
  313. }
  314. renderError(error: Error) {
  315. const notFound = Object.values(this.state.errors).find(
  316. resp => resp && resp.status === 404
  317. );
  318. const permissionDenied = Object.values(this.state.errors).find(
  319. resp => resp && resp.status === 403
  320. );
  321. if (notFound) {
  322. return <NotFound />;
  323. }
  324. if (permissionDenied) {
  325. return (
  326. <LoadingError message={t('You do not have permission to view that event.')} />
  327. );
  328. }
  329. return super.renderError(error, true);
  330. }
  331. getEventSlug = (): string => {
  332. const {eventSlug} = this.props.params;
  333. if (typeof eventSlug === 'string') {
  334. return eventSlug.trim();
  335. }
  336. return '';
  337. };
  338. renderComponent() {
  339. const {eventView, organization} = this.props;
  340. const {event} = this.state;
  341. const eventSlug = this.getEventSlug();
  342. const projectSlug = eventSlug.split(':')[0];
  343. const title = generateTitle({eventView, event, organization});
  344. return (
  345. <SentryDocumentTitle
  346. title={title}
  347. orgSlug={organization.slug}
  348. projectSlug={projectSlug}
  349. >
  350. {super.renderComponent() as React.ReactChild}
  351. </SentryDocumentTitle>
  352. );
  353. }
  354. }
  355. function EventHeader({event}: {event: Event}) {
  356. const message = getMessage(event);
  357. return (
  358. <EventHeaderContainer data-test-id="event-header">
  359. <TitleWrapper>
  360. <StyledEventOrGroupTitle data={event} />
  361. </TitleWrapper>
  362. {message && (
  363. <MessageWrapper>
  364. <EventMessage message={message} />
  365. </MessageWrapper>
  366. )}
  367. </EventHeaderContainer>
  368. );
  369. }
  370. const EventHeaderContainer = styled('div')`
  371. max-width: ${p => p.theme.breakpoints.small};
  372. `;
  373. const TitleWrapper = styled('div')`
  374. margin-top: 20px;
  375. `;
  376. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  377. font-size: ${p => p.theme.headerFontSize};
  378. `;
  379. const MessageWrapper = styled('div')`
  380. margin-top: ${space(1)};
  381. `;
  382. export default EventDetailsContent;