content.tsx 18 KB

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