content.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 size="sm" onClick={this.toggleSidebar}>
  155. {isSidebarVisible ? 'Hide Details' : 'Show Details'}
  156. </Button>
  157. {results && (
  158. <Button
  159. size="sm"
  160. icon={<IconOpen />}
  161. href={eventJsonUrl}
  162. external
  163. >
  164. {t('JSON')} (<FileSize bytes={event.size} />)
  165. </Button>
  166. )}
  167. {hasProfilingFeature && (
  168. <TransactionToProfileButton
  169. orgId={organization.slug}
  170. projectId={this.projectId}
  171. transactionId={event.eventID}
  172. />
  173. )}
  174. </ButtonBar>
  175. </Layout.HeaderActions>
  176. </Layout.Header>
  177. <Layout.Body>
  178. {results && (
  179. <Layout.Main fullWidth>
  180. <EventMetas
  181. quickTrace={results}
  182. meta={metaResults?.meta ?? null}
  183. event={event}
  184. organization={organization}
  185. projectId={this.projectId}
  186. location={location}
  187. errorDest="issue"
  188. transactionDest="performance"
  189. />
  190. </Layout.Main>
  191. )}
  192. <Layout.Main fullWidth={!isSidebarVisible}>
  193. <Projects orgId={organization.slug} slugs={[this.projectId]}>
  194. {({projects: _projects}) => (
  195. <SpanEntryContext.Provider
  196. value={{
  197. getViewChildTransactionTarget: childTransactionProps => {
  198. return getTransactionDetailsUrl(
  199. organization.slug,
  200. childTransactionProps.eventSlug,
  201. childTransactionProps.transaction,
  202. location.query
  203. );
  204. },
  205. }}
  206. >
  207. <QuickTraceContext.Provider value={results}>
  208. <BorderlessEventEntries
  209. organization={organization}
  210. event={event}
  211. project={_projects[0] as Project}
  212. showTagSummary={false}
  213. location={location}
  214. api={this.api}
  215. router={router}
  216. route={route}
  217. />
  218. </QuickTraceContext.Provider>
  219. </SpanEntryContext.Provider>
  220. )}
  221. </Projects>
  222. </Layout.Main>
  223. {isSidebarVisible && (
  224. <Layout.Side>
  225. {results === undefined && (
  226. <Fragment>
  227. <EventMetadata
  228. event={event}
  229. organization={organization}
  230. projectId={this.projectId}
  231. />
  232. <RootSpanStatus event={event} />
  233. </Fragment>
  234. )}
  235. <EventVitals event={event} />
  236. {(organization.features.includes('dashboards-mep') ||
  237. organization.features.includes('mep-rollout-flag')) && (
  238. <EventCustomPerformanceMetrics
  239. event={event}
  240. location={location}
  241. organization={organization}
  242. source={EventDetailPageSource.PERFORMANCE}
  243. />
  244. )}
  245. <TagsTable
  246. event={event}
  247. query={query}
  248. generateUrl={this.generateTagUrl}
  249. />
  250. </Layout.Side>
  251. )}
  252. </Layout.Body>
  253. </Fragment>
  254. )}
  255. </QuickTraceQuery>
  256. )}
  257. </TraceMetaQuery>
  258. );
  259. }
  260. renderError(error: Error) {
  261. const notFound = Object.values(this.state.errors).find(
  262. resp => resp && resp.status === 404
  263. );
  264. const permissionDenied = Object.values(this.state.errors).find(
  265. resp => resp && resp.status === 403
  266. );
  267. if (notFound) {
  268. return <NotFound />;
  269. }
  270. if (permissionDenied) {
  271. return (
  272. <LoadingError message={t('You do not have permission to view that event.')} />
  273. );
  274. }
  275. return super.renderError(error, true);
  276. }
  277. renderComponent() {
  278. const {organization} = this.props;
  279. return (
  280. <SentryDocumentTitle
  281. title={t('Performance - Event Details')}
  282. orgSlug={organization.slug}
  283. >
  284. {super.renderComponent() as React.ReactChild}
  285. </SentryDocumentTitle>
  286. );
  287. }
  288. }
  289. export default EventDetailsContent;