spanOperationTable.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import * as qs from 'query-string';
  2. import {getInterval} from 'sentry/components/charts/utils';
  3. import Duration from 'sentry/components/duration';
  4. import Link from 'sentry/components/links/link';
  5. import {t} from 'sentry/locale';
  6. import type {NewQuery} from 'sentry/types/organization';
  7. import EventView from 'sentry/utils/discover/eventView';
  8. import {NumberContainer} from 'sentry/utils/discover/styles';
  9. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  10. import {decodeScalar} from 'sentry/utils/queryString';
  11. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import usePageFilters from 'sentry/utils/usePageFilters';
  14. import {
  15. PRIMARY_RELEASE_ALIAS,
  16. SECONDARY_RELEASE_ALIAS,
  17. } from 'sentry/views/insights/common/components/releaseSelector';
  18. import {OverflowEllipsisTextContainer} from 'sentry/views/insights/common/components/textAlign';
  19. import {STARFISH_CHART_INTERVAL_FIDELITY} from 'sentry/views/insights/common/utils/constants';
  20. import {appendReleaseFilters} from 'sentry/views/insights/common/utils/releaseComparison';
  21. import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
  22. import {APP_START_SPANS} from 'sentry/views/insights/mobile/appStarts/components/spanOpSelector';
  23. import type {SpanOperationTableProps} from 'sentry/views/insights/mobile/common/components/tables/samplesTables';
  24. import {ScreensTable} from 'sentry/views/insights/mobile/common/components/tables/screensTable';
  25. import {useTableQuery} from 'sentry/views/insights/mobile/screenload/components/tables/screensTable';
  26. import {MobileCursors} from 'sentry/views/insights/mobile/screenload/constants';
  27. import {Referrer} from 'sentry/views/insights/mobile/ui/referrers';
  28. import {ModuleName, SpanMetricsField} from 'sentry/views/insights/types';
  29. const {SPAN_DESCRIPTION, SPAN_GROUP, SPAN_OP, PROJECT_ID} = SpanMetricsField;
  30. const VALID_SPAN_OPS = APP_START_SPANS;
  31. export function SpanOperationTable({
  32. transaction,
  33. primaryRelease,
  34. secondaryRelease,
  35. }: SpanOperationTableProps) {
  36. const moduleURL = useModuleURL('mobile-ui');
  37. const location = useLocation();
  38. const {selection} = usePageFilters();
  39. const cursor = decodeScalar(location.query?.[MobileCursors.SPANS_TABLE]);
  40. const spanOp = decodeScalar(location.query[SpanMetricsField.SPAN_OP]) ?? '';
  41. const deviceClass = decodeScalar(location.query[SpanMetricsField.DEVICE_CLASS]) ?? '';
  42. // TODO: These filters seem to be too aggressive, check that they are ingesting properly
  43. const searchQuery = new MutableSearch([
  44. // 'has:span.description',
  45. // 'transaction.op:ui.load',
  46. `transaction:${transaction}`,
  47. `${SpanMetricsField.SPAN_OP}:${spanOp ? spanOp : `[${VALID_SPAN_OPS.join(',')}]`}`,
  48. ...(spanOp ? [`${SpanMetricsField.SPAN_OP}:${spanOp}`] : []),
  49. ...(deviceClass ? [`${SpanMetricsField.DEVICE_CLASS}:${deviceClass}`] : []),
  50. ]);
  51. const queryStringPrimary = appendReleaseFilters(
  52. searchQuery,
  53. primaryRelease,
  54. secondaryRelease
  55. );
  56. const orderby = decodeScalar(location.query.sort, '');
  57. const newQuery: NewQuery = {
  58. name: '',
  59. fields: [
  60. PROJECT_ID,
  61. SPAN_OP,
  62. SPAN_GROUP,
  63. SPAN_DESCRIPTION,
  64. `division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`,
  65. `division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`,
  66. `division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`,
  67. `division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`,
  68. `avg_if(mobile.frames_delay,release,${primaryRelease})`,
  69. `avg_if(mobile.frames_delay,release,${secondaryRelease})`,
  70. `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  71. ],
  72. query: queryStringPrimary,
  73. orderby,
  74. dataset: DiscoverDatasets.SPANS_METRICS,
  75. version: 2,
  76. projects: selection.projects,
  77. interval: getInterval(selection.datetime, STARFISH_CHART_INTERVAL_FIDELITY),
  78. };
  79. const eventView = EventView.fromNewQueryWithLocation(newQuery, location);
  80. const {data, isPending, pageLinks} = useTableQuery({
  81. eventView,
  82. enabled: true,
  83. referrer: Referrer.SPAN_OPERATION_TABLE,
  84. cursor,
  85. });
  86. const columnNameMap = {
  87. [SPAN_OP]: t('Operation'),
  88. [SPAN_DESCRIPTION]: t('Span Description'),
  89. [`division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`]: t(
  90. 'Slow (%s)',
  91. PRIMARY_RELEASE_ALIAS
  92. ),
  93. [`division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`]:
  94. t('Slow (%s)', SECONDARY_RELEASE_ALIAS),
  95. [`division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`]:
  96. t('Frozen (%s)', PRIMARY_RELEASE_ALIAS),
  97. [`division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`]:
  98. t('Frozen (%s)', SECONDARY_RELEASE_ALIAS),
  99. [`avg_if(mobile.frames_delay,release,${primaryRelease})`]: t(
  100. 'Delay (%s)',
  101. PRIMARY_RELEASE_ALIAS
  102. ),
  103. [`avg_if(mobile.frames_delay,release,${secondaryRelease})`]: t(
  104. 'Delay (%s)',
  105. SECONDARY_RELEASE_ALIAS
  106. ),
  107. [`avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`]:
  108. t('Change'),
  109. };
  110. const columnTooltipMap = {
  111. [`division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`]: t(
  112. 'The number of slow frames divided by total frames (%s)',
  113. PRIMARY_RELEASE_ALIAS
  114. ),
  115. [`division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`]:
  116. t(
  117. 'The number of slow frames divided by total frames (%s)',
  118. SECONDARY_RELEASE_ALIAS
  119. ),
  120. [`division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`]:
  121. t(
  122. 'The number of frozen frames divided by total frames (%s)',
  123. PRIMARY_RELEASE_ALIAS
  124. ),
  125. [`division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`]:
  126. t(
  127. 'The number of frozen frames divided by total frames (%s)',
  128. SECONDARY_RELEASE_ALIAS
  129. ),
  130. };
  131. function renderBodyCell(column, row) {
  132. if (column.key === SPAN_DESCRIPTION) {
  133. const label = row[SpanMetricsField.SPAN_DESCRIPTION];
  134. const pathname = `${moduleURL}/spans/`;
  135. const query = {
  136. ...location.query,
  137. transaction,
  138. spanOp: row[SpanMetricsField.SPAN_OP],
  139. spanGroup: row[SpanMetricsField.SPAN_GROUP],
  140. spanDescription: row[SpanMetricsField.SPAN_DESCRIPTION],
  141. };
  142. return (
  143. <Link to={`${pathname}?${qs.stringify(query)}`}>
  144. <OverflowEllipsisTextContainer>{label}</OverflowEllipsisTextContainer>
  145. </Link>
  146. );
  147. }
  148. if (column.key.startsWith('avg_if(mobile.frames_delay')) {
  149. return (
  150. <NumberContainer>
  151. {typeof row[column.key] === 'number' ? (
  152. <Duration seconds={row[column.key]} fixedDigits={2} abbreviation />
  153. ) : (
  154. '-'
  155. )}
  156. </NumberContainer>
  157. );
  158. }
  159. return null;
  160. }
  161. return (
  162. <ScreensTable
  163. columnNameMap={columnNameMap}
  164. columnTooltipMap={columnTooltipMap}
  165. data={data}
  166. eventView={eventView}
  167. isLoading={isPending}
  168. pageLinks={pageLinks}
  169. columnOrder={[
  170. String(SPAN_OP),
  171. String(SPAN_DESCRIPTION),
  172. `division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`,
  173. `division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`,
  174. `division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`,
  175. `division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`,
  176. `avg_if(mobile.frames_delay,release,${primaryRelease})`,
  177. `avg_if(mobile.frames_delay,release,${secondaryRelease})`,
  178. `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  179. ]}
  180. defaultSort={[
  181. {
  182. key: `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  183. order: 'desc',
  184. },
  185. ]}
  186. customBodyCellRenderer={renderBodyCell}
  187. moduleName={ModuleName.MOBILE_UI}
  188. />
  189. );
  190. }