content.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. <QuickTraceQuery
  121. event={transaction}
  122. location={location}
  123. orgSlug={organization.slug}
  124. >
  125. {results => (
  126. <TransactionProfileIdProvider
  127. projectId={transaction.projectID}
  128. transactionId={
  129. transaction.type === 'transaction' ? transaction.id : undefined
  130. }
  131. timestamp={transaction.dateReceived}
  132. >
  133. <Layout.Header>
  134. <Layout.HeaderContent>
  135. <Breadcrumb
  136. organization={organization}
  137. location={location}
  138. transaction={{
  139. project: transaction.projectID,
  140. name: transactionName,
  141. }}
  142. eventSlug={eventSlug}
  143. />
  144. <Layout.Title data-test-id="event-header">
  145. <Tooltip showOnlyOnOverflow skipWrapper title={transactionName}>
  146. <EventTitle>{transaction.title}</EventTitle>
  147. </Tooltip>
  148. {originatingUrl && (
  149. <Button
  150. aria-label={t('Go to originating URL')}
  151. size="zero"
  152. icon={<IconOpen />}
  153. href={originatingUrl}
  154. external
  155. translucentBorder
  156. borderless
  157. />
  158. )}
  159. </Layout.Title>
  160. </Layout.HeaderContent>
  161. <Layout.HeaderActions>
  162. <ButtonBar gap={1}>
  163. <Button
  164. size="sm"
  165. onClick={() => setIsSidebarVisible(prev => !prev)}
  166. >
  167. {isSidebarVisible ? 'Hide Details' : 'Show Details'}
  168. </Button>
  169. {results && (
  170. <Button
  171. size="sm"
  172. icon={<IconOpen />}
  173. href={eventJsonUrl}
  174. external
  175. >
  176. {t('JSON')} (<FileSize bytes={transaction.size} />)
  177. </Button>
  178. )}
  179. {hasProfilingFeature && isTransaction(transaction) && (
  180. <TransactionToProfileButton
  181. event={transaction}
  182. projectSlug={projectId}
  183. />
  184. )}
  185. </ButtonBar>
  186. </Layout.HeaderActions>
  187. </Layout.Header>
  188. <Layout.Body>
  189. {results && (
  190. <Layout.Main fullWidth>
  191. <EventMetas
  192. quickTrace={results}
  193. meta={metaResults?.meta ?? null}
  194. event={transaction}
  195. organization={organization}
  196. projectId={projectId}
  197. location={location}
  198. errorDest="issue"
  199. transactionDest="performance"
  200. />
  201. </Layout.Main>
  202. )}
  203. <Layout.Main fullWidth={!isSidebarVisible}>
  204. <Projects orgId={organization.slug} slugs={[projectId]}>
  205. {({projects: _projects}) => (
  206. <SpanEntryContext.Provider
  207. value={{
  208. getViewChildTransactionTarget: childTransactionProps => {
  209. return getTransactionDetailsUrl(
  210. organization.slug,
  211. childTransactionProps.eventSlug,
  212. childTransactionProps.transaction,
  213. location.query
  214. );
  215. },
  216. }}
  217. >
  218. <QuickTraceContext.Provider value={results}>
  219. {hasProfilingFeature ? (
  220. <ProfilesProvider
  221. orgSlug={organization.slug}
  222. projectSlug={projectId}
  223. profileId={profileId || ''}
  224. >
  225. <ProfileContext.Consumer>
  226. {profiles => (
  227. <ProfileGroupProvider
  228. type="flamechart"
  229. input={
  230. profiles?.type === 'resolved'
  231. ? profiles.data
  232. : null
  233. }
  234. traceID={profileId || ''}
  235. >
  236. <BorderlessEventEntries
  237. organization={organization}
  238. event={event}
  239. project={_projects[0] as Project}
  240. showTagSummary={false}
  241. />
  242. </ProfileGroupProvider>
  243. )}
  244. </ProfileContext.Consumer>
  245. </ProfilesProvider>
  246. ) : (
  247. <BorderlessEventEntries
  248. organization={organization}
  249. event={event}
  250. project={_projects[0] as Project}
  251. showTagSummary={false}
  252. />
  253. )}
  254. </QuickTraceContext.Provider>
  255. </SpanEntryContext.Provider>
  256. )}
  257. </Projects>
  258. </Layout.Main>
  259. {isSidebarVisible && (
  260. <Layout.Side>
  261. {results === undefined && (
  262. <Fragment>
  263. <EventMetadata
  264. event={transaction}
  265. organization={organization}
  266. projectId={projectId}
  267. />
  268. <RootSpanStatus event={transaction} />
  269. </Fragment>
  270. )}
  271. <EventVitals event={transaction} />
  272. <EventCustomPerformanceMetrics
  273. event={transaction}
  274. location={location}
  275. organization={organization}
  276. source={EventDetailPageSource.PERFORMANCE}
  277. />
  278. <TagsTable
  279. event={transaction}
  280. query={query}
  281. generateUrl={generateTagUrl}
  282. />
  283. </Layout.Side>
  284. )}
  285. </Layout.Body>
  286. </TransactionProfileIdProvider>
  287. )}
  288. </QuickTraceQuery>
  289. )}
  290. </TraceMetaQuery>
  291. );
  292. }
  293. function renderBody() {
  294. if (!event) {
  295. return <NotFound />;
  296. }
  297. const isSampleTransaction = event.tags.some(
  298. tag => tag.key === 'sample_event' && tag.value === 'yes'
  299. );
  300. return (
  301. <TraceDetailsRouting event={event}>
  302. <Fragment>
  303. {isSampleTransaction && (
  304. <FinishSetupAlert organization={organization} projectId={projectId} />
  305. )}
  306. {renderContent(event)}
  307. </Fragment>
  308. </TraceDetailsRouting>
  309. );
  310. }
  311. if (isLoading) {
  312. return <LoadingIndicator />;
  313. }
  314. if (error) {
  315. const notFound = error.status === 404;
  316. const permissionDenied = error.status === 403;
  317. if (notFound) {
  318. return <NotFound />;
  319. }
  320. if (permissionDenied) {
  321. return (
  322. <LoadingError message={t('You do not have permission to view that event.')} />
  323. );
  324. }
  325. return (
  326. <Alert type="error" showIcon>
  327. {error.message}
  328. </Alert>
  329. );
  330. }
  331. return (
  332. <SentryDocumentTitle
  333. title={t('Performance — Event Details')}
  334. orgSlug={organization.slug}
  335. >
  336. {renderBody() as React.ReactChild}
  337. </SentryDocumentTitle>
  338. );
  339. }
  340. // We can't use theme.overflowEllipsis so that width isn't set to 100%
  341. // since button withn a link has to immediately follow the text in the title
  342. const EventTitle = styled('div')`
  343. display: block;
  344. white-space: nowrap;
  345. overflow: hidden;
  346. text-overflow: ellipsis;
  347. `;
  348. export default withRouteAnalytics(EventDetailsContent);