httpDomainSummaryPage.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'sentry/components/alert';
  4. import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
  5. import FeatureBadge from 'sentry/components/badge/featureBadge';
  6. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  9. import * as Layout from 'sentry/components/layouts/thirds';
  10. import ExternalLink from 'sentry/components/links/externalLink';
  11. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  12. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  13. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  14. import {t, tct} from 'sentry/locale';
  15. import {space} from 'sentry/styles/space';
  16. import {DurationUnit, RateUnit} from 'sentry/utils/discover/fields';
  17. import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  18. import {
  19. EMPTY_OPTION_VALUE,
  20. escapeFilterValue,
  21. MutableSearch,
  22. } from 'sentry/utils/tokenizeSearch';
  23. import useLocationQuery from 'sentry/utils/url/useLocationQuery';
  24. import {useLocation} from 'sentry/utils/useLocation';
  25. import useOrganization from 'sentry/utils/useOrganization';
  26. import useProjects from 'sentry/utils/useProjects';
  27. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  28. import {DurationChart} from 'sentry/views/performance/http/charts/durationChart';
  29. import {ResponseRateChart} from 'sentry/views/performance/http/charts/responseRateChart';
  30. import {ThroughputChart} from 'sentry/views/performance/http/charts/throughputChart';
  31. import {DomainStatusLink} from 'sentry/views/performance/http/components/domainStatusLink';
  32. import {HTTPSamplesPanel} from 'sentry/views/performance/http/httpSamplesPanel';
  33. import {Referrer} from 'sentry/views/performance/http/referrers';
  34. import {
  35. MODULE_TITLE,
  36. NULL_DOMAIN_DESCRIPTION,
  37. RELEASE_LEVEL,
  38. } from 'sentry/views/performance/http/settings';
  39. import {
  40. DomainTransactionsTable,
  41. isAValidSort,
  42. } from 'sentry/views/performance/http/tables/domainTransactionsTable';
  43. import {MetricReadout} from 'sentry/views/performance/metricReadout';
  44. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  45. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  46. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  47. import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';
  48. import {useSpanMetrics} from 'sentry/views/starfish/queries/useDiscover';
  49. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useDiscoverSeries';
  50. import type {SpanMetricsQueryFilters} from 'sentry/views/starfish/types';
  51. import {ModuleName, SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
  52. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  53. import {DataTitles, getThroughputTitle} from 'sentry/views/starfish/views/spans/types';
  54. type Query = {
  55. aggregate?: string;
  56. domain?: string;
  57. };
  58. export function HTTPDomainSummaryPage() {
  59. const location = useLocation<Query>();
  60. const organization = useOrganization();
  61. const {projects} = useProjects();
  62. // TODO: Fetch sort information using `useLocationQuery`
  63. const sortField = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_SORT]);
  64. const sort = decodeSorts(sortField).filter(isAValidSort).at(0) ?? DEFAULT_SORT;
  65. const {domain, project: projectId} = useLocationQuery({
  66. fields: {
  67. project: decodeScalar,
  68. domain: decodeScalar,
  69. },
  70. });
  71. const project = projects.find(p => projectId === p.id);
  72. const filters: SpanMetricsQueryFilters = {
  73. 'span.module': ModuleName.HTTP,
  74. 'span.domain': domain === '' ? EMPTY_OPTION_VALUE : escapeFilterValue(domain),
  75. };
  76. const cursor = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_CURSOR]);
  77. const {data: domainMetrics, isLoading: areDomainMetricsLoading} = useSpanMetrics(
  78. {
  79. search: MutableSearch.fromQueryObject(filters),
  80. fields: [
  81. `${SpanFunction.SPM}()`,
  82. `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
  83. `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
  84. 'http_response_rate(3)',
  85. 'http_response_rate(4)',
  86. 'http_response_rate(5)',
  87. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  88. ],
  89. },
  90. Referrer.DOMAIN_SUMMARY_METRICS_RIBBON
  91. );
  92. const {
  93. isLoading: isThroughputDataLoading,
  94. data: throughputData,
  95. error: throughputError,
  96. } = useSpanMetricsSeries(
  97. {
  98. search: MutableSearch.fromQueryObject(filters),
  99. yAxis: ['spm()'],
  100. },
  101. Referrer.DOMAIN_SUMMARY_THROUGHPUT_CHART
  102. );
  103. const {
  104. isLoading: isDurationDataLoading,
  105. data: durationData,
  106. error: durationError,
  107. } = useSpanMetricsSeries(
  108. {
  109. search: MutableSearch.fromQueryObject(filters),
  110. yAxis: [`avg(${SpanMetricsField.SPAN_SELF_TIME})`],
  111. },
  112. Referrer.DOMAIN_SUMMARY_DURATION_CHART
  113. );
  114. const {
  115. isLoading: isResponseCodeDataLoading,
  116. data: responseCodeData,
  117. error: responseCodeError,
  118. } = useSpanMetricsSeries(
  119. {
  120. search: MutableSearch.fromQueryObject(filters),
  121. yAxis: ['http_response_rate(3)', 'http_response_rate(4)', 'http_response_rate(5)'],
  122. },
  123. Referrer.DOMAIN_SUMMARY_RESPONSE_CODE_CHART
  124. );
  125. const {
  126. isLoading: isTransactionsListLoading,
  127. data: transactionsList,
  128. meta: transactionsListMeta,
  129. error: transactionsListError,
  130. pageLinks: transactionsListPageLinks,
  131. } = useSpanMetrics(
  132. {
  133. search: MutableSearch.fromQueryObject(filters),
  134. fields: [
  135. 'project.id',
  136. 'transaction',
  137. 'transaction.method',
  138. 'spm()',
  139. 'http_response_rate(3)',
  140. 'http_response_rate(4)',
  141. 'http_response_rate(5)',
  142. 'avg(span.self_time)',
  143. 'sum(span.self_time)',
  144. 'time_spent_percentage()',
  145. ],
  146. sorts: [sort],
  147. limit: TRANSACTIONS_TABLE_ROW_COUNT,
  148. cursor,
  149. },
  150. Referrer.DOMAIN_SUMMARY_TRANSACTIONS_LIST
  151. );
  152. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  153. return (
  154. <React.Fragment>
  155. <Layout.Header>
  156. <Layout.HeaderContent>
  157. <Breadcrumbs
  158. crumbs={[
  159. {
  160. label: 'Performance',
  161. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  162. preservePageFilters: true,
  163. },
  164. {
  165. label: MODULE_TITLE,
  166. to: normalizeUrl(`/organizations/${organization.slug}/performance/http`),
  167. preservePageFilters: true,
  168. },
  169. {
  170. label: 'Domain Summary',
  171. },
  172. ]}
  173. />
  174. <Layout.Title>
  175. {project && <ProjectAvatar project={project} size={36} />}
  176. {domain || NULL_DOMAIN_DESCRIPTION}
  177. <DomainStatusLink domain={domain} />
  178. <FeatureBadge type={RELEASE_LEVEL} />
  179. </Layout.Title>
  180. </Layout.HeaderContent>
  181. <Layout.HeaderActions>
  182. <ButtonBar gap={1}>
  183. <FeedbackWidgetButton />
  184. </ButtonBar>
  185. </Layout.HeaderActions>
  186. </Layout.Header>
  187. <Layout.Body>
  188. <Layout.Main fullWidth>
  189. {domain === '' && (
  190. <Alert type="info">
  191. {tct(
  192. '"Unknown Domain" entries can be caused by instrumentation errors. Please refer to our [link] for more information.',
  193. {
  194. link: (
  195. <ExternalLink href="https://docs.sentry.io/product/performance/requests/">
  196. documentation
  197. </ExternalLink>
  198. ),
  199. }
  200. )}
  201. </Alert>
  202. )}
  203. <ModuleLayout.Layout>
  204. <ModuleLayout.Full>
  205. <HeaderContainer>
  206. <PageFilterBar condensed>
  207. <EnvironmentPageFilter />
  208. <DatePageFilter />
  209. </PageFilterBar>
  210. <MetricsRibbon>
  211. <MetricReadout
  212. title={getThroughputTitle('http')}
  213. value={domainMetrics?.[0]?.[`${SpanFunction.SPM}()`]}
  214. unit={RateUnit.PER_MINUTE}
  215. isLoading={areDomainMetricsLoading}
  216. />
  217. <MetricReadout
  218. title={DataTitles.avg}
  219. value={
  220. domainMetrics?.[0]?.[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]
  221. }
  222. unit={DurationUnit.MILLISECOND}
  223. isLoading={areDomainMetricsLoading}
  224. />
  225. <MetricReadout
  226. title={t('3XXs')}
  227. value={domainMetrics?.[0]?.[`http_response_rate(3)`]}
  228. unit="percentage"
  229. isLoading={areDomainMetricsLoading}
  230. />
  231. <MetricReadout
  232. title={t('4XXs')}
  233. value={domainMetrics?.[0]?.[`http_response_rate(4)`]}
  234. unit="percentage"
  235. isLoading={areDomainMetricsLoading}
  236. />
  237. <MetricReadout
  238. title={t('5XXs')}
  239. value={domainMetrics?.[0]?.[`http_response_rate(5)`]}
  240. unit="percentage"
  241. isLoading={areDomainMetricsLoading}
  242. />
  243. <MetricReadout
  244. title={DataTitles.timeSpent}
  245. value={domainMetrics?.[0]?.['sum(span.self_time)']}
  246. unit={DurationUnit.MILLISECOND}
  247. tooltip={getTimeSpentExplanation(
  248. domainMetrics?.[0]?.['time_spent_percentage()'],
  249. 'http'
  250. )}
  251. isLoading={areDomainMetricsLoading}
  252. />
  253. </MetricsRibbon>
  254. </HeaderContainer>
  255. </ModuleLayout.Full>
  256. <ModuleLayout.Third>
  257. <ThroughputChart
  258. series={throughputData['spm()']}
  259. isLoading={isThroughputDataLoading}
  260. error={throughputError}
  261. />
  262. </ModuleLayout.Third>
  263. <ModuleLayout.Third>
  264. <DurationChart
  265. series={[durationData[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]]}
  266. isLoading={isDurationDataLoading}
  267. error={durationError}
  268. />
  269. </ModuleLayout.Third>
  270. <ModuleLayout.Third>
  271. <ResponseRateChart
  272. series={[
  273. {
  274. ...responseCodeData[`http_response_rate(3)`],
  275. seriesName: t('3XX'),
  276. },
  277. {
  278. ...responseCodeData[`http_response_rate(4)`],
  279. seriesName: t('4XX'),
  280. },
  281. {
  282. ...responseCodeData[`http_response_rate(5)`],
  283. seriesName: t('5XX'),
  284. },
  285. ]}
  286. isLoading={isResponseCodeDataLoading}
  287. error={responseCodeError}
  288. />
  289. </ModuleLayout.Third>
  290. <ModuleLayout.Full>
  291. <DomainTransactionsTable
  292. domain={domain}
  293. data={transactionsList}
  294. error={transactionsListError}
  295. isLoading={isTransactionsListLoading}
  296. meta={transactionsListMeta}
  297. pageLinks={transactionsListPageLinks}
  298. sort={sort}
  299. />
  300. </ModuleLayout.Full>
  301. </ModuleLayout.Layout>
  302. </Layout.Main>
  303. </Layout.Body>
  304. <HTTPSamplesPanel />
  305. </React.Fragment>
  306. );
  307. }
  308. const DEFAULT_SORT = {
  309. field: 'time_spent_percentage()' as const,
  310. kind: 'desc' as const,
  311. };
  312. const TRANSACTIONS_TABLE_ROW_COUNT = 20;
  313. const HeaderContainer = styled('div')`
  314. display: flex;
  315. justify-content: space-between;
  316. flex-wrap: wrap;
  317. `;
  318. const MetricsRibbon = styled('div')`
  319. display: flex;
  320. flex-wrap: wrap;
  321. gap: ${space(4)};
  322. `;
  323. function LandingPageWithProviders() {
  324. return (
  325. <ModulePageProviders
  326. baseURL="/performance/http"
  327. title={[t('Performance'), MODULE_TITLE, t('Domain Summary')].join(' — ')}
  328. features="spans-first-ui"
  329. >
  330. <HTTPDomainSummaryPage />
  331. </ModulePageProviders>
  332. );
  333. }
  334. export default LandingPageWithProviders;