content.tsx 19 KB

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