content.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. import {Fragment, useEffect, useState} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import Alert from 'sentry/components/alert';
  5. import {Button} from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import NotFound from 'sentry/components/errors/notFound';
  8. import EventCustomPerformanceMetrics, {
  9. EventDetailPageSource,
  10. } from 'sentry/components/events/eventCustomPerformanceMetrics';
  11. import {BorderlessEventEntries} from 'sentry/components/events/eventEntries';
  12. import EventMetadata from 'sentry/components/events/eventMetadata';
  13. import EventVitals from 'sentry/components/events/eventVitals';
  14. import getUrlFromEvent from 'sentry/components/events/interfaces/request/getUrlFromEvent';
  15. import * as SpanEntryContext from 'sentry/components/events/interfaces/spans/context';
  16. import RootSpanStatus from 'sentry/components/events/rootSpanStatus';
  17. import FileSize from 'sentry/components/fileSize';
  18. import * as Layout from 'sentry/components/layouts/thirds';
  19. import LoadingError from 'sentry/components/loadingError';
  20. import LoadingIndicator from 'sentry/components/loadingIndicator';
  21. import {TransactionProfileIdProvider} from 'sentry/components/profiling/transactionProfileIdProvider';
  22. import {TransactionToProfileButton} from 'sentry/components/profiling/transactionToProfileButton';
  23. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  24. import {TagsTable} from 'sentry/components/tagsTable';
  25. import {Tooltip} from 'sentry/components/tooltip';
  26. import {IconOpen} from 'sentry/icons';
  27. import {t} from 'sentry/locale';
  28. import type {Organization, Project} from 'sentry/types';
  29. import type {Event, EventTag, EventTransaction} from 'sentry/types/event';
  30. import {formatTagKey} from 'sentry/utils/discover/fields';
  31. import {getAnalyticsDataForEvent} from 'sentry/utils/events';
  32. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  33. import QuickTraceQuery from 'sentry/utils/performance/quickTrace/quickTraceQuery';
  34. import TraceMetaQuery from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  35. import {
  36. getTraceTimeRangeFromEvent,
  37. isTransaction,
  38. } from 'sentry/utils/performance/quickTrace/utils';
  39. import {getTransactionDetailsUrl} from 'sentry/utils/performance/urls';
  40. import Projects from 'sentry/utils/projects';
  41. import {useApiQuery} from 'sentry/utils/queryClient';
  42. import {appendTagCondition, decodeScalar} from 'sentry/utils/queryString';
  43. import type {WithRouteAnalyticsProps} from 'sentry/utils/routeAnalytics/withRouteAnalytics';
  44. import withRouteAnalytics from 'sentry/utils/routeAnalytics/withRouteAnalytics';
  45. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  46. import {ProfileGroupProvider} from 'sentry/views/profiling/profileGroupProvider';
  47. import {ProfileContext, ProfilesProvider} from 'sentry/views/profiling/profilesProvider';
  48. import TraceDetailsRouting from '../traceDetails/TraceDetailsRouting';
  49. import {transactionSummaryRouteWithQuery} from '../transactionSummary/utils';
  50. import {getSelectedProjectPlatforms} from '../utils';
  51. import EventMetas from './eventMetas';
  52. import FinishSetupAlert from './finishSetupAlert';
  53. type Props = Pick<RouteComponentProps<{eventSlug: string}, {}>, 'params' | 'location'> &
  54. WithRouteAnalyticsProps & {
  55. eventSlug: string;
  56. organization: Organization;
  57. projects: Project[];
  58. };
  59. function EventDetailsContent(props: Props) {
  60. const [isSidebarVisible, setIsSidebarVisible] = useState<boolean>(true);
  61. const projectId = props.eventSlug.split(':')[0];
  62. const {organization, eventSlug, location} = props;
  63. const {
  64. data: event,
  65. isLoading,
  66. error,
  67. } = useApiQuery<Event>(
  68. [`/organizations/${organization.slug}/events/${eventSlug}/`],
  69. {staleTime: 2 * 60 * 1000} // 2 minutes in milliseonds
  70. );
  71. useEffect(() => {
  72. if (event) {
  73. const {projects} = props;
  74. props.setEventNames(
  75. 'performance.event_details',
  76. 'Performance: Opened Event Details'
  77. );
  78. props.setRouteAnalyticsParams({
  79. event_type: event?.type,
  80. project_platforms: getSelectedProjectPlatforms(location, projects),
  81. ...getAnalyticsDataForEvent(event),
  82. });
  83. }
  84. }, [event, props, location]);
  85. const generateTagUrl = (tag: EventTag) => {
  86. if (!event) {
  87. return '';
  88. }
  89. const query = decodeScalar(location.query.query, '');
  90. const newQuery = {
  91. ...location.query,
  92. query: appendTagCondition(query, formatTagKey(tag.key), tag.value),
  93. };
  94. return transactionSummaryRouteWithQuery({
  95. orgSlug: organization.slug,
  96. transaction: event.title,
  97. projectID: event.projectID,
  98. query: newQuery,
  99. });
  100. };
  101. function renderContent(transaction: Event) {
  102. const transactionName = transaction.title;
  103. const query = decodeScalar(location.query.query, '');
  104. const eventJsonUrl = `/api/0/projects/${organization.slug}/${projectId}/events/${transaction.eventID}/json/`;
  105. const traceId = transaction.contexts?.trace?.trace_id ?? '';
  106. const {start, end} = getTraceTimeRangeFromEvent(transaction);
  107. const hasProfilingFeature = organization.features.includes('profiling');
  108. const profileId =
  109. (transaction as EventTransaction).contexts?.profile?.profile_id ?? null;
  110. const originatingUrl = getUrlFromEvent(transaction);
  111. return (
  112. <TraceMetaQuery
  113. location={location}
  114. orgSlug={organization.slug}
  115. traceId={traceId}
  116. start={start}
  117. end={end}
  118. >
  119. {metaResults => (
  120. <TraceDetailsRouting event={transaction} metaResults={metaResults}>
  121. <QuickTraceQuery
  122. event={transaction}
  123. location={location}
  124. orgSlug={organization.slug}
  125. >
  126. {results => (
  127. <TransactionProfileIdProvider
  128. projectId={transaction.projectID}
  129. transactionId={
  130. transaction.type === 'transaction' ? transaction.id : undefined
  131. }
  132. timestamp={transaction.dateReceived}
  133. >
  134. <Layout.Header>
  135. <Layout.HeaderContent>
  136. <Breadcrumb
  137. organization={organization}
  138. location={location}
  139. transaction={{
  140. project: transaction.projectID,
  141. name: transactionName,
  142. }}
  143. eventSlug={eventSlug}
  144. />
  145. <Layout.Title data-test-id="event-header">
  146. <Tooltip showOnlyOnOverflow skipWrapper title={transactionName}>
  147. <EventTitle>{transaction.title}</EventTitle>
  148. </Tooltip>
  149. {originatingUrl && (
  150. <Button
  151. aria-label={t('Go to originating URL')}
  152. size="zero"
  153. icon={<IconOpen />}
  154. href={originatingUrl}
  155. external
  156. translucentBorder
  157. borderless
  158. />
  159. )}
  160. </Layout.Title>
  161. </Layout.HeaderContent>
  162. <Layout.HeaderActions>
  163. <ButtonBar gap={1}>
  164. <Button
  165. size="sm"
  166. onClick={() => setIsSidebarVisible(prev => !prev)}
  167. >
  168. {isSidebarVisible ? 'Hide Details' : 'Show Details'}
  169. </Button>
  170. {results && (
  171. <Button
  172. size="sm"
  173. icon={<IconOpen />}
  174. href={eventJsonUrl}
  175. external
  176. >
  177. {t('JSON')} (<FileSize bytes={transaction.size} />)
  178. </Button>
  179. )}
  180. {hasProfilingFeature && isTransaction(transaction) && (
  181. <TransactionToProfileButton
  182. event={transaction}
  183. projectSlug={projectId}
  184. />
  185. )}
  186. </ButtonBar>
  187. </Layout.HeaderActions>
  188. </Layout.Header>
  189. <Layout.Body>
  190. {results && (
  191. <Layout.Main fullWidth>
  192. <EventMetas
  193. quickTrace={results}
  194. meta={metaResults?.meta ?? null}
  195. event={transaction}
  196. organization={organization}
  197. projectId={projectId}
  198. location={location}
  199. errorDest="issue"
  200. transactionDest="performance"
  201. />
  202. </Layout.Main>
  203. )}
  204. <Layout.Main fullWidth={!isSidebarVisible}>
  205. <Projects orgId={organization.slug} slugs={[projectId]}>
  206. {({projects: _projects}) => (
  207. <SpanEntryContext.Provider
  208. value={{
  209. getViewChildTransactionTarget: childTransactionProps => {
  210. return getTransactionDetailsUrl(
  211. organization.slug,
  212. childTransactionProps.eventSlug,
  213. childTransactionProps.transaction,
  214. location.query
  215. );
  216. },
  217. }}
  218. >
  219. <QuickTraceContext.Provider value={results}>
  220. {hasProfilingFeature ? (
  221. <ProfilesProvider
  222. orgSlug={organization.slug}
  223. projectSlug={projectId}
  224. profileId={profileId || ''}
  225. >
  226. <ProfileContext.Consumer>
  227. {profiles => (
  228. <ProfileGroupProvider
  229. type="flamechart"
  230. input={
  231. profiles?.type === 'resolved'
  232. ? profiles.data
  233. : null
  234. }
  235. traceID={profileId || ''}
  236. >
  237. <BorderlessEventEntries
  238. organization={organization}
  239. event={event}
  240. project={_projects[0] as Project}
  241. showTagSummary={false}
  242. location={location}
  243. />
  244. </ProfileGroupProvider>
  245. )}
  246. </ProfileContext.Consumer>
  247. </ProfilesProvider>
  248. ) : (
  249. <BorderlessEventEntries
  250. organization={organization}
  251. event={event}
  252. project={_projects[0] as Project}
  253. showTagSummary={false}
  254. location={location}
  255. />
  256. )}
  257. </QuickTraceContext.Provider>
  258. </SpanEntryContext.Provider>
  259. )}
  260. </Projects>
  261. </Layout.Main>
  262. {isSidebarVisible && (
  263. <Layout.Side>
  264. {results === undefined && (
  265. <Fragment>
  266. <EventMetadata
  267. event={transaction}
  268. organization={organization}
  269. projectId={projectId}
  270. />
  271. <RootSpanStatus event={transaction} />
  272. </Fragment>
  273. )}
  274. <EventVitals event={transaction} />
  275. <EventCustomPerformanceMetrics
  276. event={transaction}
  277. location={location}
  278. organization={organization}
  279. source={EventDetailPageSource.PERFORMANCE}
  280. />
  281. <TagsTable
  282. event={transaction}
  283. query={query}
  284. generateUrl={generateTagUrl}
  285. />
  286. </Layout.Side>
  287. )}
  288. </Layout.Body>
  289. </TransactionProfileIdProvider>
  290. )}
  291. </QuickTraceQuery>
  292. </TraceDetailsRouting>
  293. )}
  294. </TraceMetaQuery>
  295. );
  296. }
  297. function renderBody() {
  298. if (!event) {
  299. return <NotFound />;
  300. }
  301. const isSampleTransaction = event.tags.some(
  302. tag => tag.key === 'sample_event' && tag.value === 'yes'
  303. );
  304. return (
  305. <Fragment>
  306. {isSampleTransaction && (
  307. <FinishSetupAlert organization={organization} projectId={projectId} />
  308. )}
  309. {renderContent(event)}
  310. </Fragment>
  311. );
  312. }
  313. if (isLoading) {
  314. return <LoadingIndicator />;
  315. }
  316. if (error) {
  317. const notFound = error.status === 404;
  318. const permissionDenied = error.status === 403;
  319. if (notFound) {
  320. return <NotFound />;
  321. }
  322. if (permissionDenied) {
  323. return (
  324. <LoadingError message={t('You do not have permission to view that event.')} />
  325. );
  326. }
  327. return (
  328. <Alert type="error" showIcon>
  329. {error.message}
  330. </Alert>
  331. );
  332. }
  333. return (
  334. <SentryDocumentTitle
  335. title={t('Performance — Event Details')}
  336. orgSlug={organization.slug}
  337. >
  338. {renderBody() as React.ReactChild}
  339. </SentryDocumentTitle>
  340. );
  341. }
  342. // We can't use theme.overflowEllipsis so that width isn't set to 100%
  343. // since button withn a link has to immediately follow the text in the title
  344. const EventTitle = styled('div')`
  345. display: block;
  346. white-space: nowrap;
  347. overflow: hidden;
  348. text-overflow: ellipsis;
  349. `;
  350. export default withRouteAnalytics(EventDetailsContent);