frontendOverviewPage.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. import styled from '@emotion/styled';
  2. import Feature from 'sentry/components/acl/feature';
  3. import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import {NoAccess} from 'sentry/components/noAccess';
  7. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  8. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  9. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  10. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  11. import TransactionNameSearchBar from 'sentry/components/performance/searchBar';
  12. import * as TeamKeyTransactionManager from 'sentry/components/performance/teamKeyTransactionsManager';
  13. import {tct} from 'sentry/locale';
  14. import type {Project} from 'sentry/types/project';
  15. import {trackAnalytics} from 'sentry/utils/analytics';
  16. import {
  17. canUseMetricsData,
  18. useMEPSettingContext,
  19. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  20. import {PageAlert, usePageAlert} from 'sentry/utils/performance/contexts/pageAlert';
  21. import {PerformanceDisplayProvider} from 'sentry/utils/performance/contexts/performanceDisplayContext';
  22. import {getSelectedProjectList} from 'sentry/utils/project/useSelectedProjectsHaveField';
  23. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  24. import {useLocation} from 'sentry/utils/useLocation';
  25. import {useNavigate} from 'sentry/utils/useNavigate';
  26. import useOrganization from 'sentry/utils/useOrganization';
  27. import usePageFilters from 'sentry/utils/usePageFilters';
  28. import useProjects from 'sentry/utils/useProjects';
  29. import {useUserTeams} from 'sentry/utils/useUserTeams';
  30. import * as ModuleLayout from 'sentry/views/insights/common/components/moduleLayout';
  31. import {ToolRibbon} from 'sentry/views/insights/common/components/ribbon';
  32. import {ViewTrendsButton} from 'sentry/views/insights/common/components/viewTrendsButton';
  33. import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
  34. import {OVERVIEW_PAGE_ALLOWED_OPS as BACKEND_OVERVIEW_PAGE_ALLOWED_OPS} from 'sentry/views/insights/pages/backend/settings';
  35. import {DomainOverviewPageProviders} from 'sentry/views/insights/pages/domainOverviewPageProviders';
  36. import {FrontendHeader} from 'sentry/views/insights/pages/frontend/frontendPageHeader';
  37. import {
  38. FRONTEND_LANDING_TITLE,
  39. FRONTEND_PLATFORMS,
  40. OVERVIEW_PAGE_ALLOWED_OPS,
  41. } from 'sentry/views/insights/pages/frontend/settings';
  42. import {
  43. generateFrontendOtherPerformanceEventView,
  44. USER_MISERY_TOOLTIP,
  45. } from 'sentry/views/performance/data';
  46. import {
  47. DoubleChartRow,
  48. TripleChartRow,
  49. } from 'sentry/views/performance/landing/widgets/components/widgetChartRow';
  50. import {filterAllowedChartsMetrics} from 'sentry/views/performance/landing/widgets/utils';
  51. import {PerformanceWidgetSetting} from 'sentry/views/performance/landing/widgets/widgetDefinitions';
  52. import {LegacyOnboarding} from 'sentry/views/performance/onboarding';
  53. import Table from 'sentry/views/performance/table';
  54. import {
  55. getTransactionSearchQuery,
  56. ProjectPerformanceType,
  57. } from 'sentry/views/performance/utils';
  58. const DURATION_TOOLTIP = tct(
  59. 'A heuristic measuring when a pageload or navigation completes. Based on whether the initial load of the webpage has become idle. [link:Learn more.]',
  60. {
  61. link: (
  62. <ExternalLink href="https://docs.sentry.io/platforms/javascript/tracing/instrumentation/automatic-instrumentation/#idletimeout" />
  63. ),
  64. }
  65. );
  66. export const FRONTEND_COLUMN_TITLES = [
  67. {title: 'transaction'},
  68. {title: 'operation'},
  69. {title: 'project'},
  70. {title: 'tpm'},
  71. {title: 'p50()', tooltip: DURATION_TOOLTIP},
  72. {title: 'p75()', tooltip: DURATION_TOOLTIP},
  73. {title: 'p95()', tooltip: DURATION_TOOLTIP},
  74. {title: 'users'},
  75. {title: 'user misery', tooltip: USER_MISERY_TOOLTIP},
  76. ];
  77. function FrontendOverviewPage() {
  78. const organization = useOrganization();
  79. const location = useLocation();
  80. const {setPageError} = usePageAlert();
  81. const {projects} = useProjects();
  82. const onboardingProject = useOnboardingProject();
  83. const navigate = useNavigate();
  84. const {teams} = useUserTeams();
  85. const mepSetting = useMEPSettingContext();
  86. const {selection} = usePageFilters();
  87. const withStaticFilters = canUseMetricsData(organization);
  88. const eventView = generateFrontendOtherPerformanceEventView(
  89. location,
  90. withStaticFilters
  91. );
  92. const searchBarEventView = eventView.clone();
  93. const sharedProps = {eventView, location, organization, withStaticFilters};
  94. // TODO - this should come from MetricsField / EAP fields
  95. eventView.fields = [
  96. {field: 'team_key_transaction'},
  97. {field: 'transaction'},
  98. {field: 'transaction.op'},
  99. {field: 'project'},
  100. {field: 'tpm()'},
  101. {field: 'p50(transaction.duration)'},
  102. {field: 'p75(transaction.duration)'},
  103. {field: 'p95(transaction.duration)'},
  104. {field: 'count_unique(user)'},
  105. {field: 'count_miserable(user)'},
  106. {field: 'user_misery()'},
  107. ].map(field => ({...field, width: COL_WIDTH_UNDEFINED}));
  108. const doubleChartRowEventView = eventView.clone(); // some of the double chart rows rely on span metrics, so they can't be queried the same way
  109. const selectedFrontendProjects: Project[] = getSelectedProjectList(
  110. selection.projects,
  111. projects
  112. ).filter((project): project is Project =>
  113. Boolean(project?.platform && FRONTEND_PLATFORMS.includes(project.platform))
  114. );
  115. const existingQuery = new MutableSearch(eventView.query);
  116. // TODO - this query is getting complicated, once were on EAP, we should consider moving this to the backend
  117. existingQuery.addOp('(');
  118. existingQuery.addDisjunctionFilterValues('transaction.op', OVERVIEW_PAGE_ALLOWED_OPS);
  119. // add disjunction filter creates a very long query as it seperates conditions with OR, project ids are numeric with no spaces, so we can use a comma seperated list
  120. if (selectedFrontendProjects.length > 0) {
  121. existingQuery.addOp('OR');
  122. existingQuery.addFilterValue(
  123. 'project.id',
  124. `[${selectedFrontendProjects.map(({id}) => id).join(',')}]`
  125. );
  126. }
  127. existingQuery.addOp(')');
  128. existingQuery.addFilterValues('!transaction.op', BACKEND_OVERVIEW_PAGE_ALLOWED_OPS);
  129. eventView.query = existingQuery.formatString();
  130. const showOnboarding = onboardingProject !== undefined;
  131. const doubleChartRowCharts = [
  132. PerformanceWidgetSetting.SLOW_HTTP_OPS,
  133. PerformanceWidgetSetting.SLOW_RESOURCE_OPS,
  134. ];
  135. const tripleChartRowCharts = filterAllowedChartsMetrics(
  136. organization,
  137. [
  138. PerformanceWidgetSetting.TPM_AREA,
  139. PerformanceWidgetSetting.DURATION_HISTOGRAM,
  140. PerformanceWidgetSetting.P50_DURATION_AREA,
  141. PerformanceWidgetSetting.P75_DURATION_AREA,
  142. PerformanceWidgetSetting.P95_DURATION_AREA,
  143. PerformanceWidgetSetting.P99_DURATION_AREA,
  144. PerformanceWidgetSetting.FAILURE_RATE_AREA,
  145. ],
  146. mepSetting
  147. );
  148. if (organization.features.includes('insights-initial-modules')) {
  149. doubleChartRowCharts.unshift(PerformanceWidgetSetting.MOST_TIME_CONSUMING_DOMAINS);
  150. doubleChartRowCharts.unshift(PerformanceWidgetSetting.MOST_TIME_CONSUMING_RESOURCES);
  151. doubleChartRowCharts.unshift(PerformanceWidgetSetting.HIGHEST_OPPORTUNITY_PAGES);
  152. }
  153. const getFreeTextFromQuery = (query: string) => {
  154. const conditions = new MutableSearch(query);
  155. const transactionValues = conditions.getFilterValues('transaction');
  156. if (transactionValues.length) {
  157. return transactionValues[0];
  158. }
  159. if (conditions.freeText.length > 0) {
  160. // raw text query will be wrapped in wildcards in generatePerformanceEventView
  161. // so no need to wrap it here
  162. return conditions.freeText.join(' ');
  163. }
  164. return '';
  165. };
  166. function handleSearch(searchQuery: string) {
  167. trackAnalytics('performance.domains.frontend.search', {organization});
  168. navigate({
  169. pathname: location.pathname,
  170. query: {
  171. ...location.query,
  172. cursor: undefined,
  173. query: String(searchQuery).trim() || undefined,
  174. isDefaultQuery: false,
  175. },
  176. });
  177. }
  178. const derivedQuery = getTransactionSearchQuery(location, eventView.query);
  179. return (
  180. <Feature
  181. features="performance-view"
  182. organization={organization}
  183. renderDisabled={NoAccess}
  184. >
  185. <FrontendHeader
  186. headerTitle={FRONTEND_LANDING_TITLE}
  187. headerActions={<ViewTrendsButton />}
  188. />
  189. <Layout.Body>
  190. <Layout.Main fullWidth>
  191. <ModuleLayout.Layout>
  192. <ModuleLayout.Full>
  193. <ToolRibbon>
  194. <PageFilterBar condensed>
  195. <ProjectPageFilter />
  196. <EnvironmentPageFilter />
  197. <DatePageFilter />
  198. </PageFilterBar>
  199. {!showOnboarding && (
  200. <StyledTransactionNameSearchBar
  201. organization={organization}
  202. eventView={searchBarEventView}
  203. onSearch={(query: string) => {
  204. handleSearch(query);
  205. }}
  206. query={getFreeTextFromQuery(derivedQuery)!}
  207. />
  208. )}
  209. </ToolRibbon>
  210. </ModuleLayout.Full>
  211. <PageAlert />
  212. <ModuleLayout.Full>
  213. {!showOnboarding && (
  214. <PerformanceDisplayProvider
  215. value={{performanceType: ProjectPerformanceType.FRONTEND_OTHER}}
  216. >
  217. <DoubleChartRow
  218. allowedCharts={doubleChartRowCharts}
  219. {...sharedProps}
  220. eventView={doubleChartRowEventView}
  221. />
  222. <TripleChartRow allowedCharts={tripleChartRowCharts} {...sharedProps} />
  223. <TeamKeyTransactionManager.Provider
  224. organization={organization}
  225. teams={teams}
  226. selectedTeams={['myteams']}
  227. selectedProjects={eventView.project.map(String)}
  228. >
  229. <Table
  230. projects={projects}
  231. columnTitles={FRONTEND_COLUMN_TITLES}
  232. setError={setPageError}
  233. {...sharedProps}
  234. />
  235. </TeamKeyTransactionManager.Provider>
  236. </PerformanceDisplayProvider>
  237. )}
  238. {showOnboarding && (
  239. <LegacyOnboarding
  240. project={onboardingProject}
  241. organization={organization}
  242. />
  243. )}
  244. </ModuleLayout.Full>
  245. </ModuleLayout.Layout>
  246. </Layout.Main>
  247. </Layout.Body>
  248. </Feature>
  249. );
  250. }
  251. function FrontendOverviewPageWithProviders() {
  252. return (
  253. <DomainOverviewPageProviders>
  254. <FrontendOverviewPage />
  255. </DomainOverviewPageProviders>
  256. );
  257. }
  258. const StyledTransactionNameSearchBar = styled(TransactionNameSearchBar)`
  259. flex: 2;
  260. `;
  261. export default FrontendOverviewPageWithProviders;