content.tsx 11 KB

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