databaseSpanSummaryPage.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import {RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import Breadcrumbs from 'sentry/components/breadcrumbs';
  5. import DatePageFilter from 'sentry/components/datePageFilter';
  6. import FeatureBadge from 'sentry/components/featureBadge';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  9. import {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import type {Sort} from 'sentry/utils/discover/fields';
  12. import {RateUnits} from 'sentry/utils/discover/fields';
  13. import {formatRate} from 'sentry/utils/formatters';
  14. import {useLocation} from 'sentry/utils/useLocation';
  15. import useOrganization from 'sentry/utils/useOrganization';
  16. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  17. import {ModulePageProviders} from 'sentry/views/performance/database/modulePageProviders';
  18. import {AVG_COLOR, THROUGHPUT_COLOR} from 'sentry/views/starfish/colours';
  19. import Chart, {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  20. import ChartPanel from 'sentry/views/starfish/components/chartPanel';
  21. import {SpanDescription} from 'sentry/views/starfish/components/spanDescription';
  22. import {useFullSpanFromTrace} from 'sentry/views/starfish/queries/useFullSpanFromTrace';
  23. import {
  24. SpanSummaryQueryFilters,
  25. useSpanMetrics,
  26. } from 'sentry/views/starfish/queries/useSpanMetrics';
  27. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  28. import {SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
  29. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  30. import {
  31. getDurationChartTitle,
  32. getThroughputChartTitle,
  33. } from 'sentry/views/starfish/views/spans/types';
  34. import {useModuleSort} from 'sentry/views/starfish/views/spans/useModuleSort';
  35. import {Block, BlockContainer} from 'sentry/views/starfish/views/spanSummaryPage/block';
  36. import {SampleList} from 'sentry/views/starfish/views/spanSummaryPage/sampleList';
  37. import {SpanMetricsRibbon} from 'sentry/views/starfish/views/spanSummaryPage/spanMetricsRibbon';
  38. import {SpanTransactionsTable} from 'sentry/views/starfish/views/spanSummaryPage/spanTransactionsTable';
  39. type Query = {
  40. endpoint: string;
  41. endpointMethod: string;
  42. transaction: string;
  43. transactionMethod: string;
  44. [QueryParameterNames.SPANS_SORT]: string;
  45. };
  46. type Props = {
  47. location: Location<Query>;
  48. } & RouteComponentProps<Query, {groupId: string}>;
  49. function SpanSummaryPage({params}: Props) {
  50. const organization = useOrganization();
  51. const location = useLocation<Query>();
  52. const {groupId} = params;
  53. const {transaction, transactionMethod, endpoint, endpointMethod} = location.query;
  54. const queryFilter: SpanSummaryQueryFilters = endpoint
  55. ? {transactionName: endpoint, 'transaction.method': endpointMethod}
  56. : {};
  57. const sort = useModuleSort(QueryParameterNames.ENDPOINTS_SORT, DEFAULT_SORT);
  58. const {data: fullSpan} = useFullSpanFromTrace(groupId);
  59. const {data: spanMetrics} = useSpanMetrics(
  60. groupId,
  61. queryFilter,
  62. [
  63. SpanMetricsField.SPAN_OP,
  64. SpanMetricsField.SPAN_DESCRIPTION,
  65. SpanMetricsField.SPAN_ACTION,
  66. SpanMetricsField.SPAN_DOMAIN,
  67. 'count()',
  68. `${SpanFunction.SPM}()`,
  69. `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
  70. `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
  71. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  72. `${SpanFunction.HTTP_ERROR_COUNT}()`,
  73. ],
  74. 'api.starfish.span-summary-page-metrics'
  75. );
  76. const span = {
  77. ...spanMetrics,
  78. [SpanMetricsField.SPAN_GROUP]: groupId,
  79. } as {
  80. [SpanMetricsField.SPAN_OP]: string;
  81. [SpanMetricsField.SPAN_DESCRIPTION]: string;
  82. [SpanMetricsField.SPAN_ACTION]: string;
  83. [SpanMetricsField.SPAN_DOMAIN]: string;
  84. [SpanMetricsField.SPAN_GROUP]: string;
  85. };
  86. const {isLoading: areSpanMetricsSeriesLoading, data: spanMetricsSeriesData} =
  87. useSpanMetricsSeries(
  88. groupId,
  89. queryFilter,
  90. [`avg(${SpanMetricsField.SPAN_SELF_TIME})`, 'spm()', 'http_error_count()'],
  91. 'api.starfish.span-summary-page-metrics-chart'
  92. );
  93. useSynchronizeCharts([!areSpanMetricsSeriesLoading]);
  94. const spanMetricsThroughputSeries = {
  95. seriesName: span?.[SpanMetricsField.SPAN_OP]?.startsWith('db')
  96. ? 'Queries'
  97. : 'Requests',
  98. data: spanMetricsSeriesData?.['spm()'].data,
  99. };
  100. return (
  101. <ModulePageProviders
  102. title={[t('Performance'), t('Database'), t('Query Summary')].join(' — ')}
  103. >
  104. <Layout.Header>
  105. <Layout.HeaderContent>
  106. <Breadcrumbs
  107. crumbs={[
  108. {
  109. label: 'Performance',
  110. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  111. preservePageFilters: true,
  112. },
  113. {
  114. label: 'Database',
  115. to: normalizeUrl(
  116. `/organizations/${organization.slug}/performance/database`
  117. ),
  118. preservePageFilters: true,
  119. },
  120. {
  121. label: 'Query Summary',
  122. },
  123. ]}
  124. />
  125. <Layout.Title>
  126. {t('Query Summary')}
  127. <FeatureBadge type="alpha" />
  128. </Layout.Title>
  129. </Layout.HeaderContent>
  130. </Layout.Header>
  131. <Layout.Body>
  132. <Layout.Main fullWidth>
  133. <HeaderContainer>
  134. <PaddedContainer>
  135. <PageFilterBar condensed>
  136. <DatePageFilter alignDropdown="left" />
  137. </PageFilterBar>
  138. </PaddedContainer>
  139. <SpanMetricsRibbon spanMetrics={span} />
  140. </HeaderContainer>
  141. {span?.[SpanMetricsField.SPAN_DESCRIPTION] && (
  142. <DescriptionContainer>
  143. <SpanDescription
  144. span={{
  145. ...span,
  146. [SpanMetricsField.SPAN_DESCRIPTION]:
  147. fullSpan?.description ??
  148. spanMetrics?.[SpanMetricsField.SPAN_DESCRIPTION],
  149. }}
  150. />
  151. </DescriptionContainer>
  152. )}
  153. <BlockContainer>
  154. <Block>
  155. <ChartPanel
  156. title={getThroughputChartTitle(span?.[SpanMetricsField.SPAN_OP])}
  157. >
  158. <Chart
  159. height={CHART_HEIGHT}
  160. data={[spanMetricsThroughputSeries]}
  161. loading={areSpanMetricsSeriesLoading}
  162. utc={false}
  163. chartColors={[THROUGHPUT_COLOR]}
  164. isLineChart
  165. definedAxisTicks={4}
  166. aggregateOutputFormat="rate"
  167. rateUnit={RateUnits.PER_MINUTE}
  168. tooltipFormatterOptions={{
  169. valueFormatter: value => formatRate(value, RateUnits.PER_MINUTE),
  170. }}
  171. />
  172. </ChartPanel>
  173. </Block>
  174. <Block>
  175. <ChartPanel title={getDurationChartTitle(span?.[SpanMetricsField.SPAN_OP])}>
  176. <Chart
  177. height={CHART_HEIGHT}
  178. data={[
  179. spanMetricsSeriesData?.[`avg(${SpanMetricsField.SPAN_SELF_TIME})`],
  180. ]}
  181. loading={areSpanMetricsSeriesLoading}
  182. utc={false}
  183. chartColors={[AVG_COLOR]}
  184. isLineChart
  185. definedAxisTicks={4}
  186. />
  187. </ChartPanel>
  188. </Block>
  189. </BlockContainer>
  190. {span && (
  191. <SpanTransactionsTable
  192. span={span}
  193. sort={sort}
  194. endpoint={endpoint}
  195. endpointMethod={endpointMethod}
  196. />
  197. )}
  198. <SampleList
  199. groupId={span[SpanMetricsField.SPAN_GROUP]}
  200. transactionName={transaction}
  201. transactionMethod={transactionMethod}
  202. />
  203. </Layout.Main>
  204. </Layout.Body>
  205. </ModulePageProviders>
  206. );
  207. }
  208. const CHART_HEIGHT = 160;
  209. const DEFAULT_SORT: Sort = {
  210. kind: 'desc',
  211. field: 'time_spent_percentage(local)',
  212. };
  213. const PaddedContainer = styled('div')`
  214. margin-bottom: ${space(2)};
  215. `;
  216. const HeaderContainer = styled('div')`
  217. display: flex;
  218. justify-content: space-between;
  219. flex-wrap: wrap;
  220. `;
  221. const DescriptionContainer = styled('div')`
  222. width: 100%;
  223. margin-bottom: ${space(2)};
  224. font-size: 1rem;
  225. line-height: 1.2;
  226. `;
  227. export default SpanSummaryPage;