spanSamplesTable.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 {renderHeadCell} from 'sentry/views/insights/common/components/tableCells/renderHeadCell';
  15. import {SpanIdCell} from 'sentry/views/insights/common/components/tableCells/spanIdCell';
  16. import type {SpanIndexedResponse} from 'sentry/views/insights/types';
  17. import {ModuleName, SpanIndexedField} from 'sentry/views/insights/types';
  18. import {TraceViewSources} from 'sentry/views/performance/newTraceDetails/traceHeader/breadcrumbs';
  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.RESPONSE_CODE;
  27. type ColumnKeys =
  28. | SpanIndexedField.ID
  29. | SpanIndexedField.SPAN_DESCRIPTION
  30. | SpanIndexedField.RESPONSE_CODE;
  31. type DataRow = Pick<SpanIndexedResponse, DataRowKeys>;
  32. type Column = GridColumnHeader<ColumnKeys>;
  33. const COLUMN_ORDER: Column[] = [
  34. {
  35. key: SpanIndexedField.ID,
  36. name: t('Span ID'),
  37. width: 150,
  38. },
  39. {
  40. key: SpanIndexedField.RESPONSE_CODE,
  41. name: t('Status'),
  42. width: 50,
  43. },
  44. {
  45. key: SpanIndexedField.SPAN_DESCRIPTION,
  46. name: t('URL'),
  47. width: COL_WIDTH_UNDEFINED,
  48. },
  49. ];
  50. interface Props {
  51. data: DataRow[];
  52. isLoading: boolean;
  53. error?: Error | null;
  54. highlightedSpanId?: string;
  55. meta?: EventsMetaType;
  56. onSampleMouseOut?: ComponentProps<typeof GridEditable>['onRowMouseOut'];
  57. onSampleMouseOver?: ComponentProps<typeof GridEditable>['onRowMouseOver'];
  58. referrer?: string;
  59. }
  60. export function SpanSamplesTable({
  61. data,
  62. isLoading,
  63. error,
  64. meta,
  65. onSampleMouseOver,
  66. onSampleMouseOut,
  67. highlightedSpanId,
  68. }: Props) {
  69. const location = useLocation();
  70. const organization = useOrganization();
  71. return (
  72. <GridEditable
  73. aria-label={t('Span Samples')}
  74. isLoading={isLoading}
  75. error={error}
  76. data={data}
  77. columnOrder={COLUMN_ORDER}
  78. columnSortBy={[]}
  79. grid={{
  80. renderHeadCell: col =>
  81. renderHeadCell({
  82. column: col,
  83. location,
  84. }),
  85. renderBodyCell: (column, row) =>
  86. renderBodyCell(column, row, meta, location, organization),
  87. }}
  88. highlightedRowKey={data.findIndex(row => row.span_id === highlightedSpanId)}
  89. onRowMouseOver={onSampleMouseOver}
  90. onRowMouseOut={onSampleMouseOut}
  91. />
  92. );
  93. }
  94. function renderBodyCell(
  95. column: Column,
  96. row: DataRow,
  97. meta: EventsMetaType | undefined,
  98. location: Location,
  99. organization: Organization
  100. ) {
  101. if (column.key === SpanIndexedField.ID) {
  102. return (
  103. <SpanIdCell
  104. moduleName={ModuleName.HTTP}
  105. projectSlug={row.project}
  106. traceId={row.trace}
  107. timestamp={row.timestamp}
  108. transactionId={row[SpanIndexedField.TRANSACTION_ID]}
  109. spanId={row[SpanIndexedField.ID]}
  110. source={TraceViewSources.REQUESTS_MODULE}
  111. location={location}
  112. />
  113. );
  114. }
  115. if (column.key === SpanIndexedField.SPAN_DESCRIPTION) {
  116. return <SpanDescriptionCell>{row[column.key]}</SpanDescriptionCell>;
  117. }
  118. if (!meta?.fields) {
  119. return row[column.key];
  120. }
  121. const renderer = getFieldRenderer(column.key, meta.fields, false);
  122. return renderer(row, {
  123. location,
  124. organization,
  125. unit: meta.units?.[column.key],
  126. });
  127. }
  128. const SpanDescriptionCell = styled('span')`
  129. word-break: break-word;
  130. `;