spanOperationTable.tsx 8.8 KB

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