spanOpSelector.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import {CompactSelect} from 'sentry/components/compactSelect';
  2. import {t} from 'sentry/locale';
  3. import type {NewQuery} from 'sentry/types/organization';
  4. import {browserHistory} from 'sentry/utils/browserHistory';
  5. import EventView from 'sentry/utils/discover/eventView';
  6. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  7. import {decodeScalar} from 'sentry/utils/queryString';
  8. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  9. import {useLocation} from 'sentry/utils/useLocation';
  10. import usePageFilters from 'sentry/utils/usePageFilters';
  11. import {COLD_START_TYPE} from 'sentry/views/performance/mobile/appStarts/screenSummary/startTypeSelector';
  12. import {TTID_CONTRIBUTING_SPAN_OPS} from 'sentry/views/performance/mobile/screenload/screenLoadSpans/spanOpSelector';
  13. import {MobileCursors} from 'sentry/views/performance/mobile/screenload/screens/constants';
  14. import {useTableQuery} from 'sentry/views/performance/mobile/screenload/screens/screensTable';
  15. import useCrossPlatformProject from 'sentry/views/performance/mobile/useCrossPlatformProject';
  16. import {SpanMetricsField} from 'sentry/views/starfish/types';
  17. import {appendReleaseFilters} from 'sentry/views/starfish/utils/releaseComparison';
  18. export const APP_START_SPANS = [
  19. ...TTID_CONTRIBUTING_SPAN_OPS,
  20. 'app.start.cold',
  21. 'app.start.warm',
  22. 'contentprovider.load',
  23. 'application.load',
  24. 'activity.load',
  25. 'process.load',
  26. ];
  27. type Props = {
  28. primaryRelease?: string;
  29. secondaryRelease?: string;
  30. transaction?: string;
  31. };
  32. export function SpanOpSelector({transaction, primaryRelease, secondaryRelease}: Props) {
  33. const location = useLocation();
  34. const {selection} = usePageFilters();
  35. const {isProjectCrossPlatform, selectedPlatform} = useCrossPlatformProject();
  36. const value = decodeScalar(location.query[SpanMetricsField.SPAN_OP]) ?? '';
  37. const appStartType =
  38. decodeScalar(location.query[SpanMetricsField.APP_START_TYPE]) ?? COLD_START_TYPE;
  39. const searchQuery = new MutableSearch([
  40. // Exclude root level spans because they're comprised of nested operations
  41. '!span.description:"Cold Start"',
  42. '!span.description:"Warm Start"',
  43. // Exclude this span because we can get TTID contributing spans instead
  44. '!span.description:"Initial Frame Render"',
  45. 'has:span.description',
  46. 'transaction.op:ui.load',
  47. `transaction:${transaction}`,
  48. `has:ttid`,
  49. `span.op:[${APP_START_SPANS.join(',')}]`,
  50. `app_start_type:${appStartType}`,
  51. ]);
  52. if (isProjectCrossPlatform) {
  53. searchQuery.addFilterValue('os.name', selectedPlatform);
  54. }
  55. const queryStringPrimary = appendReleaseFilters(
  56. searchQuery,
  57. primaryRelease,
  58. secondaryRelease
  59. );
  60. const newQuery: NewQuery = {
  61. name: '',
  62. fields: [SpanMetricsField.SPAN_OP, 'count()'],
  63. query: queryStringPrimary,
  64. dataset: DiscoverDatasets.SPANS_METRICS,
  65. version: 2,
  66. projects: selection.projects,
  67. };
  68. const eventView = EventView.fromNewQueryWithLocation(newQuery, location);
  69. const {data} = useTableQuery({
  70. eventView,
  71. enabled: true,
  72. limit: 25,
  73. referrer: 'api.starfish.get-span-operations',
  74. });
  75. const options = [
  76. {value: '', label: t('All')},
  77. ...(data?.data ?? [])
  78. .filter(datum => Boolean(datum[SpanMetricsField.SPAN_OP]))
  79. .map(datum => {
  80. return {
  81. value: datum[SpanMetricsField.SPAN_OP],
  82. label: datum[SpanMetricsField.SPAN_OP],
  83. };
  84. }),
  85. ];
  86. return (
  87. <CompactSelect
  88. triggerProps={{prefix: t('Operation')}}
  89. value={value}
  90. options={options ?? []}
  91. onChange={newValue => {
  92. browserHistory.push({
  93. ...location,
  94. query: {
  95. ...location.query,
  96. [SpanMetricsField.SPAN_OP]: newValue.value,
  97. [MobileCursors.SPANS_TABLE]: undefined,
  98. },
  99. });
  100. }}
  101. />
  102. );
  103. }