content.tsx 14 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 {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. skipLight={false}
  126. >
  127. {results => (
  128. <TransactionProfileIdProvider
  129. projectId={transaction.projectID}
  130. transactionId={
  131. transaction.type === 'transaction' ? transaction.id : undefined
  132. }
  133. timestamp={transaction.dateReceived}
  134. >
  135. <Layout.Header>
  136. <Layout.HeaderContent>
  137. <Breadcrumb
  138. organization={organization}
  139. location={location}
  140. transaction={{
  141. project: transaction.projectID,
  142. name: transactionName,
  143. }}
  144. eventSlug={eventSlug}
  145. />
  146. <Layout.Title data-test-id="event-header">
  147. <Tooltip showOnlyOnOverflow skipWrapper title={transactionName}>
  148. <EventTitle>{transaction.title}</EventTitle>
  149. </Tooltip>
  150. {originatingUrl && (
  151. <Button
  152. aria-label={t('Go to originating URL')}
  153. size="zero"
  154. icon={<IconOpen />}
  155. href={originatingUrl}
  156. external
  157. translucentBorder
  158. borderless
  159. />
  160. )}
  161. </Layout.Title>
  162. </Layout.HeaderContent>
  163. <Layout.HeaderActions>
  164. <ButtonBar gap={1}>
  165. <Button
  166. size="sm"
  167. onClick={() => setIsSidebarVisible(prev => !prev)}
  168. >
  169. {isSidebarVisible ? 'Hide Details' : 'Show Details'}
  170. </Button>
  171. {results && (
  172. <Button
  173. size="sm"
  174. icon={<IconOpen />}
  175. href={eventJsonUrl}
  176. external
  177. >
  178. {t('JSON')} (<FileSize bytes={transaction.size} />)
  179. </Button>
  180. )}
  181. {hasProfilingFeature && isTransaction(transaction) && (
  182. <TransactionToProfileButton
  183. event={transaction}
  184. projectSlug={projectId}
  185. />
  186. )}
  187. </ButtonBar>
  188. </Layout.HeaderActions>
  189. </Layout.Header>
  190. <Layout.Body>
  191. {results && (
  192. <Layout.Main fullWidth>
  193. <EventMetas
  194. quickTrace={results}
  195. meta={metaResults?.meta ?? null}
  196. event={transaction}
  197. organization={organization}
  198. projectId={projectId}
  199. location={location}
  200. errorDest="issue"
  201. transactionDest="performance"
  202. />
  203. </Layout.Main>
  204. )}
  205. <Layout.Main fullWidth={!isSidebarVisible}>
  206. <Projects orgId={organization.slug} slugs={[projectId]}>
  207. {({projects: _projects}) => (
  208. <SpanEntryContext.Provider
  209. value={{
  210. getViewChildTransactionTarget: childTransactionProps => {
  211. return getTransactionDetailsUrl(
  212. organization.slug,
  213. childTransactionProps.eventSlug,
  214. childTransactionProps.transaction,
  215. location.query
  216. );
  217. },
  218. }}
  219. >
  220. <QuickTraceContext.Provider value={results}>
  221. {hasProfilingFeature ? (
  222. <ProfilesProvider
  223. orgSlug={organization.slug}
  224. projectSlug={projectId}
  225. profileId={profileId || ''}
  226. >
  227. <ProfileContext.Consumer>
  228. {profiles => (
  229. <ProfileGroupProvider
  230. type="flamechart"
  231. input={
  232. profiles?.type === 'resolved'
  233. ? profiles.data
  234. : null
  235. }
  236. traceID={profileId || ''}
  237. >
  238. <BorderlessEventEntries
  239. organization={organization}
  240. event={event}
  241. project={_projects[0] as Project}
  242. showTagSummary={false}
  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. />
  255. )}
  256. </QuickTraceContext.Provider>
  257. </SpanEntryContext.Provider>
  258. )}
  259. </Projects>
  260. </Layout.Main>
  261. {isSidebarVisible && (
  262. <Layout.Side>
  263. {results === undefined && (
  264. <Fragment>
  265. <EventMetadata
  266. event={transaction}
  267. organization={organization}
  268. projectId={projectId}
  269. />
  270. <RootSpanStatus event={transaction} />
  271. </Fragment>
  272. )}
  273. <EventVitals event={transaction} />
  274. <EventCustomPerformanceMetrics
  275. event={transaction}
  276. location={location}
  277. organization={organization}
  278. source={EventDetailPageSource.PERFORMANCE}
  279. />
  280. <TagsTable
  281. event={transaction}
  282. query={query}
  283. generateUrl={generateTagUrl}
  284. />
  285. </Layout.Side>
  286. )}
  287. </Layout.Body>
  288. </TransactionProfileIdProvider>
  289. )}
  290. </QuickTraceQuery>
  291. )}
  292. </TraceMetaQuery>
  293. );
  294. }
  295. function renderBody() {
  296. if (!event) {
  297. return <NotFound />;
  298. }
  299. const isSampleTransaction = event.tags.some(
  300. tag => tag.key === 'sample_event' && tag.value === 'yes'
  301. );
  302. return (
  303. <TraceDetailsRouting event={event}>
  304. <Fragment>
  305. {isSampleTransaction && (
  306. <FinishSetupAlert organization={organization} projectId={projectId} />
  307. )}
  308. {renderContent(event)}
  309. </Fragment>
  310. </TraceDetailsRouting>
  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);