messageSpanSamplesTable.tsx 3.7 KB

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