spanSamplesTable.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 {SpanIndexedResponse} from 'sentry/views/starfish/types';
  18. import {ModuleName, 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. export type DataRow = Pick<SpanIndexedResponse, DataRowKeys> & {
  35. 'transaction.duration': number;
  36. };
  37. type Column = GridColumnHeader<ColumnKeys>;
  38. const COLUMN_ORDER: Column[] = [
  39. {
  40. key: SpanIndexedField.ID,
  41. name: t('Span ID'),
  42. width: 150,
  43. },
  44. {
  45. key: SpanIndexedField.SPAN_DESCRIPTION,
  46. name: t('Span Description'),
  47. width: COL_WIDTH_UNDEFINED,
  48. },
  49. {
  50. key: 'transaction.duration',
  51. name: t('Transaction Duration'),
  52. width: COL_WIDTH_UNDEFINED,
  53. },
  54. {
  55. key: SpanIndexedField.CACHE_ITEM_SIZE,
  56. name: t('Value Size'),
  57. width: COL_WIDTH_UNDEFINED,
  58. },
  59. {
  60. key: SpanIndexedField.CACHE_HIT,
  61. name: t('Status'),
  62. width: COL_WIDTH_UNDEFINED,
  63. },
  64. ];
  65. interface Props {
  66. data: DataRow[];
  67. isLoading: boolean;
  68. error?: Error | null;
  69. highlightedSpanId?: string;
  70. meta?: EventsMetaType;
  71. onSampleMouseOut?: ComponentProps<typeof GridEditable>['onRowMouseOut'];
  72. onSampleMouseOver?: ComponentProps<typeof GridEditable>['onRowMouseOver'];
  73. }
  74. export function SpanSamplesTable({
  75. data,
  76. isLoading,
  77. error,
  78. meta,
  79. onSampleMouseOver,
  80. onSampleMouseOut,
  81. highlightedSpanId,
  82. }: Props) {
  83. const location = useLocation();
  84. const organization = useOrganization();
  85. return (
  86. <GridEditable
  87. aria-label={t('Span Samples')}
  88. isLoading={isLoading}
  89. error={error}
  90. data={data}
  91. columnOrder={COLUMN_ORDER}
  92. columnSortBy={[]}
  93. grid={{
  94. renderHeadCell: col =>
  95. renderHeadCell({
  96. column: col,
  97. location,
  98. }),
  99. renderBodyCell: (column, row) =>
  100. renderBodyCell(column, row, meta, location, organization),
  101. }}
  102. highlightedRowKey={data.findIndex(row => row.span_id === highlightedSpanId)}
  103. onRowMouseOver={onSampleMouseOver}
  104. onRowMouseOut={onSampleMouseOut}
  105. location={location}
  106. />
  107. );
  108. }
  109. function renderBodyCell(
  110. column: Column,
  111. row: DataRow,
  112. meta: EventsMetaType | undefined,
  113. location: Location,
  114. organization: Organization
  115. ) {
  116. if (column.key === SpanIndexedField.ID) {
  117. return (
  118. <SpanIdCell
  119. moduleName={ModuleName.CACHE}
  120. projectSlug={row.project}
  121. traceId={row.trace}
  122. timestamp={row.timestamp}
  123. transactionId={row[SpanIndexedField.TRANSACTION_ID]}
  124. spanId={row[SpanIndexedField.ID]}
  125. />
  126. );
  127. }
  128. if (column.key === SpanIndexedField.SPAN_DESCRIPTION) {
  129. return (
  130. <SpanDescriptionCell>{row[SpanIndexedField.SPAN_DESCRIPTION]}</SpanDescriptionCell>
  131. );
  132. }
  133. if (column.key === SpanIndexedField.CACHE_HIT) {
  134. return <CacheHitMissCell hit={row[column.key]} />;
  135. }
  136. if (!meta?.fields) {
  137. return row[column.key];
  138. }
  139. const renderer = getFieldRenderer(column.key, meta.fields, false);
  140. return renderer(row, {
  141. location,
  142. organization,
  143. unit: meta.units?.[column.key],
  144. });
  145. }
  146. const SpanDescriptionCell = styled('span')`
  147. word-break: break-word;
  148. `;