httpDomainSummaryPage.tsx 14 KB

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