spanSamplesTable.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import type {ComponentProps} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import GridEditable, {
  5. COL_WIDTH_UNDEFINED,
  6. type GridColumnHeader,
  7. } from 'sentry/components/gridEditable';
  8. import {t} from 'sentry/locale';
  9. import type {Organization} from 'sentry/types/organization';
  10. import type {EventsMetaType} from 'sentry/utils/discover/eventView';
  11. import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import {CacheHitMissCell} from 'sentry/views/performance/cache/tables/cacheHitMissCell';
  15. import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
  16. import {SpanIdCell} from 'sentry/views/starfish/components/tableCells/spanIdCell';
  17. import type {IndexedResponse} from 'sentry/views/starfish/types';
  18. import {SpanIndexedField} from 'sentry/views/starfish/types';
  19. type DataRowKeys =
  20. | SpanIndexedField.PROJECT
  21. | SpanIndexedField.TRANSACTION_ID
  22. | SpanIndexedField.TRACE
  23. | SpanIndexedField.TIMESTAMP
  24. | SpanIndexedField.ID
  25. | SpanIndexedField.SPAN_DESCRIPTION
  26. | SpanIndexedField.CACHE_HIT
  27. | SpanIndexedField.CACHE_ITEM_SIZE;
  28. type ColumnKeys =
  29. | SpanIndexedField.ID
  30. | SpanIndexedField.SPAN_DESCRIPTION
  31. | SpanIndexedField.CACHE_HIT
  32. | SpanIndexedField.CACHE_ITEM_SIZE
  33. | 'transaction.duration';
  34. type DataRow = Pick<IndexedResponse, DataRowKeys> & {'transaction.duration': number};
  35. type Column = GridColumnHeader<ColumnKeys>;
  36. const COLUMN_ORDER: Column[] = [
  37. {
  38. key: SpanIndexedField.ID,
  39. name: t('Span ID'),
  40. width: 150,
  41. },
  42. {
  43. key: SpanIndexedField.SPAN_DESCRIPTION,
  44. name: t('Key'),
  45. width: COL_WIDTH_UNDEFINED,
  46. },
  47. {
  48. key: 'transaction.duration',
  49. name: t('Txn Duration'),
  50. width: COL_WIDTH_UNDEFINED,
  51. },
  52. {
  53. key: SpanIndexedField.CACHE_ITEM_SIZE,
  54. name: t('Value Size'),
  55. width: COL_WIDTH_UNDEFINED,
  56. },
  57. {
  58. key: SpanIndexedField.CACHE_HIT,
  59. name: t('Status'),
  60. width: COL_WIDTH_UNDEFINED,
  61. },
  62. ];
  63. interface Props {
  64. data: DataRow[];
  65. isLoading: boolean;
  66. error?: Error | null;
  67. highlightedSpanId?: string;
  68. meta?: EventsMetaType;
  69. onSampleMouseOut?: ComponentProps<typeof GridEditable>['onRowMouseOut'];
  70. onSampleMouseOver?: ComponentProps<typeof GridEditable>['onRowMouseOver'];
  71. }
  72. export function SpanSamplesTable({
  73. data,
  74. isLoading,
  75. error,
  76. meta,
  77. onSampleMouseOver,
  78. onSampleMouseOut,
  79. highlightedSpanId,
  80. }: Props) {
  81. const location = useLocation();
  82. const organization = useOrganization();
  83. return (
  84. <GridEditable
  85. aria-label={t('Span Samples')}
  86. isLoading={isLoading}
  87. error={error}
  88. data={data}
  89. columnOrder={COLUMN_ORDER}
  90. columnSortBy={[]}
  91. grid={{
  92. renderHeadCell: col =>
  93. renderHeadCell({
  94. column: col,
  95. location,
  96. }),
  97. renderBodyCell: (column, row) =>
  98. renderBodyCell(column, row, meta, location, organization),
  99. }}
  100. highlightedRowKey={data.findIndex(row => row.span_id === highlightedSpanId)}
  101. onRowMouseOver={onSampleMouseOver}
  102. onRowMouseOut={onSampleMouseOut}
  103. location={location}
  104. />
  105. );
  106. }
  107. function renderBodyCell(
  108. column: Column,
  109. row: DataRow,
  110. meta: EventsMetaType | undefined,
  111. location: Location,
  112. organization: Organization
  113. ) {
  114. if (column.key === SpanIndexedField.ID) {
  115. return (
  116. <SpanIdCell
  117. projectSlug={row.project}
  118. traceId={row.trace}
  119. timestamp={row.timestamp}
  120. transactionId={row[SpanIndexedField.TRANSACTION_ID]}
  121. spanId={row[SpanIndexedField.ID]}
  122. />
  123. );
  124. }
  125. if (column.key === SpanIndexedField.SPAN_DESCRIPTION) {
  126. const cacheKey = row[column.key].split(' ')[1]; // TODO - test with multiple keys
  127. return <SpanDescriptionCell>{cacheKey}</SpanDescriptionCell>;
  128. }
  129. if (column.key === SpanIndexedField.CACHE_HIT) {
  130. return <CacheHitMissCell hit={row[column.key]} />;
  131. }
  132. if (!meta?.fields) {
  133. return row[column.key];
  134. }
  135. const renderer = getFieldRenderer(column.key, meta.fields, false);
  136. return renderer(row, {
  137. location,
  138. organization,
  139. unit: meta.units?.[column.key],
  140. });
  141. }
  142. const SpanDescriptionCell = styled('span')`
  143. word-break: break-word;
  144. `;