databaseSpanSummaryPage.tsx 8.4 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 FeedbackWidget from 'sentry/components/feedback/widget/feedbackWidget';
  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 {AVG_COLOR, THROUGHPUT_COLOR} from 'sentry/views/starfish/colours';
  20. import Chart, {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  21. import ChartPanel from 'sentry/views/starfish/components/chartPanel';
  22. import {SpanDescription} from 'sentry/views/starfish/components/spanDescription';
  23. import {useFullSpanFromTrace} from 'sentry/views/starfish/queries/useFullSpanFromTrace';
  24. import {
  25. SpanSummaryQueryFilters,
  26. useSpanMetrics,
  27. } from 'sentry/views/starfish/queries/useSpanMetrics';
  28. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  29. import {SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
  30. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  31. import {
  32. getDurationChartTitle,
  33. getThroughputChartTitle,
  34. } from 'sentry/views/starfish/views/spans/types';
  35. import {useModuleSort} from 'sentry/views/starfish/views/spans/useModuleSort';
  36. import {Block, BlockContainer} from 'sentry/views/starfish/views/spanSummaryPage/block';
  37. import {SampleList} from 'sentry/views/starfish/views/spanSummaryPage/sampleList';
  38. import {SpanMetricsRibbon} from 'sentry/views/starfish/views/spanSummaryPage/spanMetricsRibbon';
  39. import {SpanTransactionsTable} from 'sentry/views/starfish/views/spanSummaryPage/spanTransactionsTable';
  40. type Query = {
  41. endpoint: string;
  42. endpointMethod: string;
  43. transaction: string;
  44. transactionMethod: string;
  45. [QueryParameterNames.SPANS_SORT]: string;
  46. };
  47. type Props = {
  48. location: Location<Query>;
  49. } & RouteComponentProps<Query, {groupId: string}>;
  50. function SpanSummaryPage({params}: Props) {
  51. const organization = useOrganization();
  52. const location = useLocation<Query>();
  53. const {groupId} = params;
  54. const {transaction, transactionMethod, endpoint, endpointMethod} = location.query;
  55. const queryFilter: SpanSummaryQueryFilters = endpoint
  56. ? {transactionName: endpoint, 'transaction.method': endpointMethod}
  57. : {};
  58. const sort = useModuleSort(QueryParameterNames.ENDPOINTS_SORT, DEFAULT_SORT);
  59. const {data: fullSpan} = useFullSpanFromTrace(groupId);
  60. const {data: spanMetrics} = useSpanMetrics(
  61. groupId,
  62. queryFilter,
  63. [
  64. SpanMetricsField.SPAN_OP,
  65. SpanMetricsField.SPAN_DESCRIPTION,
  66. SpanMetricsField.SPAN_ACTION,
  67. SpanMetricsField.SPAN_DOMAIN,
  68. 'count()',
  69. `${SpanFunction.SPM}()`,
  70. `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
  71. `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
  72. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  73. `${SpanFunction.HTTP_ERROR_COUNT}()`,
  74. ],
  75. 'api.starfish.span-summary-page-metrics'
  76. );
  77. const span = {
  78. ...spanMetrics,
  79. [SpanMetricsField.SPAN_GROUP]: groupId,
  80. } as {
  81. [SpanMetricsField.SPAN_OP]: string;
  82. [SpanMetricsField.SPAN_DESCRIPTION]: string;
  83. [SpanMetricsField.SPAN_ACTION]: string;
  84. [SpanMetricsField.SPAN_DOMAIN]: string[];
  85. [SpanMetricsField.SPAN_GROUP]: string;
  86. };
  87. const {isLoading: areSpanMetricsSeriesLoading, data: spanMetricsSeriesData} =
  88. useSpanMetricsSeries(
  89. groupId,
  90. queryFilter,
  91. [`avg(${SpanMetricsField.SPAN_SELF_TIME})`, 'spm()', 'http_error_count()'],
  92. 'api.starfish.span-summary-page-metrics-chart'
  93. );
  94. useSynchronizeCharts([!areSpanMetricsSeriesLoading]);
  95. const spanMetricsThroughputSeries = {
  96. seriesName: span?.[SpanMetricsField.SPAN_OP]?.startsWith('db')
  97. ? 'Queries'
  98. : 'Requests',
  99. data: spanMetricsSeriesData?.['spm()'].data,
  100. };
  101. return (
  102. <ModulePageProviders
  103. title={[t('Performance'), t('Database'), t('Query Summary')].join(' — ')}
  104. >
  105. <Layout.Header>
  106. <Layout.HeaderContent>
  107. <Breadcrumbs
  108. crumbs={[
  109. {
  110. label: 'Performance',
  111. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  112. preservePageFilters: true,
  113. },
  114. {
  115. label: 'Queries',
  116. to: normalizeUrl(
  117. `/organizations/${organization.slug}/performance/database`
  118. ),
  119. preservePageFilters: true,
  120. },
  121. {
  122. label: 'Query Summary',
  123. },
  124. ]}
  125. />
  126. <Layout.Title>{t('Query Summary')}</Layout.Title>
  127. </Layout.HeaderContent>
  128. </Layout.Header>
  129. <Layout.Body>
  130. <FeedbackWidget />
  131. <Layout.Main fullWidth>
  132. <HeaderContainer>
  133. <PaddedContainer>
  134. <PageFilterBar condensed>
  135. <EnvironmentPageFilter />
  136. <DatePageFilter />
  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()',
  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;