content.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. import {Fragment} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Location} from 'history';
  5. import omit from 'lodash/omit';
  6. import Feature from 'sentry/components/acl/feature';
  7. import DatePageFilter from 'sentry/components/datePageFilter';
  8. import TransactionsList, {
  9. DropdownOption,
  10. } from 'sentry/components/discover/transactionsList';
  11. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  12. import SearchBar from 'sentry/components/events/searchBar';
  13. import * as Layout from 'sentry/components/layouts/thirds';
  14. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  15. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  16. import {MAX_QUERY_LENGTH} from 'sentry/constants';
  17. import {t} from 'sentry/locale';
  18. import space from 'sentry/styles/space';
  19. import {Organization, Project} from 'sentry/types';
  20. import {defined, generateQueryWithTag} from 'sentry/utils';
  21. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  22. import EventView from 'sentry/utils/discover/eventView';
  23. import {
  24. formatTagKey,
  25. getAggregateAlias,
  26. isRelativeSpanOperationBreakdownField,
  27. SPAN_OP_BREAKDOWN_FIELDS,
  28. SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  29. } from 'sentry/utils/discover/fields';
  30. import {QueryError} from 'sentry/utils/discover/genericDiscoverQuery';
  31. import {canUseMetricsData} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  32. import {decodeScalar} from 'sentry/utils/queryString';
  33. import {useRoutes} from 'sentry/utils/useRoutes';
  34. import withProjects from 'sentry/utils/withProjects';
  35. import {Actions, updateQuery} from 'sentry/views/eventsV2/table/cellAction';
  36. import {TableColumn} from 'sentry/views/eventsV2/table/types';
  37. import Tags from 'sentry/views/eventsV2/tags';
  38. import {
  39. PERCENTILE as VITAL_PERCENTILE,
  40. VITAL_GROUPS,
  41. } from 'sentry/views/performance/transactionSummary/transactionVitals/constants';
  42. import {isSummaryViewFrontend, isSummaryViewFrontendPageLoad} from '../../utils';
  43. import Filter, {
  44. decodeFilterFromLocation,
  45. filterToField,
  46. filterToSearchConditions,
  47. SpanOperationBreakdownFilter,
  48. } from '../filter';
  49. import {
  50. generateReplayLink,
  51. generateTraceLink,
  52. generateTransactionLink,
  53. normalizeSearchConditions,
  54. SidebarSpacer,
  55. TransactionFilterOptions,
  56. } from '../utils';
  57. import TransactionSummaryCharts from './charts';
  58. import RelatedIssues from './relatedIssues';
  59. import SidebarCharts from './sidebarCharts';
  60. import SidebarMEPCharts from './sidebarMEPCharts';
  61. import StatusBreakdown from './statusBreakdown';
  62. import SuspectSpans from './suspectSpans';
  63. import {TagExplorer} from './tagExplorer';
  64. import UserStats from './userStats';
  65. type Props = {
  66. error: QueryError | null;
  67. eventView: EventView;
  68. isLoading: boolean;
  69. location: Location;
  70. onChangeFilter: (newFilter: SpanOperationBreakdownFilter) => void;
  71. organization: Organization;
  72. projectId: string;
  73. projects: Project[];
  74. spanOperationBreakdownFilter: SpanOperationBreakdownFilter;
  75. totalValues: Record<string, number> | null;
  76. transactionName: string;
  77. };
  78. function SummaryContent({
  79. eventView,
  80. location,
  81. totalValues,
  82. spanOperationBreakdownFilter,
  83. organization,
  84. projects,
  85. isLoading,
  86. error,
  87. projectId,
  88. transactionName,
  89. onChangeFilter,
  90. }: Props) {
  91. const routes = useRoutes();
  92. const useAggregateAlias = !organization.features.includes(
  93. 'performance-frontend-use-events-endpoint'
  94. );
  95. function handleSearch(query: string) {
  96. const queryParams = normalizeDateTimeParams({
  97. ...(location.query || {}),
  98. query,
  99. });
  100. // do not propagate pagination when making a new search
  101. const searchQueryParams = omit(queryParams, 'cursor');
  102. browserHistory.push({
  103. pathname: location.pathname,
  104. query: searchQueryParams,
  105. });
  106. }
  107. function generateTagUrl(key: string, value: string) {
  108. const query = generateQueryWithTag(location.query, {key: formatTagKey(key), value});
  109. return {
  110. ...location,
  111. query,
  112. };
  113. }
  114. function handleCellAction(column: TableColumn<React.ReactText>) {
  115. return (action: Actions, value: React.ReactText) => {
  116. const searchConditions = normalizeSearchConditions(eventView.query);
  117. updateQuery(searchConditions, action, column, value);
  118. browserHistory.push({
  119. pathname: location.pathname,
  120. query: {
  121. ...location.query,
  122. cursor: undefined,
  123. query: searchConditions.formatString(),
  124. },
  125. });
  126. };
  127. }
  128. function handleTransactionsListSortChange(value: string) {
  129. const target = {
  130. pathname: location.pathname,
  131. query: {...location.query, showTransactions: value, transactionCursor: undefined},
  132. };
  133. browserHistory.push(target);
  134. }
  135. function handleAllEventsViewClick() {
  136. trackAnalyticsEvent({
  137. eventKey: 'performance_views.summary.view_in_transaction_events',
  138. eventName: 'Performance Views: View in All Events from Transaction Summary',
  139. organization_id: parseInt(organization.id, 10),
  140. });
  141. }
  142. function generateEventView(
  143. transactionsListEventView: EventView,
  144. transactionsListTitles: string[]
  145. ) {
  146. const {selected} = getTransactionsListSort(location, {
  147. p95: (useAggregateAlias ? totalValues?.p95 : totalValues?.['p95()']) ?? 0,
  148. spanOperationBreakdownFilter,
  149. });
  150. const sortedEventView = transactionsListEventView.withSorts([selected.sort]);
  151. if (spanOperationBreakdownFilter === SpanOperationBreakdownFilter.None) {
  152. const fields = [
  153. // Remove the extra field columns
  154. ...sortedEventView.fields.slice(0, transactionsListTitles.length),
  155. ];
  156. // omit "Operation Duration" column
  157. sortedEventView.fields = fields.filter(({field}) => {
  158. return !isRelativeSpanOperationBreakdownField(field);
  159. });
  160. }
  161. return sortedEventView;
  162. }
  163. const hasPerformanceChartInterpolation = organization.features.includes(
  164. 'performance-chart-interpolation'
  165. );
  166. const query = decodeScalar(location.query.query, '');
  167. const totalCount =
  168. totalValues === null
  169. ? null
  170. : useAggregateAlias
  171. ? totalValues.count
  172. : totalValues['count()'];
  173. // NOTE: This is not a robust check for whether or not a transaction is a front end
  174. // transaction, however it will suffice for now.
  175. const hasWebVitals =
  176. isSummaryViewFrontendPageLoad(eventView, projects) ||
  177. (totalValues !== null &&
  178. VITAL_GROUPS.some(group =>
  179. group.vitals.some(vital => {
  180. const functionName = `percentile(${vital},${VITAL_PERCENTILE})`;
  181. const field = useAggregateAlias
  182. ? getAggregateAlias(functionName)
  183. : functionName;
  184. return Number.isFinite(totalValues[field]);
  185. })
  186. ));
  187. const isFrontendView = isSummaryViewFrontend(eventView, projects);
  188. const transactionsListTitles = [
  189. t('event id'),
  190. t('user'),
  191. t('total duration'),
  192. t('trace id'),
  193. t('timestamp'),
  194. ];
  195. if (organization.features.includes('session-replay-ui')) {
  196. transactionsListTitles.push(t('replay'));
  197. }
  198. let transactionsListEventView = eventView.clone();
  199. // update search conditions
  200. const spanOperationBreakdownConditions = filterToSearchConditions(
  201. spanOperationBreakdownFilter,
  202. location
  203. );
  204. if (spanOperationBreakdownConditions) {
  205. eventView = eventView.clone();
  206. eventView.query = `${eventView.query} ${spanOperationBreakdownConditions}`.trim();
  207. transactionsListEventView = eventView.clone();
  208. }
  209. // update header titles of transactions list
  210. const operationDurationTableTitle =
  211. spanOperationBreakdownFilter === SpanOperationBreakdownFilter.None
  212. ? t('operation duration')
  213. : `${spanOperationBreakdownFilter} duration`;
  214. // add ops breakdown duration column as the 3rd column
  215. transactionsListTitles.splice(2, 0, operationDurationTableTitle);
  216. // span_ops_breakdown.relative is a preserved name and a marker for the associated
  217. // field renderer to be used to generate the relative ops breakdown
  218. let durationField = SPAN_OP_RELATIVE_BREAKDOWN_FIELD;
  219. if (spanOperationBreakdownFilter !== SpanOperationBreakdownFilter.None) {
  220. durationField = filterToField(spanOperationBreakdownFilter)!;
  221. }
  222. const fields = [...transactionsListEventView.fields];
  223. // add ops breakdown duration column as the 3rd column
  224. fields.splice(2, 0, {field: durationField});
  225. if (spanOperationBreakdownFilter === SpanOperationBreakdownFilter.None) {
  226. fields.push(
  227. ...SPAN_OP_BREAKDOWN_FIELDS.map(field => {
  228. return {field};
  229. })
  230. );
  231. }
  232. transactionsListEventView.fields = fields;
  233. const openAllEventsProps = {
  234. generatePerformanceTransactionEventsView: () => {
  235. const performanceTransactionEventsView = generateEventView(
  236. transactionsListEventView,
  237. transactionsListTitles
  238. );
  239. performanceTransactionEventsView.query = query;
  240. return performanceTransactionEventsView;
  241. },
  242. handleOpenAllEventsClick: handleAllEventsViewClick,
  243. };
  244. const isUsingMetrics = canUseMetricsData(organization);
  245. return (
  246. <Fragment>
  247. <Layout.Main>
  248. <FilterActions>
  249. <Filter
  250. organization={organization}
  251. currentFilter={spanOperationBreakdownFilter}
  252. onChangeFilter={onChangeFilter}
  253. />
  254. <PageFilterBar condensed>
  255. <EnvironmentPageFilter />
  256. <DatePageFilter alignDropdown="left" />
  257. </PageFilterBar>
  258. <StyledSearchBar
  259. searchSource="transaction_summary"
  260. organization={organization}
  261. projectIds={eventView.project}
  262. query={query}
  263. fields={eventView.fields}
  264. onSearch={handleSearch}
  265. maxQueryLength={MAX_QUERY_LENGTH}
  266. />
  267. </FilterActions>
  268. <TransactionSummaryCharts
  269. organization={organization}
  270. location={location}
  271. eventView={eventView}
  272. totalValues={totalCount}
  273. currentFilter={spanOperationBreakdownFilter}
  274. withoutZerofill={hasPerformanceChartInterpolation}
  275. />
  276. <TransactionsList
  277. location={location}
  278. organization={organization}
  279. eventView={transactionsListEventView}
  280. {...openAllEventsProps}
  281. showTransactions={
  282. decodeScalar(
  283. location.query.showTransactions,
  284. TransactionFilterOptions.SLOW
  285. ) as TransactionFilterOptions
  286. }
  287. breakdown={decodeFilterFromLocation(location)}
  288. titles={transactionsListTitles}
  289. handleDropdownChange={handleTransactionsListSortChange}
  290. generateLink={{
  291. id: generateTransactionLink(transactionName),
  292. trace: generateTraceLink(eventView.normalizeDateSelection(location)),
  293. replayId: generateReplayLink(routes),
  294. }}
  295. handleCellAction={handleCellAction}
  296. {...getTransactionsListSort(location, {
  297. p95: (useAggregateAlias ? totalValues?.p95 : totalValues?.['p95()']) ?? 0,
  298. spanOperationBreakdownFilter,
  299. })}
  300. forceLoading={isLoading}
  301. />
  302. <Feature
  303. requireAll={false}
  304. features={['organizations:performance-suspect-spans-view']}
  305. >
  306. <SuspectSpans
  307. location={location}
  308. organization={organization}
  309. eventView={eventView}
  310. totals={
  311. defined(totalValues?.['count()'])
  312. ? {'count()': totalValues!['count()']}
  313. : null
  314. }
  315. projectId={projectId}
  316. transactionName={transactionName}
  317. />
  318. </Feature>
  319. <TagExplorer
  320. eventView={eventView}
  321. organization={organization}
  322. location={location}
  323. projects={projects}
  324. transactionName={transactionName}
  325. currentFilter={spanOperationBreakdownFilter}
  326. />
  327. <RelatedIssues
  328. organization={organization}
  329. location={location}
  330. transaction={transactionName}
  331. start={eventView.start}
  332. end={eventView.end}
  333. statsPeriod={eventView.statsPeriod}
  334. />
  335. </Layout.Main>
  336. <Layout.Side>
  337. {(isUsingMetrics ?? null) && (
  338. <Fragment>
  339. <SidebarMEPCharts
  340. organization={organization}
  341. isLoading={isLoading}
  342. error={error}
  343. totals={totalValues}
  344. eventView={eventView}
  345. transactionName={transactionName}
  346. isShowingMetricsEventCount
  347. />
  348. <SidebarSpacer />
  349. </Fragment>
  350. )}
  351. <UserStats
  352. organization={organization}
  353. location={location}
  354. isLoading={isLoading}
  355. hasWebVitals={hasWebVitals}
  356. error={error}
  357. totals={totalValues}
  358. transactionName={transactionName}
  359. eventView={eventView}
  360. />
  361. {!isFrontendView && (
  362. <StatusBreakdown
  363. eventView={eventView}
  364. organization={organization}
  365. location={location}
  366. />
  367. )}
  368. <SidebarSpacer />
  369. {isUsingMetrics ? (
  370. <SidebarMEPCharts
  371. organization={organization}
  372. isLoading={isLoading}
  373. error={error}
  374. totals={totalValues}
  375. eventView={eventView}
  376. transactionName={transactionName}
  377. />
  378. ) : (
  379. <SidebarCharts
  380. organization={organization}
  381. isLoading={isLoading}
  382. error={error}
  383. totals={totalValues}
  384. eventView={eventView}
  385. transactionName={transactionName}
  386. />
  387. )}
  388. <SidebarSpacer />
  389. <Tags
  390. generateUrl={generateTagUrl}
  391. totalValues={totalCount}
  392. eventView={eventView}
  393. organization={organization}
  394. location={location}
  395. />
  396. </Layout.Side>
  397. </Fragment>
  398. );
  399. }
  400. function getFilterOptions({
  401. p95,
  402. spanOperationBreakdownFilter,
  403. }: {
  404. p95: number;
  405. spanOperationBreakdownFilter: SpanOperationBreakdownFilter;
  406. }): DropdownOption[] {
  407. if (spanOperationBreakdownFilter === SpanOperationBreakdownFilter.None) {
  408. return [
  409. {
  410. sort: {kind: 'asc', field: 'transaction.duration'},
  411. value: TransactionFilterOptions.FASTEST,
  412. label: t('Fastest Transactions'),
  413. },
  414. {
  415. query: [['transaction.duration', `<=${p95.toFixed(0)}`]],
  416. sort: {kind: 'desc', field: 'transaction.duration'},
  417. value: TransactionFilterOptions.SLOW,
  418. label: t('Slow Transactions (p95)'),
  419. },
  420. {
  421. sort: {kind: 'desc', field: 'transaction.duration'},
  422. value: TransactionFilterOptions.OUTLIER,
  423. label: t('Outlier Transactions (p100)'),
  424. },
  425. {
  426. sort: {kind: 'desc', field: 'timestamp'},
  427. value: TransactionFilterOptions.RECENT,
  428. label: t('Recent Transactions'),
  429. },
  430. ];
  431. }
  432. const field = filterToField(spanOperationBreakdownFilter)!;
  433. const operationName = spanOperationBreakdownFilter;
  434. return [
  435. {
  436. sort: {kind: 'asc', field},
  437. value: TransactionFilterOptions.FASTEST,
  438. label: t('Fastest %s Operations', operationName),
  439. },
  440. {
  441. query: [['transaction.duration', `<=${p95.toFixed(0)}`]],
  442. sort: {kind: 'desc', field},
  443. value: TransactionFilterOptions.SLOW,
  444. label: t('Slow %s Operations (p95)', operationName),
  445. },
  446. {
  447. sort: {kind: 'desc', field},
  448. value: TransactionFilterOptions.OUTLIER,
  449. label: t('Outlier %s Operations (p100)', operationName),
  450. },
  451. {
  452. sort: {kind: 'desc', field: 'timestamp'},
  453. value: TransactionFilterOptions.RECENT,
  454. label: t('Recent Transactions'),
  455. },
  456. ];
  457. }
  458. function getTransactionsListSort(
  459. location: Location,
  460. options: {p95: number; spanOperationBreakdownFilter: SpanOperationBreakdownFilter}
  461. ): {options: DropdownOption[]; selected: DropdownOption} {
  462. const sortOptions = getFilterOptions(options);
  463. const urlParam = decodeScalar(
  464. location.query.showTransactions,
  465. TransactionFilterOptions.SLOW
  466. );
  467. const selectedSort = sortOptions.find(opt => opt.value === urlParam) || sortOptions[0];
  468. return {selected: selectedSort, options: sortOptions};
  469. }
  470. const FilterActions = styled('div')`
  471. display: grid;
  472. gap: ${space(2)};
  473. margin-bottom: ${space(2)};
  474. @media (min-width: ${p => p.theme.breakpoints.small}) {
  475. grid-template-columns: repeat(2, min-content);
  476. }
  477. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  478. grid-template-columns: auto auto 1fr;
  479. }
  480. `;
  481. const StyledSearchBar = styled(SearchBar)`
  482. @media (min-width: ${p => p.theme.breakpoints.small}) {
  483. order: 1;
  484. grid-column: 1/4;
  485. }
  486. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  487. order: initial;
  488. grid-column: auto;
  489. }
  490. `;
  491. export default withProjects(SummaryContent);