transactionSamplesTable.tsx 5.2 KB

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