content.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  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 EventCustomPerformanceMetrics, {
  9. EventDetailPageSource,
  10. } from 'sentry/components/events/eventCustomPerformanceMetrics';
  11. import {BorderlessEventEntries} from 'sentry/components/events/eventEntries';
  12. import EventMetadata from 'sentry/components/events/eventMetadata';
  13. import EventVitals from 'sentry/components/events/eventVitals';
  14. import getUrlFromEvent from 'sentry/components/events/interfaces/request/getUrlFromEvent';
  15. import * as SpanEntryContext from 'sentry/components/events/interfaces/spans/context';
  16. import RootSpanStatus from 'sentry/components/events/rootSpanStatus';
  17. import FileSize from 'sentry/components/fileSize';
  18. import * as Layout from 'sentry/components/layouts/thirds';
  19. import LoadingError from 'sentry/components/loadingError';
  20. import {TransactionProfileIdProvider} from 'sentry/components/profiling/transactionProfileIdProvider';
  21. import {TransactionToProfileButton} from 'sentry/components/profiling/transactionToProfileButton';
  22. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  23. import {TagsTable} from 'sentry/components/tagsTable';
  24. import {Tooltip} from 'sentry/components/tooltip';
  25. import {IconOpen} from 'sentry/icons';
  26. import {t} from 'sentry/locale';
  27. import {Organization, Project} from 'sentry/types';
  28. import {Event, EventTag, EventTransaction} from 'sentry/types/event';
  29. import {formatTagKey} from 'sentry/utils/discover/fields';
  30. import {getAnalyticsDataForEvent} from 'sentry/utils/events';
  31. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  32. import QuickTraceQuery from 'sentry/utils/performance/quickTrace/quickTraceQuery';
  33. import TraceMetaQuery from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  34. import {
  35. getTraceTimeRangeFromEvent,
  36. isTransaction,
  37. } from 'sentry/utils/performance/quickTrace/utils';
  38. import {getTransactionDetailsUrl} from 'sentry/utils/performance/urls';
  39. import Projects from 'sentry/utils/projects';
  40. import {appendTagCondition, decodeScalar} from 'sentry/utils/queryString';
  41. import withRouteAnalytics, {
  42. WithRouteAnalyticsProps,
  43. } from 'sentry/utils/routeAnalytics/withRouteAnalytics';
  44. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  45. import {ProfileGroupProvider} from 'sentry/views/profiling/profileGroupProvider';
  46. import {ProfileContext, ProfilesProvider} from 'sentry/views/profiling/profilesProvider';
  47. import TraceDetailsRouting from '../traceDetails/TraceDetailsRouting';
  48. import {transactionSummaryRouteWithQuery} from '../transactionSummary/utils';
  49. import {getSelectedProjectPlatforms} from '../utils';
  50. import EventMetas from './eventMetas';
  51. import FinishSetupAlert from './finishSetupAlert';
  52. type Props = Pick<RouteComponentProps<{eventSlug: string}, {}>, 'params' | 'location'> &
  53. WithRouteAnalyticsProps & {
  54. eventSlug: string;
  55. organization: Organization;
  56. projects: Project[];
  57. };
  58. type State = {
  59. event: Event | undefined;
  60. isSidebarVisible: boolean;
  61. } & DeprecatedAsyncComponent['state'];
  62. class EventDetailsContent extends DeprecatedAsyncComponent<Props, State> {
  63. state: State = {
  64. // AsyncComponent state
  65. loading: true,
  66. reloading: false,
  67. error: false,
  68. errors: {},
  69. event: undefined,
  70. // local state
  71. isSidebarVisible: true,
  72. };
  73. toggleSidebar = () => {
  74. this.setState({isSidebarVisible: !this.state.isSidebarVisible});
  75. };
  76. getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
  77. const {organization, params} = this.props;
  78. const {eventSlug} = params;
  79. const url = `/organizations/${organization.slug}/events/${eventSlug}/`;
  80. return [['event', url]];
  81. }
  82. onLoadAllEndpointsSuccess() {
  83. const {location, projects} = this.props;
  84. const {event} = this.state;
  85. this.props.setEventNames(
  86. 'performance.event_details',
  87. 'Performance: Opened Event Details'
  88. );
  89. this.props.setRouteAnalyticsParams({
  90. event_type: event?.type,
  91. project_platforms: getSelectedProjectPlatforms(location, projects),
  92. ...getAnalyticsDataForEvent(event),
  93. });
  94. }
  95. get projectId() {
  96. return this.props.eventSlug.split(':')[0];
  97. }
  98. generateTagUrl = (tag: EventTag) => {
  99. const {location, organization} = this.props;
  100. const {event} = this.state;
  101. if (!event) {
  102. return '';
  103. }
  104. const query = decodeScalar(location.query.query, '');
  105. const newQuery = {
  106. ...location.query,
  107. query: appendTagCondition(query, formatTagKey(tag.key), tag.value),
  108. };
  109. return transactionSummaryRouteWithQuery({
  110. orgSlug: organization.slug,
  111. transaction: event.title,
  112. projectID: event.projectID,
  113. query: newQuery,
  114. });
  115. };
  116. renderBody() {
  117. const {event} = this.state;
  118. const {organization} = this.props;
  119. if (!event) {
  120. return <NotFound />;
  121. }
  122. const isSampleTransaction = event.tags.some(
  123. tag => tag.key === 'sample_event' && tag.value === 'yes'
  124. );
  125. return (
  126. <Fragment>
  127. {isSampleTransaction && (
  128. <FinishSetupAlert organization={organization} projectId={this.projectId} />
  129. )}
  130. {this.renderContent(event)}
  131. </Fragment>
  132. );
  133. }
  134. renderContent(event: Event) {
  135. const {organization, location, eventSlug} = this.props;
  136. const {isSidebarVisible} = this.state;
  137. const transactionName = event.title;
  138. const query = decodeScalar(location.query.query, '');
  139. const eventJsonUrl = `/api/0/projects/${organization.slug}/${this.projectId}/events/${event.eventID}/json/`;
  140. const traceId = event.contexts?.trace?.trace_id ?? '';
  141. const {start, end} = getTraceTimeRangeFromEvent(event);
  142. const hasProfilingFeature = organization.features.includes('profiling');
  143. const profileId = (event as EventTransaction).contexts?.profile?.profile_id ?? null;
  144. const originatingUrl = getUrlFromEvent(event);
  145. return (
  146. <TraceMetaQuery
  147. location={location}
  148. orgSlug={organization.slug}
  149. traceId={traceId}
  150. start={start}
  151. end={end}
  152. >
  153. {metaResults => (
  154. <TraceDetailsRouting event={event} metaResults={metaResults}>
  155. <QuickTraceQuery
  156. event={event}
  157. location={location}
  158. orgSlug={organization.slug}
  159. >
  160. {results => (
  161. <TransactionProfileIdProvider
  162. projectId={event.projectID}
  163. transactionId={event.type === 'transaction' ? event.id : undefined}
  164. timestamp={event.dateReceived}
  165. >
  166. <Layout.Header>
  167. <Layout.HeaderContent>
  168. <Breadcrumb
  169. organization={organization}
  170. location={location}
  171. transaction={{
  172. project: event.projectID,
  173. name: transactionName,
  174. }}
  175. eventSlug={eventSlug}
  176. />
  177. <Layout.Title data-test-id="event-header">
  178. <Tooltip showOnlyOnOverflow skipWrapper title={transactionName}>
  179. <EventTitle>{event.title}</EventTitle>
  180. </Tooltip>
  181. {originatingUrl && (
  182. <Button
  183. aria-label={t('Go to originating URL')}
  184. size="zero"
  185. icon={<IconOpen />}
  186. href={originatingUrl}
  187. external
  188. translucentBorder
  189. borderless
  190. />
  191. )}
  192. </Layout.Title>
  193. </Layout.HeaderContent>
  194. <Layout.HeaderActions>
  195. <ButtonBar gap={1}>
  196. <Button size="sm" onClick={this.toggleSidebar}>
  197. {isSidebarVisible ? 'Hide Details' : 'Show Details'}
  198. </Button>
  199. {results && (
  200. <Button
  201. size="sm"
  202. icon={<IconOpen />}
  203. href={eventJsonUrl}
  204. external
  205. >
  206. {t('JSON')} (<FileSize bytes={event.size} />)
  207. </Button>
  208. )}
  209. {hasProfilingFeature && isTransaction(event) && (
  210. <TransactionToProfileButton
  211. event={event}
  212. projectSlug={this.projectId}
  213. />
  214. )}
  215. </ButtonBar>
  216. </Layout.HeaderActions>
  217. </Layout.Header>
  218. <Layout.Body>
  219. {results && (
  220. <Layout.Main fullWidth>
  221. <EventMetas
  222. quickTrace={results}
  223. meta={metaResults?.meta ?? null}
  224. event={event}
  225. organization={organization}
  226. projectId={this.projectId}
  227. location={location}
  228. errorDest="issue"
  229. transactionDest="performance"
  230. />
  231. </Layout.Main>
  232. )}
  233. <Layout.Main fullWidth={!isSidebarVisible}>
  234. <Projects orgId={organization.slug} slugs={[this.projectId]}>
  235. {({projects: _projects}) => (
  236. <SpanEntryContext.Provider
  237. value={{
  238. getViewChildTransactionTarget: childTransactionProps => {
  239. return getTransactionDetailsUrl(
  240. organization.slug,
  241. childTransactionProps.eventSlug,
  242. childTransactionProps.transaction,
  243. location.query
  244. );
  245. },
  246. }}
  247. >
  248. <QuickTraceContext.Provider value={results}>
  249. {hasProfilingFeature ? (
  250. <ProfilesProvider
  251. orgSlug={organization.slug}
  252. projectSlug={this.projectId}
  253. profileId={profileId || ''}
  254. >
  255. <ProfileContext.Consumer>
  256. {profiles => (
  257. <ProfileGroupProvider
  258. type="flamechart"
  259. input={
  260. profiles?.type === 'resolved'
  261. ? profiles.data
  262. : null
  263. }
  264. traceID={profileId || ''}
  265. >
  266. <BorderlessEventEntries
  267. organization={organization}
  268. event={event}
  269. project={_projects[0] as Project}
  270. showTagSummary={false}
  271. location={location}
  272. />
  273. </ProfileGroupProvider>
  274. )}
  275. </ProfileContext.Consumer>
  276. </ProfilesProvider>
  277. ) : (
  278. <BorderlessEventEntries
  279. organization={organization}
  280. event={event}
  281. project={_projects[0] as Project}
  282. showTagSummary={false}
  283. location={location}
  284. />
  285. )}
  286. </QuickTraceContext.Provider>
  287. </SpanEntryContext.Provider>
  288. )}
  289. </Projects>
  290. </Layout.Main>
  291. {isSidebarVisible && (
  292. <Layout.Side>
  293. {results === undefined && (
  294. <Fragment>
  295. <EventMetadata
  296. event={event}
  297. organization={organization}
  298. projectId={this.projectId}
  299. />
  300. <RootSpanStatus event={event} />
  301. </Fragment>
  302. )}
  303. <EventVitals event={event} />
  304. <EventCustomPerformanceMetrics
  305. event={event}
  306. location={location}
  307. organization={organization}
  308. source={EventDetailPageSource.PERFORMANCE}
  309. />
  310. <TagsTable
  311. event={event}
  312. query={query}
  313. generateUrl={this.generateTagUrl}
  314. />
  315. </Layout.Side>
  316. )}
  317. </Layout.Body>
  318. </TransactionProfileIdProvider>
  319. )}
  320. </QuickTraceQuery>
  321. </TraceDetailsRouting>
  322. )}
  323. </TraceMetaQuery>
  324. );
  325. }
  326. renderError(error: Error) {
  327. const notFound = Object.values(this.state.errors).find(
  328. resp => resp && resp.status === 404
  329. );
  330. const permissionDenied = Object.values(this.state.errors).find(
  331. resp => resp && resp.status === 403
  332. );
  333. if (notFound) {
  334. return <NotFound />;
  335. }
  336. if (permissionDenied) {
  337. return (
  338. <LoadingError message={t('You do not have permission to view that event.')} />
  339. );
  340. }
  341. return super.renderError(error, true);
  342. }
  343. renderComponent() {
  344. const {organization} = this.props;
  345. return (
  346. <SentryDocumentTitle
  347. title={t('Performance — Event Details')}
  348. orgSlug={organization.slug}
  349. >
  350. {super.renderComponent() as React.ReactChild}
  351. </SentryDocumentTitle>
  352. );
  353. }
  354. }
  355. // We can't use theme.overflowEllipsis so that width isn't set to 100%
  356. // since button withn a link has to immediately follow the text in the title
  357. const EventTitle = styled('div')`
  358. display: block;
  359. white-space: nowrap;
  360. overflow: hidden;
  361. text-overflow: ellipsis;
  362. `;
  363. export default withRouteAnalytics(EventDetailsContent);