content.tsx 11 KB

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