content.tsx 11 KB

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