content.tsx 14 KB

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