transactionSamplesTable.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. | 'avg_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. fields: [],
  66. dataset: DiscoverDatasets.DISCOVER,
  67. version: 2,
  68. };
  69. const columnOrder: TableColumnHeader[] = [
  70. {
  71. key: 'id',
  72. name: 'Event ID',
  73. width: 100,
  74. },
  75. ...(sampleFilter === 'ALL'
  76. ? [
  77. {
  78. key: 'profile_id',
  79. name: 'Profile ID',
  80. width: 140,
  81. } as TableColumnHeader,
  82. {
  83. key: SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  84. name: 'Operation Duration',
  85. width: 180,
  86. } as TableColumnHeader,
  87. {
  88. key: 'timestamp',
  89. name: 'Timestamp',
  90. width: 230,
  91. } as TableColumnHeader,
  92. {
  93. key: 'transaction.duration',
  94. name: DataTitles.duration,
  95. width: 100,
  96. } as TableColumnHeader,
  97. {
  98. key: 'avg_comparison',
  99. name: 'Compared to Average',
  100. width: 100,
  101. } as TableColumnHeader,
  102. ]
  103. : [
  104. {
  105. key: 'http.status_code',
  106. name: 'Response Code',
  107. width: COL_WIDTH_UNDEFINED,
  108. } as TableColumnHeader,
  109. {
  110. key: 'transaction.status',
  111. name: 'Status',
  112. width: COL_WIDTH_UNDEFINED,
  113. } as TableColumnHeader,
  114. {
  115. key: 'timestamp',
  116. name: 'Timestamp',
  117. width: 230,
  118. } as TableColumnHeader,
  119. ]),
  120. ];
  121. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  122. const {isLoading, data, aggregatesData} = useSlowMedianFastSamplesQuery(eventView);
  123. const {isLoading: isErrorSamplesLoading, data: errorSamples} =
  124. useErrorSamples(eventView);
  125. function renderHeadCell(column: GridColumnHeader): React.ReactNode {
  126. if (column.key === 'avg_comparison' || column.key === 'transaction.duration') {
  127. return (
  128. <TextAlignRight>
  129. <OverflowEllipsisTextContainer>{column.name}</OverflowEllipsisTextContainer>
  130. </TextAlignRight>
  131. );
  132. }
  133. if (column.key === SPAN_OP_RELATIVE_BREAKDOWN_FIELD) {
  134. return (
  135. <Fragment>
  136. {column.name}
  137. <StyledIconQuestion
  138. size="xs"
  139. position="top"
  140. title={t(
  141. `Span durations are summed over the course of an entire transaction. Any overlapping spans are only counted once.`
  142. )}
  143. />
  144. </Fragment>
  145. );
  146. }
  147. return <OverflowEllipsisTextContainer>{column.name}</OverflowEllipsisTextContainer>;
  148. }
  149. function renderBodyCell(column: TableColumnHeader, row: DataRow): React.ReactNode {
  150. if (column.key === 'id') {
  151. return (
  152. <Link to={`/performance/${row['project.name']}:${row.id}`}>
  153. {row.id.slice(0, 8)}
  154. </Link>
  155. );
  156. }
  157. if (column.key === 'profile_id') {
  158. return row.profile_id ? (
  159. <Link
  160. to={`/profiling/profile/${row['project.name']}/${row.profile_id}/flamechart/`}
  161. >
  162. {row.profile_id.slice(0, 8)}
  163. </Link>
  164. ) : (
  165. '(no value)'
  166. );
  167. }
  168. if (column.key === 'transaction.duration') {
  169. return <DurationCell milliseconds={row['transaction.duration']} />;
  170. }
  171. if (column.key === 'timestamp') {
  172. return <DateTime date={row[column.key]} year timeZone seconds />;
  173. }
  174. if (column.key === 'avg_comparison') {
  175. return (
  176. <DurationComparisonCell
  177. duration={row['transaction.duration']}
  178. compareToDuration={
  179. (aggregatesData?.['avg(transaction.duration)'] as number) ?? 0
  180. }
  181. />
  182. );
  183. }
  184. if (column.key === SPAN_OP_RELATIVE_BREAKDOWN_FIELD) {
  185. return getFieldRenderer(column.key, {})(row, {
  186. location,
  187. organization,
  188. eventView,
  189. });
  190. }
  191. return <TextAlignLeft>{row[column.key]}</TextAlignLeft>;
  192. }
  193. return (
  194. <GridEditable
  195. isLoading={sampleFilter === 'ALL' ? isLoading : isErrorSamplesLoading}
  196. data={sampleFilter === 'ALL' ? (data as DataRow[]) : (errorSamples as DataRow[])}
  197. columnOrder={columnOrder}
  198. columnSortBy={[]}
  199. location={location}
  200. grid={{
  201. renderHeadCell,
  202. renderBodyCell,
  203. }}
  204. />
  205. );
  206. }
  207. const StyledIconQuestion = styled(QuestionTooltip)`
  208. position: relative;
  209. left: 4px;
  210. `;