transactionSamplesTable.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import DateTime from 'sentry/components/dateTime';
  4. import GridEditable, {
  5. COL_WIDTH_UNDEFINED,
  6. GridColumnHeader,
  7. } from 'sentry/components/gridEditable';
  8. import Link from 'sentry/components/links/link';
  9. import QuestionTooltip from 'sentry/components/questionTooltip';
  10. import {t} from 'sentry/locale';
  11. import {NewQuery} from 'sentry/types';
  12. import EventView from 'sentry/utils/discover/eventView';
  13. import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
  14. import {SPAN_OP_RELATIVE_BREAKDOWN_FIELD} from 'sentry/utils/discover/fields';
  15. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  16. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  17. import {useLocation} from 'sentry/utils/useLocation';
  18. import useOrganization from 'sentry/utils/useOrganization';
  19. import {DurationComparisonCell} from 'sentry/views/starfish/components/samplesTable/common';
  20. import useErrorSamples from 'sentry/views/starfish/components/samplesTable/useErrorSamples';
  21. import useSlowMedianFastSamplesQuery from 'sentry/views/starfish/components/samplesTable/useSlowMedianFastSamplesQuery';
  22. import DurationCell from 'sentry/views/starfish/components/tableCells/durationCell';
  23. import {
  24. OverflowEllipsisTextContainer,
  25. TextAlignLeft,
  26. TextAlignRight,
  27. } from 'sentry/views/starfish/components/textAlign';
  28. import {DataTitles} from 'sentry/views/starfish/views/spans/types';
  29. import {SampleFilter} from 'sentry/views/starfish/views/webServiceView/endpointOverview';
  30. type Keys =
  31. | 'id'
  32. | 'profile_id'
  33. | 'timestamp'
  34. | 'transaction.duration'
  35. | 'p95_comparison'
  36. | 'span_ops_breakdown.relative'
  37. | 'http.status_code'
  38. | 'transaction.status';
  39. type TableColumnHeader = GridColumnHeader<Keys>;
  40. type Props = {
  41. queryConditions: string[];
  42. sampleFilter: SampleFilter;
  43. };
  44. type DataRow = {
  45. 'http.status_code': number;
  46. id: string;
  47. profile_id: string;
  48. 'spans.browser': number;
  49. 'spans.db': number;
  50. 'spans.http': number;
  51. 'spans.resource': number;
  52. 'spans.ui': number;
  53. timestamp: string;
  54. 'transaction.duration': number;
  55. 'transaction.status': string;
  56. };
  57. export function TransactionSamplesTable({queryConditions, sampleFilter}: Props) {
  58. const location = useLocation();
  59. const organization = useOrganization();
  60. const query = new MutableSearch(queryConditions);
  61. const savedQuery: NewQuery = {
  62. id: undefined,
  63. name: 'Endpoint Overview Samples',
  64. query: query.formatString(),
  65. projects: [1],
  66. fields: [],
  67. dataset: DiscoverDatasets.DISCOVER,
  68. version: 2,
  69. };
  70. const columnOrder: TableColumnHeader[] = [
  71. {
  72. key: 'id',
  73. name: 'Event ID',
  74. width: 100,
  75. },
  76. ...(sampleFilter === 'ALL'
  77. ? [
  78. {
  79. key: 'profile_id',
  80. name: 'Profile ID',
  81. width: 140,
  82. } as TableColumnHeader,
  83. {
  84. key: SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  85. name: 'Operation Duration',
  86. width: 180,
  87. } as TableColumnHeader,
  88. {
  89. key: 'timestamp',
  90. name: 'Timestamp',
  91. width: 230,
  92. } as TableColumnHeader,
  93. {
  94. key: 'transaction.duration',
  95. name: DataTitles.duration,
  96. width: 100,
  97. } as TableColumnHeader,
  98. {
  99. key: 'p95_comparison',
  100. name: 'Compared to P95',
  101. width: 100,
  102. } as TableColumnHeader,
  103. ]
  104. : [
  105. {
  106. key: 'http.status_code',
  107. name: 'Response Code',
  108. width: COL_WIDTH_UNDEFINED,
  109. } as TableColumnHeader,
  110. {
  111. key: 'transaction.status',
  112. name: 'Status',
  113. width: COL_WIDTH_UNDEFINED,
  114. } as TableColumnHeader,
  115. {
  116. key: 'timestamp',
  117. name: 'Timestamp',
  118. width: 230,
  119. } as TableColumnHeader,
  120. ]),
  121. ];
  122. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  123. const {isLoading, data, aggregatesData} = useSlowMedianFastSamplesQuery(eventView);
  124. const {isLoading: isErrorSamplesLoading, data: errorSamples} =
  125. useErrorSamples(eventView);
  126. function renderHeadCell(column: GridColumnHeader): React.ReactNode {
  127. if (column.key === 'p95_comparison' || column.key === 'transaction.duration') {
  128. return (
  129. <TextAlignRight>
  130. <OverflowEllipsisTextContainer>{column.name}</OverflowEllipsisTextContainer>
  131. </TextAlignRight>
  132. );
  133. }
  134. if (column.key === SPAN_OP_RELATIVE_BREAKDOWN_FIELD) {
  135. return (
  136. <Fragment>
  137. {column.name}
  138. <StyledIconQuestion
  139. size="xs"
  140. position="top"
  141. title={t(
  142. `Span durations are summed over the course of an entire transaction. Any overlapping spans are only counted once.`
  143. )}
  144. />
  145. </Fragment>
  146. );
  147. }
  148. return <OverflowEllipsisTextContainer>{column.name}</OverflowEllipsisTextContainer>;
  149. }
  150. function renderBodyCell(column: TableColumnHeader, row: DataRow): React.ReactNode {
  151. if (column.key === 'id') {
  152. return (
  153. <Link to={`/performance/${row['project.name']}:${row.id}`}>
  154. {row.id.slice(0, 8)}
  155. </Link>
  156. );
  157. }
  158. if (column.key === 'profile_id') {
  159. return row.profile_id ? (
  160. <Link
  161. to={`/profiling/profile/${row['project.name']}/${row.profile_id}/flamechart/`}
  162. >
  163. {row.profile_id.slice(0, 8)}
  164. </Link>
  165. ) : (
  166. '(no value)'
  167. );
  168. }
  169. if (column.key === 'transaction.duration') {
  170. return <DurationCell milliseconds={row['transaction.duration']} />;
  171. }
  172. if (column.key === 'timestamp') {
  173. return <DateTime date={row[column.key]} year timeZone seconds />;
  174. }
  175. if (column.key === 'p95_comparison') {
  176. return (
  177. <DurationComparisonCell
  178. duration={row['transaction.duration']}
  179. p95={(aggregatesData?.['p95(transaction.duration)'] as number) ?? 0}
  180. />
  181. );
  182. }
  183. if (column.key === SPAN_OP_RELATIVE_BREAKDOWN_FIELD) {
  184. return getFieldRenderer(column.key, {})(row, {
  185. location,
  186. organization,
  187. eventView,
  188. });
  189. }
  190. return <TextAlignLeft>{row[column.key]}</TextAlignLeft>;
  191. }
  192. return (
  193. <GridEditable
  194. isLoading={sampleFilter === 'ALL' ? isLoading : isErrorSamplesLoading}
  195. data={sampleFilter === 'ALL' ? (data as DataRow[]) : (errorSamples as DataRow[])}
  196. columnOrder={columnOrder}
  197. columnSortBy={[]}
  198. location={location}
  199. grid={{
  200. renderHeadCell,
  201. renderBodyCell,
  202. }}
  203. />
  204. );
  205. }
  206. const StyledIconQuestion = styled(QuestionTooltip)`
  207. position: relative;
  208. left: 4px;
  209. `;