content.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 {TransactionProfileIdProvider} from 'sentry/components/profiling/transactionProfileIdProvider';
  19. import {TransactionToProfileButton} from 'sentry/components/profiling/transactionToProfileButton';
  20. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  21. import {TagsTable} from 'sentry/components/tagsTable';
  22. import {IconOpen} from 'sentry/icons';
  23. import {t} from 'sentry/locale';
  24. import {Organization, Project} from 'sentry/types';
  25. import {Event, EventTag, EventTransaction} from 'sentry/types/event';
  26. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  27. import {formatTagKey} from 'sentry/utils/discover/fields';
  28. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  29. import QuickTraceQuery from 'sentry/utils/performance/quickTrace/quickTraceQuery';
  30. import TraceMetaQuery from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  31. import {getTraceTimeRangeFromEvent} from 'sentry/utils/performance/quickTrace/utils';
  32. import {getTransactionDetailsUrl} from 'sentry/utils/performance/urls';
  33. import Projects from 'sentry/utils/projects';
  34. import {appendTagCondition, decodeScalar} from 'sentry/utils/queryString';
  35. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  36. import {ProfileGroupProvider} from 'sentry/views/profiling/profileGroupProvider';
  37. import {ProfileContext, ProfilesProvider} from 'sentry/views/profiling/profilesProvider';
  38. import {transactionSummaryRouteWithQuery} from '../transactionSummary/utils';
  39. import {getSelectedProjectPlatforms} from '../utils';
  40. import EventMetas from './eventMetas';
  41. import FinishSetupAlert from './finishSetupAlert';
  42. type Props = Pick<RouteComponentProps<{eventSlug: string}, {}>, 'params' | 'location'> & {
  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, 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. has_otel: event?.contexts?.otel !== undefined,
  120. });
  121. const {isSidebarVisible} = this.state;
  122. const transactionName = event.title;
  123. const query = decodeScalar(location.query.query, '');
  124. const eventJsonUrl = `/api/0/projects/${organization.slug}/${this.projectId}/events/${event.eventID}/json/`;
  125. const traceId = event.contexts?.trace?.trace_id ?? '';
  126. const {start, end} = getTraceTimeRangeFromEvent(event);
  127. const hasProfilingFeature = organization.features.includes('profiling');
  128. const hasProfilingPreviewsFeature =
  129. hasProfilingFeature && organization.features.includes('profiling-previews');
  130. const profileId = (event as EventTransaction).contexts?.profile?.profile_id ?? null;
  131. return (
  132. <TraceMetaQuery
  133. location={location}
  134. orgSlug={organization.slug}
  135. traceId={traceId}
  136. start={start}
  137. end={end}
  138. >
  139. {metaResults => (
  140. <QuickTraceQuery event={event} location={location} orgSlug={organization.slug}>
  141. {results => (
  142. <TransactionProfileIdProvider
  143. projectId={event.projectID}
  144. transactionId={event.type === 'transaction' ? event.id : undefined}
  145. timestamp={event.dateReceived}
  146. >
  147. <Layout.Header>
  148. <Layout.HeaderContent>
  149. <Breadcrumb
  150. organization={organization}
  151. location={location}
  152. transaction={{
  153. project: event.projectID,
  154. name: transactionName,
  155. }}
  156. eventSlug={eventSlug}
  157. />
  158. <Layout.Title data-test-id="event-header">{event.title}</Layout.Title>
  159. </Layout.HeaderContent>
  160. <Layout.HeaderActions>
  161. <ButtonBar gap={1}>
  162. <Button size="sm" onClick={this.toggleSidebar}>
  163. {isSidebarVisible ? 'Hide Details' : 'Show Details'}
  164. </Button>
  165. {results && (
  166. <Button
  167. size="sm"
  168. icon={<IconOpen />}
  169. href={eventJsonUrl}
  170. external
  171. >
  172. {t('JSON')} (<FileSize bytes={event.size} />)
  173. </Button>
  174. )}
  175. {hasProfilingFeature && (
  176. <TransactionToProfileButton projectSlug={this.projectId} />
  177. )}
  178. </ButtonBar>
  179. </Layout.HeaderActions>
  180. </Layout.Header>
  181. <Layout.Body>
  182. {results && (
  183. <Layout.Main fullWidth>
  184. <EventMetas
  185. quickTrace={results}
  186. meta={metaResults?.meta ?? null}
  187. event={event}
  188. organization={organization}
  189. projectId={this.projectId}
  190. location={location}
  191. errorDest="issue"
  192. transactionDest="performance"
  193. />
  194. </Layout.Main>
  195. )}
  196. <Layout.Main fullWidth={!isSidebarVisible}>
  197. <Projects orgId={organization.slug} slugs={[this.projectId]}>
  198. {({projects: _projects}) => (
  199. <SpanEntryContext.Provider
  200. value={{
  201. getViewChildTransactionTarget: childTransactionProps => {
  202. return getTransactionDetailsUrl(
  203. organization.slug,
  204. childTransactionProps.eventSlug,
  205. childTransactionProps.transaction,
  206. location.query
  207. );
  208. },
  209. }}
  210. >
  211. <QuickTraceContext.Provider value={results}>
  212. {hasProfilingPreviewsFeature ? (
  213. <ProfilesProvider
  214. orgSlug={organization.slug}
  215. projectSlug={this.projectId}
  216. profileId={profileId || ''}
  217. >
  218. <ProfileContext.Consumer>
  219. {profiles => (
  220. <ProfileGroupProvider
  221. type="flamechart"
  222. input={
  223. profiles?.type === 'resolved'
  224. ? profiles.data
  225. : null
  226. }
  227. traceID={profileId || ''}
  228. >
  229. <BorderlessEventEntries
  230. organization={organization}
  231. event={event}
  232. project={_projects[0] as Project}
  233. showTagSummary={false}
  234. location={location}
  235. />
  236. </ProfileGroupProvider>
  237. )}
  238. </ProfileContext.Consumer>
  239. </ProfilesProvider>
  240. ) : (
  241. <BorderlessEventEntries
  242. organization={organization}
  243. event={event}
  244. project={_projects[0] as Project}
  245. showTagSummary={false}
  246. location={location}
  247. />
  248. )}
  249. </QuickTraceContext.Provider>
  250. </SpanEntryContext.Provider>
  251. )}
  252. </Projects>
  253. </Layout.Main>
  254. {isSidebarVisible && (
  255. <Layout.Side>
  256. {results === undefined && (
  257. <Fragment>
  258. <EventMetadata
  259. event={event}
  260. organization={organization}
  261. projectId={this.projectId}
  262. />
  263. <RootSpanStatus event={event} />
  264. </Fragment>
  265. )}
  266. <EventVitals event={event} />
  267. {(organization.features.includes('dashboards-mep') ||
  268. organization.features.includes('mep-rollout-flag')) && (
  269. <EventCustomPerformanceMetrics
  270. event={event}
  271. location={location}
  272. organization={organization}
  273. source={EventDetailPageSource.PERFORMANCE}
  274. />
  275. )}
  276. <TagsTable
  277. event={event}
  278. query={query}
  279. generateUrl={this.generateTagUrl}
  280. />
  281. </Layout.Side>
  282. )}
  283. </Layout.Body>
  284. </TransactionProfileIdProvider>
  285. )}
  286. </QuickTraceQuery>
  287. )}
  288. </TraceMetaQuery>
  289. );
  290. }
  291. renderError(error: Error) {
  292. const notFound = Object.values(this.state.errors).find(
  293. resp => resp && resp.status === 404
  294. );
  295. const permissionDenied = Object.values(this.state.errors).find(
  296. resp => resp && resp.status === 403
  297. );
  298. if (notFound) {
  299. return <NotFound />;
  300. }
  301. if (permissionDenied) {
  302. return (
  303. <LoadingError message={t('You do not have permission to view that event.')} />
  304. );
  305. }
  306. return super.renderError(error, true);
  307. }
  308. renderComponent() {
  309. const {organization} = this.props;
  310. return (
  311. <SentryDocumentTitle
  312. title={t('Performance - Event Details')}
  313. orgSlug={organization.slug}
  314. >
  315. {super.renderComponent() as React.ReactChild}
  316. </SentryDocumentTitle>
  317. );
  318. }
  319. }
  320. export default EventDetailsContent;