123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- import {ReactNode} from 'react';
- import {Location} from 'history';
- import GridEditable, {
- COL_WIDTH_UNDEFINED,
- GridColumnOrder,
- } from 'sentry/components/gridEditable';
- import SortLink from 'sentry/components/gridEditable/sortLink';
- import Link from 'sentry/components/links/link';
- import {t} from 'sentry/locale';
- import {Organization, Project} from 'sentry/types';
- import {defined} from 'sentry/utils';
- import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
- import {ColumnType, fieldAlignment} from 'sentry/utils/discover/fields';
- import {Container as TableCellContainer} from 'sentry/utils/discover/styles';
- import {SuspectSpans} from 'sentry/utils/performance/suspectSpans/types';
- import {spanDetailsRouteWithQuery} from './spanDetails/utils';
- import {SpanSort, SpanSortOthers, SpanSortPercentiles, SpansTotalValues} from './types';
- type Props = {
- isLoading: boolean;
- location: Location;
- organization: Organization;
- sort: SpanSort;
- suspectSpans: SuspectSpans;
- totals: SpansTotalValues | null;
- transactionName: string;
- project?: Project;
- };
- export default function SuspectSpansTable(props: Props) {
- const {
- location,
- organization,
- transactionName,
- isLoading,
- suspectSpans,
- totals,
- sort,
- project,
- } = props;
- const data: TableDataRowWithExtras[] = suspectSpans.map(suspectSpan => ({
- operation: suspectSpan.op,
- group: suspectSpan.group,
- description: suspectSpan.description,
- totalCount: suspectSpan.count,
- frequency:
- // Frequency is computed using the `uniq` function in ClickHouse.
- // Because it is an approximation, it can occasionally exceed the number of events.
- defined(suspectSpan.frequency) && defined(totals?.['count()'])
- ? Math.min(1, suspectSpan.frequency / totals!['count()'])
- : null,
- avgOccurrences: suspectSpan.avgOccurrences,
- p50ExclusiveTime: suspectSpan.p50ExclusiveTime,
- p75ExclusiveTime: suspectSpan.p75ExclusiveTime,
- p95ExclusiveTime: suspectSpan.p95ExclusiveTime,
- p99ExclusiveTime: suspectSpan.p99ExclusiveTime,
- sumExclusiveTime: suspectSpan.sumExclusiveTime,
- }));
- return (
- <GridEditable
- isLoading={isLoading}
- data={data}
- columnOrder={COLUMN_ORDER[sort].map(column => COLUMNS[column])}
- columnSortBy={[]}
- grid={{
- renderHeadCell,
- renderBodyCell: renderBodyCellWithMeta(
- location,
- organization,
- transactionName,
- project
- ),
- }}
- location={location}
- />
- );
- }
- function renderHeadCell(column: TableColumn, _index: number): ReactNode {
- const align = fieldAlignment(column.key, COLUMN_TYPE[column.key]);
- return (
- <SortLink
- title={column.name}
- align={align}
- direction={undefined}
- canSort={false}
- generateSortLink={() => undefined}
- />
- );
- }
- function renderBodyCellWithMeta(
- location: Location,
- organization: Organization,
- transactionName: string,
- project?: Project
- ) {
- return (column: TableColumn, dataRow: TableDataRowWithExtras): React.ReactNode => {
- const fieldRenderer = getFieldRenderer(column.key, COLUMN_TYPE);
- if (column.key === 'description') {
- const target = spanDetailsRouteWithQuery({
- orgSlug: organization.slug,
- transaction: transactionName,
- query: location.query,
- spanSlug: {op: dataRow.operation, group: dataRow.group},
- projectID: project?.id,
- });
- return (
- <TableCellContainer>
- <Link to={target}>{dataRow[column.key] ?? t('(unnamed span)')}</Link>
- </TableCellContainer>
- );
- }
- return fieldRenderer(dataRow, {location, organization});
- };
- }
- type TableColumnKey =
- | 'operation'
- | 'description'
- | 'totalCount'
- | 'frequency'
- | 'avgOccurrences'
- | 'p50ExclusiveTime'
- | 'p75ExclusiveTime'
- | 'p95ExclusiveTime'
- | 'p99ExclusiveTime'
- | 'sumExclusiveTime';
- type TableColumn = GridColumnOrder<TableColumnKey>;
- type TableDataRow = Record<TableColumnKey, any>;
- type TableDataRowWithExtras = TableDataRow & {
- group: string;
- };
- const COLUMN_ORDER: Record<SpanSort, TableColumnKey[]> = {
- [SpanSortOthers.COUNT]: [
- 'operation',
- 'description',
- 'totalCount',
- 'frequency',
- 'p75ExclusiveTime',
- 'sumExclusiveTime',
- ],
- [SpanSortOthers.AVG_OCCURRENCE]: [
- 'operation',
- 'description',
- 'avgOccurrences',
- 'frequency',
- 'p75ExclusiveTime',
- 'sumExclusiveTime',
- ],
- [SpanSortOthers.SUM_EXCLUSIVE_TIME]: [
- 'operation',
- 'description',
- 'totalCount',
- 'frequency',
- 'p75ExclusiveTime',
- 'sumExclusiveTime',
- ],
- [SpanSortPercentiles.P50_EXCLUSIVE_TIME]: [
- 'operation',
- 'description',
- 'totalCount',
- 'frequency',
- 'p50ExclusiveTime',
- 'sumExclusiveTime',
- ],
- [SpanSortPercentiles.P75_EXCLUSIVE_TIME]: [
- 'operation',
- 'description',
- 'totalCount',
- 'frequency',
- 'p75ExclusiveTime',
- 'sumExclusiveTime',
- ],
- [SpanSortPercentiles.P95_EXCLUSIVE_TIME]: [
- 'operation',
- 'description',
- 'totalCount',
- 'frequency',
- 'p95ExclusiveTime',
- 'sumExclusiveTime',
- ],
- [SpanSortPercentiles.P99_EXCLUSIVE_TIME]: [
- 'operation',
- 'description',
- 'totalCount',
- 'frequency',
- 'p99ExclusiveTime',
- 'sumExclusiveTime',
- ],
- };
- const COLUMNS: Record<TableColumnKey, TableColumn> = {
- operation: {
- key: 'operation',
- name: t('Span Operation'),
- width: COL_WIDTH_UNDEFINED,
- },
- description: {
- key: 'description',
- name: t('Span Name'),
- width: COL_WIDTH_UNDEFINED,
- },
- totalCount: {
- key: 'totalCount',
- name: t('Total Count'),
- width: COL_WIDTH_UNDEFINED,
- },
- frequency: {
- key: 'frequency',
- name: t('Frequency'),
- width: COL_WIDTH_UNDEFINED,
- },
- avgOccurrences: {
- key: 'avgOccurrences',
- name: t('Average Occurrences'),
- width: COL_WIDTH_UNDEFINED,
- },
- p50ExclusiveTime: {
- key: 'p50ExclusiveTime',
- name: t('P50 Self Time'),
- width: COL_WIDTH_UNDEFINED,
- },
- p75ExclusiveTime: {
- key: 'p75ExclusiveTime',
- name: t('P75 Self Time'),
- width: COL_WIDTH_UNDEFINED,
- },
- p95ExclusiveTime: {
- key: 'p95ExclusiveTime',
- name: t('P95 Self Time'),
- width: COL_WIDTH_UNDEFINED,
- },
- p99ExclusiveTime: {
- key: 'p99ExclusiveTime',
- name: t('P99 Self Time'),
- width: COL_WIDTH_UNDEFINED,
- },
- sumExclusiveTime: {
- key: 'sumExclusiveTime',
- name: t('Total Self Time'),
- width: COL_WIDTH_UNDEFINED,
- },
- };
- const COLUMN_TYPE: Record<TableColumnKey, ColumnType> = {
- operation: 'string',
- description: 'string',
- totalCount: 'integer',
- frequency: 'percentage',
- avgOccurrences: 'number',
- p50ExclusiveTime: 'duration',
- p75ExclusiveTime: 'duration',
- p95ExclusiveTime: 'duration',
- p99ExclusiveTime: 'duration',
- sumExclusiveTime: 'duration',
- };
|