content.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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 {Event, EventTag, EventTransaction} from 'sentry/types/event';
  29. import type {Organization} from 'sentry/types/organization';
  30. import type {Project} from 'sentry/types/project';
  31. import {formatTagKey} from 'sentry/utils/discover/fields';
  32. import {getAnalyticsDataForEvent} from 'sentry/utils/events';
  33. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  34. import QuickTraceQuery from 'sentry/utils/performance/quickTrace/quickTraceQuery';
  35. import TraceMetaQuery from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  36. import {
  37. getTraceTimeRangeFromEvent,
  38. isTransaction,
  39. } from 'sentry/utils/performance/quickTrace/utils';
  40. import {getTransactionDetailsUrl} from 'sentry/utils/performance/urls';
  41. import Projects from 'sentry/utils/projects';
  42. import {useApiQuery} from 'sentry/utils/queryClient';
  43. import {appendTagCondition, decodeScalar} from 'sentry/utils/queryString';
  44. import type {WithRouteAnalyticsProps} from 'sentry/utils/routeAnalytics/withRouteAnalytics';
  45. import withRouteAnalytics from 'sentry/utils/routeAnalytics/withRouteAnalytics';
  46. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  47. import {ProfileGroupProvider} from 'sentry/views/profiling/profileGroupProvider';
  48. import {ProfileContext, ProfilesProvider} from 'sentry/views/profiling/profilesProvider';
  49. import TraceDetailsRouting from '../traceDetails/TraceDetailsRouting';
  50. import {transactionSummaryRouteWithQuery} from '../transactionSummary/utils';
  51. import {getSelectedProjectPlatforms} from '../utils';
  52. import EventMetas from './eventMetas';
  53. import FinishSetupAlert from './finishSetupAlert';
  54. type Props = Pick<RouteComponentProps<{eventSlug: string}, {}>, 'params' | 'location'> &
  55. WithRouteAnalyticsProps & {
  56. eventSlug: string;
  57. organization: Organization;
  58. projects: Project[];
  59. };
  60. function EventDetailsContent(props: Props) {
  61. const [isSidebarVisible, setIsSidebarVisible] = useState<boolean>(true);
  62. const projectId = props.eventSlug.split(':')[0];
  63. const {organization, eventSlug, location} = props;
  64. const {
  65. data: event,
  66. isLoading,
  67. error,
  68. } = useApiQuery<Event>(
  69. [`/organizations/${organization.slug}/events/${eventSlug}/`],
  70. {staleTime: 2 * 60 * 1000} // 2 minutes in milliseonds
  71. );
  72. useEffect(() => {
  73. if (event) {
  74. const {projects} = props;
  75. props.setEventNames(
  76. 'performance.event_details',
  77. 'Performance: Opened Event Details'
  78. );
  79. props.setRouteAnalyticsParams({
  80. event_type: event?.type,
  81. project_platforms: getSelectedProjectPlatforms(location, projects),
  82. ...getAnalyticsDataForEvent(event),
  83. });
  84. }
  85. }, [event, props, location]);
  86. const generateTagUrl = (tag: EventTag) => {
  87. if (!event) {
  88. return '';
  89. }
  90. const query = decodeScalar(location.query.query, '');
  91. const newQuery = {
  92. ...location.query,
  93. query: appendTagCondition(query, formatTagKey(tag.key), tag.value),
  94. };
  95. return transactionSummaryRouteWithQuery({
  96. orgSlug: organization.slug,
  97. transaction: event.title,
  98. projectID: event.projectID,
  99. query: newQuery,
  100. });
  101. };
  102. function renderContent(transaction: Event) {
  103. const transactionName = transaction.title;
  104. const query = decodeScalar(location.query.query, '');
  105. const eventJsonUrl = `/api/0/projects/${organization.slug}/${projectId}/events/${transaction.eventID}/json/`;
  106. const traceId = transaction.contexts?.trace?.trace_id ?? '';
  107. const {start, end} = getTraceTimeRangeFromEvent(transaction);
  108. const hasProfilingFeature = organization.features.includes('profiling');
  109. const profileId =
  110. (transaction as EventTransaction).contexts?.profile?.profile_id ?? null;
  111. const originatingUrl = getUrlFromEvent(transaction);
  112. return (
  113. <TraceMetaQuery
  114. location={location}
  115. orgSlug={organization.slug}
  116. traceId={traceId}
  117. start={start}
  118. end={end}
  119. >
  120. {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. />
  243. </ProfileGroupProvider>
  244. )}
  245. </ProfileContext.Consumer>
  246. </ProfilesProvider>
  247. ) : (
  248. <BorderlessEventEntries
  249. organization={organization}
  250. event={event}
  251. project={_projects[0] as Project}
  252. showTagSummary={false}
  253. />
  254. )}
  255. </QuickTraceContext.Provider>
  256. </SpanEntryContext.Provider>
  257. )}
  258. </Projects>
  259. </Layout.Main>
  260. {isSidebarVisible && (
  261. <Layout.Side>
  262. {results === undefined && (
  263. <Fragment>
  264. <EventMetadata
  265. event={transaction}
  266. organization={organization}
  267. projectId={projectId}
  268. />
  269. <RootSpanStatus event={transaction} />
  270. </Fragment>
  271. )}
  272. <EventVitals event={transaction} />
  273. <EventCustomPerformanceMetrics
  274. event={transaction}
  275. location={location}
  276. organization={organization}
  277. source={EventDetailPageSource.PERFORMANCE}
  278. />
  279. <TagsTable
  280. event={transaction}
  281. query={query}
  282. generateUrl={generateTagUrl}
  283. />
  284. </Layout.Side>
  285. )}
  286. </Layout.Body>
  287. </TransactionProfileIdProvider>
  288. )}
  289. </QuickTraceQuery>
  290. )}
  291. </TraceMetaQuery>
  292. );
  293. }
  294. function renderBody() {
  295. if (!event) {
  296. return <NotFound />;
  297. }
  298. const isSampleTransaction = event.tags.some(
  299. tag => tag.key === 'sample_event' && tag.value === 'yes'
  300. );
  301. return (
  302. <TraceDetailsRouting event={event}>
  303. <Fragment>
  304. {isSampleTransaction && (
  305. <FinishSetupAlert organization={organization} projectId={projectId} />
  306. )}
  307. {renderContent(event)}
  308. </Fragment>
  309. </TraceDetailsRouting>
  310. );
  311. }
  312. if (isLoading) {
  313. return <LoadingIndicator />;
  314. }
  315. if (error) {
  316. const notFound = error.status === 404;
  317. const permissionDenied = error.status === 403;
  318. if (notFound) {
  319. return <NotFound />;
  320. }
  321. if (permissionDenied) {
  322. return (
  323. <LoadingError message={t('You do not have permission to view that event.')} />
  324. );
  325. }
  326. return (
  327. <Alert type="error" showIcon>
  328. {error.message}
  329. </Alert>
  330. );
  331. }
  332. return (
  333. <SentryDocumentTitle
  334. title={t('Performance — Event Details')}
  335. orgSlug={organization.slug}
  336. >
  337. {renderBody() as React.ReactChild}
  338. </SentryDocumentTitle>
  339. );
  340. }
  341. // We can't use theme.overflowEllipsis so that width isn't set to 100%
  342. // since button withn a link has to immediately follow the text in the title
  343. const EventTitle = styled('div')`
  344. display: block;
  345. white-space: nowrap;
  346. overflow: hidden;
  347. text-overflow: ellipsis;
  348. `;
  349. export default withRouteAnalytics(EventDetailsContent);