spanOperationTable.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. `avg_if(mobile.slow_frames,release,${primaryRelease})`,
  65. `avg_if(mobile.slow_frames,release,${secondaryRelease})`,
  66. `avg_if(mobile.frozen_frames,release,${primaryRelease})`,
  67. `avg_if(mobile.frozen_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, isLoading, 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. [`avg_if(mobile.slow_frames,release,${primaryRelease})`]: t(
  90. 'Slow (%s)',
  91. PRIMARY_RELEASE_ALIAS
  92. ),
  93. [`avg_if(mobile.slow_frames,release,${secondaryRelease})`]: t(
  94. 'Slow (%s)',
  95. SECONDARY_RELEASE_ALIAS
  96. ),
  97. [`avg_if(mobile.frozen_frames,release,${primaryRelease})`]: t(
  98. 'Frozen (%s)',
  99. PRIMARY_RELEASE_ALIAS
  100. ),
  101. [`avg_if(mobile.frozen_frames,release,${secondaryRelease})`]: t(
  102. 'Frozen (%s)',
  103. SECONDARY_RELEASE_ALIAS
  104. ),
  105. [`avg_if(mobile.frames_delay,release,${primaryRelease})`]: t(
  106. 'Delay (%s)',
  107. PRIMARY_RELEASE_ALIAS
  108. ),
  109. [`avg_if(mobile.frames_delay,release,${secondaryRelease})`]: t(
  110. 'Delay (%s)',
  111. SECONDARY_RELEASE_ALIAS
  112. ),
  113. [`avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`]:
  114. t('Change'),
  115. };
  116. function renderBodyCell(column, row) {
  117. if (column.key === SPAN_DESCRIPTION) {
  118. const label = row[SpanMetricsField.SPAN_DESCRIPTION];
  119. const pathname = `${moduleURL}/spans/`;
  120. const query = {
  121. ...location.query,
  122. transaction,
  123. spanOp: row[SpanMetricsField.SPAN_OP],
  124. spanGroup: row[SpanMetricsField.SPAN_GROUP],
  125. spanDescription: row[SpanMetricsField.SPAN_DESCRIPTION],
  126. };
  127. return (
  128. <Link to={`${pathname}?${qs.stringify(query)}`}>
  129. <OverflowEllipsisTextContainer>{label}</OverflowEllipsisTextContainer>
  130. </Link>
  131. );
  132. }
  133. if (column.key.startsWith('avg_if(mobile.frames_delay')) {
  134. return (
  135. <NumberContainer>
  136. {typeof row[column.key] === 'number' ? (
  137. <Duration seconds={row[column.key]} fixedDigits={2} abbreviation />
  138. ) : (
  139. '-'
  140. )}
  141. </NumberContainer>
  142. );
  143. }
  144. return null;
  145. }
  146. return (
  147. <ScreensTable
  148. columnNameMap={columnNameMap}
  149. data={data}
  150. eventView={eventView}
  151. isLoading={isLoading}
  152. pageLinks={pageLinks}
  153. columnOrder={[
  154. String(SPAN_OP),
  155. String(SPAN_DESCRIPTION),
  156. `avg_if(mobile.slow_frames,release,${primaryRelease})`,
  157. `avg_if(mobile.slow_frames,release,${secondaryRelease})`,
  158. `avg_if(mobile.frozen_frames,release,${primaryRelease})`,
  159. `avg_if(mobile.frozen_frames,release,${secondaryRelease})`,
  160. `avg_if(mobile.frames_delay,release,${primaryRelease})`,
  161. `avg_if(mobile.frames_delay,release,${secondaryRelease})`,
  162. `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  163. ]}
  164. defaultSort={[
  165. {
  166. key: `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  167. order: 'desc',
  168. },
  169. ]}
  170. customBodyCellRenderer={renderBodyCell}
  171. moduleName={ModuleName.MOBILE_UI}
  172. />
  173. );
  174. }