spanSamplesTable.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import styled from '@emotion/styled';
  2. import {LinkButton} from 'sentry/components/button';
  3. import type {GridColumnHeader} from 'sentry/components/gridEditable';
  4. import GridEditable, {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  5. import Link from 'sentry/components/links/link';
  6. import {Tooltip} from 'sentry/components/tooltip';
  7. import {IconProfiling} from 'sentry/icons/iconProfiling';
  8. import {t} from 'sentry/locale';
  9. import {trackAnalytics} from 'sentry/utils/analytics';
  10. import {generateLinkToEventInTraceView} from 'sentry/utils/discover/urls';
  11. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import {DurationComparisonCell} from 'sentry/views/insights/common/components/samplesTable/common';
  15. import {DurationCell} from 'sentry/views/insights/common/components/tableCells/durationCell';
  16. import FilenameCell from 'sentry/views/insights/common/components/tableCells/filenameCell';
  17. import ResourceSizeCell from 'sentry/views/insights/common/components/tableCells/resourceSizeCell';
  18. import {
  19. OverflowEllipsisTextContainer,
  20. TextAlignRight,
  21. } from 'sentry/views/insights/common/components/textAlign';
  22. import type {SpanSample} from 'sentry/views/insights/common/queries/useSpanSamples';
  23. import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
  24. import {type ModuleName, SpanMetricsField} from 'sentry/views/insights/types';
  25. const {HTTP_RESPONSE_CONTENT_LENGTH, SPAN_DESCRIPTION} = SpanMetricsField;
  26. type Keys =
  27. | 'transaction_id'
  28. | 'span_id'
  29. | 'profile_id'
  30. | 'timestamp'
  31. | 'duration'
  32. | 'p95_comparison'
  33. | 'avg_comparison'
  34. | 'http.response_content_length'
  35. | 'span.description';
  36. export type SamplesTableColumnHeader = GridColumnHeader<Keys>;
  37. export const DEFAULT_COLUMN_ORDER: SamplesTableColumnHeader[] = [
  38. {
  39. key: 'span_id',
  40. name: 'Span ID',
  41. width: COL_WIDTH_UNDEFINED,
  42. },
  43. {
  44. key: 'duration',
  45. name: 'Span Duration',
  46. width: COL_WIDTH_UNDEFINED,
  47. },
  48. {
  49. key: 'avg_comparison',
  50. name: 'Compared to Average',
  51. width: COL_WIDTH_UNDEFINED,
  52. },
  53. ];
  54. type SpanTableRow = {
  55. op: string;
  56. trace: string;
  57. transaction: {
  58. 'project.name': string;
  59. timestamp: string;
  60. 'transaction.duration': number;
  61. };
  62. 'transaction.id': string;
  63. } & SpanSample;
  64. type Props = {
  65. avg: number;
  66. data: SpanTableRow[];
  67. groupId: string;
  68. isLoading: boolean;
  69. moduleName: ModuleName;
  70. columnOrder?: SamplesTableColumnHeader[];
  71. highlightedSpanId?: string;
  72. onMouseLeaveSample?: () => void;
  73. onMouseOverSample?: (sample: SpanSample) => void;
  74. source?: string;
  75. };
  76. export function SpanSamplesTable({
  77. groupId,
  78. isLoading,
  79. data,
  80. avg,
  81. moduleName,
  82. highlightedSpanId,
  83. onMouseLeaveSample,
  84. onMouseOverSample,
  85. columnOrder,
  86. source,
  87. }: Props) {
  88. const location = useLocation();
  89. const organization = useOrganization();
  90. const {view} = useDomainViewFilters();
  91. function renderHeadCell(column: GridColumnHeader): React.ReactNode {
  92. if (
  93. column.key === 'p95_comparison' ||
  94. column.key === 'avg_comparison' ||
  95. column.key === 'duration' ||
  96. column.key === HTTP_RESPONSE_CONTENT_LENGTH
  97. ) {
  98. return (
  99. <TextAlignRight>
  100. <OverflowEllipsisTextContainer>{column.name}</OverflowEllipsisTextContainer>
  101. </TextAlignRight>
  102. );
  103. }
  104. return <OverflowEllipsisTextContainer>{column.name}</OverflowEllipsisTextContainer>;
  105. }
  106. function renderBodyCell(column: GridColumnHeader, row: SpanTableRow): React.ReactNode {
  107. if (column.key === 'transaction_id') {
  108. return (
  109. <Link
  110. to={generateLinkToEventInTraceView({
  111. eventId: row['transaction.id'],
  112. timestamp: row.timestamp,
  113. traceSlug: row.trace,
  114. projectSlug: row.project,
  115. organization,
  116. location: {
  117. ...location,
  118. query: {
  119. ...location.query,
  120. groupId,
  121. },
  122. },
  123. spanId: row.span_id,
  124. source,
  125. view,
  126. })}
  127. >
  128. {row['transaction.id'].slice(0, 8)}
  129. </Link>
  130. );
  131. }
  132. if (column.key === 'span_id') {
  133. return (
  134. <Link
  135. onClick={() =>
  136. trackAnalytics('performance_views.sample_spans.span_clicked', {
  137. organization,
  138. source: moduleName,
  139. })
  140. }
  141. to={generateLinkToEventInTraceView({
  142. eventId: row['transaction.id'],
  143. timestamp: row.timestamp,
  144. traceSlug: row.trace,
  145. projectSlug: row.project,
  146. organization,
  147. location: {
  148. ...location,
  149. query: {
  150. ...location.query,
  151. groupId,
  152. },
  153. },
  154. spanId: row.span_id,
  155. source,
  156. view,
  157. })}
  158. >
  159. {row.span_id}
  160. </Link>
  161. );
  162. }
  163. if (column.key === HTTP_RESPONSE_CONTENT_LENGTH) {
  164. const size = parseInt(row[HTTP_RESPONSE_CONTENT_LENGTH], 10);
  165. return <ResourceSizeCell bytes={size} />;
  166. }
  167. if (column.key === SPAN_DESCRIPTION) {
  168. return <FilenameCell url={row[SPAN_DESCRIPTION]} />;
  169. }
  170. if (column.key === 'profile_id') {
  171. return (
  172. <IconWrapper>
  173. {row.profile_id ? (
  174. <Tooltip title={t('View Profile')}>
  175. <LinkButton
  176. to={normalizeUrl(
  177. `/organizations/${organization.slug}/profiling/profile/${row.project}/${row.profile_id}/flamegraph/?spanId=${row.span_id}`
  178. )}
  179. size="xs"
  180. >
  181. <IconProfiling size="xs" />
  182. </LinkButton>
  183. </Tooltip>
  184. ) : (
  185. <div>(no value)</div>
  186. )}
  187. </IconWrapper>
  188. );
  189. }
  190. if (column.key === 'duration') {
  191. return <DurationCell milliseconds={row['span.self_time']} />;
  192. }
  193. if (column.key === 'avg_comparison') {
  194. return (
  195. <DurationComparisonCell
  196. duration={row['span.self_time']}
  197. compareToDuration={avg}
  198. />
  199. );
  200. }
  201. return <span>{row[column.key]}</span>;
  202. }
  203. return (
  204. <GridEditable
  205. isLoading={isLoading}
  206. data={data}
  207. columnOrder={columnOrder ?? DEFAULT_COLUMN_ORDER}
  208. columnSortBy={[]}
  209. onRowMouseOver={onMouseOverSample}
  210. onRowMouseOut={onMouseLeaveSample}
  211. highlightedRowKey={data.findIndex(sample => sample.span_id === highlightedSpanId)}
  212. grid={{
  213. renderHeadCell,
  214. renderBodyCell,
  215. }}
  216. />
  217. );
  218. }
  219. const IconWrapper = styled('div')`
  220. text-align: right;
  221. width: 100%;
  222. height: 26px;
  223. `;