123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- import type {RouteComponentProps} from 'react-router';
- import styled from '@emotion/styled';
- import type {Location} from 'history';
- import {Breadcrumbs} from 'sentry/components/breadcrumbs';
- import ButtonBar from 'sentry/components/buttonBar';
- import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
- import * as Layout from 'sentry/components/layouts/thirds';
- import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
- import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
- import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
- import {t} from 'sentry/locale';
- import {space} from 'sentry/styles/space';
- import {DurationUnit, RateUnit, type Sort} from 'sentry/utils/discover/fields';
- import {MutableSearch} from 'sentry/utils/tokenizeSearch';
- import {useLocation} from 'sentry/utils/useLocation';
- import useOrganization from 'sentry/utils/useOrganization';
- import {normalizeUrl} from 'sentry/utils/withDomainRequired';
- import {DurationChart} from 'sentry/views/performance/database/durationChart';
- import {ThroughputChart} from 'sentry/views/performance/database/throughputChart';
- import {useSelectedDurationAggregate} from 'sentry/views/performance/database/useSelectedDurationAggregate';
- import {MetricReadout} from 'sentry/views/performance/metricReadout';
- import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
- import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
- import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
- import {DatabaseSpanDescription} from 'sentry/views/starfish/components/spanDescription';
- import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';
- import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
- import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
- import type {SpanMetricsQueryFilters} from 'sentry/views/starfish/types';
- import {SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
- import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
- import {DataTitles, getThroughputTitle} from 'sentry/views/starfish/views/spans/types';
- import {useModuleSort} from 'sentry/views/starfish/views/spans/useModuleSort';
- import {SampleList} from 'sentry/views/starfish/views/spanSummaryPage/sampleList';
- import {SpanTransactionsTable} from 'sentry/views/starfish/views/spanSummaryPage/spanTransactionsTable';
- type Query = {
- endpoint: string;
- endpointMethod: string;
- transaction: string;
- transactionMethod: string;
- [QueryParameterNames.SPANS_SORT]: string;
- aggregate?: string;
- };
- type Props = {
- location: Location<Query>;
- } & RouteComponentProps<Query, {groupId: string}>;
- function SpanSummaryPage({params}: Props) {
- const organization = useOrganization();
- const location = useLocation<Query>();
- const [selectedAggregate] = useSelectedDurationAggregate();
- const {groupId} = params;
- const {transaction, transactionMethod, endpoint, endpointMethod} = location.query;
- const filters: SpanMetricsQueryFilters = {
- 'span.group': groupId,
- };
- if (endpoint) {
- filters.transaction = endpoint;
- }
- if (endpointMethod) {
- filters['transaction.method'] = endpointMethod;
- }
- const sort = useModuleSort(QueryParameterNames.ENDPOINTS_SORT, DEFAULT_SORT);
- const {data, isLoading: areSpanMetricsLoading} = useSpanMetrics({
- search: MutableSearch.fromQueryObject(filters),
- fields: [
- SpanMetricsField.SPAN_OP,
- SpanMetricsField.SPAN_DESCRIPTION,
- SpanMetricsField.SPAN_ACTION,
- SpanMetricsField.SPAN_DOMAIN,
- 'count()',
- `${SpanFunction.SPM}()`,
- `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
- `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
- `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
- `${SpanFunction.HTTP_ERROR_COUNT}()`,
- ],
- enabled: Boolean(groupId),
- referrer: 'api.starfish.span-summary-page-metrics',
- });
- const spanMetrics = data[0] ?? {};
- const span = {
- ...spanMetrics,
- [SpanMetricsField.SPAN_GROUP]: groupId,
- } as {
- [SpanMetricsField.SPAN_OP]: string;
- [SpanMetricsField.SPAN_DESCRIPTION]: string;
- [SpanMetricsField.SPAN_ACTION]: string;
- [SpanMetricsField.SPAN_DOMAIN]: string[];
- [SpanMetricsField.SPAN_GROUP]: string;
- };
- const {
- isLoading: isThroughputDataLoading,
- data: throughputData,
- error: throughputError,
- } = useSpanMetricsSeries({
- search: MutableSearch.fromQueryObject(filters),
- yAxis: ['spm()'],
- enabled: Boolean(groupId),
- referrer: 'api.starfish.span-summary-page-metrics-chart',
- });
- const {
- isLoading: isDurationDataLoading,
- data: durationData,
- error: durationError,
- } = useSpanMetricsSeries({
- search: MutableSearch.fromQueryObject(filters),
- yAxis: [`${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`],
- enabled: Boolean(groupId),
- referrer: 'api.starfish.span-summary-page-metrics-chart',
- });
- useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
- return (
- <ModulePageProviders
- title={[t('Performance'), t('Database'), t('Query Summary')].join(' — ')}
- baseURL="/performance/database"
- features="spans-first-ui"
- >
- <Layout.Header>
- <Layout.HeaderContent>
- <Breadcrumbs
- crumbs={[
- {
- label: 'Performance',
- to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
- preservePageFilters: true,
- },
- {
- label: 'Queries',
- to: normalizeUrl(
- `/organizations/${organization.slug}/performance/database`
- ),
- preservePageFilters: true,
- },
- {
- label: 'Query Summary',
- },
- ]}
- />
- <Layout.Title>{t('Query Summary')}</Layout.Title>
- </Layout.HeaderContent>
- <Layout.HeaderActions>
- <ButtonBar gap={1}>
- <FeedbackWidgetButton />
- </ButtonBar>
- </Layout.HeaderActions>
- </Layout.Header>
- <Layout.Body>
- <Layout.Main fullWidth>
- <HeaderContainer>
- <PageFilterBar condensed>
- <EnvironmentPageFilter />
- <DatePageFilter />
- </PageFilterBar>
- <MetricsRibbon>
- <MetricReadout
- title={getThroughputTitle('db')}
- value={spanMetrics?.[`${SpanFunction.SPM}()`]}
- unit={RateUnit.PER_MINUTE}
- isLoading={areSpanMetricsLoading}
- />
- <MetricReadout
- title={DataTitles.avg}
- value={spanMetrics?.[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]}
- unit={DurationUnit.MILLISECOND}
- isLoading={areSpanMetricsLoading}
- />
- <MetricReadout
- title={DataTitles.timeSpent}
- value={spanMetrics?.['sum(span.self_time)']}
- unit={DurationUnit.MILLISECOND}
- tooltip={getTimeSpentExplanation(
- spanMetrics?.['time_spent_percentage()'],
- 'db'
- )}
- isLoading={areSpanMetricsLoading}
- />
- </MetricsRibbon>
- </HeaderContainer>
- <ModuleLayout.Layout>
- {groupId && (
- <DescriptionContainer>
- <DatabaseSpanDescription
- groupId={groupId}
- preliminaryDescription={spanMetrics?.['span.description']}
- />
- </DescriptionContainer>
- )}
- <ModuleLayout.Full>
- <ChartContainer>
- <ThroughputChart
- series={throughputData['spm()']}
- isLoading={isThroughputDataLoading}
- error={throughputError}
- />
- <DurationChart
- series={[
- durationData[
- `${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`
- ],
- ]}
- isLoading={isDurationDataLoading}
- error={durationError}
- />
- </ChartContainer>
- </ModuleLayout.Full>
- {span && (
- <ModuleLayout.Full>
- <SpanTransactionsTable
- span={span}
- sort={sort}
- endpoint={endpoint}
- endpointMethod={endpointMethod}
- />
- </ModuleLayout.Full>
- )}
- </ModuleLayout.Layout>
- <SampleList
- groupId={span[SpanMetricsField.SPAN_GROUP]}
- transactionName={transaction}
- transactionMethod={transactionMethod}
- />
- </Layout.Main>
- </Layout.Body>
- </ModulePageProviders>
- );
- }
- const DEFAULT_SORT: Sort = {
- kind: 'desc',
- field: 'time_spent_percentage()',
- };
- const ChartContainer = styled('div')`
- display: grid;
- gap: 0;
- grid-template-columns: 1fr;
- @media (min-width: ${p => p.theme.breakpoints.small}) {
- grid-template-columns: 1fr 1fr;
- gap: ${space(2)};
- }
- `;
- const HeaderContainer = styled('div')`
- display: flex;
- justify-content: space-between;
- flex-wrap: wrap;
- `;
- const DescriptionContainer = styled(ModuleLayout.Full)`
- line-height: 1.2;
- `;
- const MetricsRibbon = styled('div')`
- display: flex;
- flex-wrap: wrap;
- gap: ${space(4)};
- `;
- export default SpanSummaryPage;
|