databaseSpanSummaryPage.tsx 8.5 KB

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