eventSamples.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {t} from 'sentry/locale';
  2. import type {NewQuery} from 'sentry/types';
  3. import {defined} from 'sentry/utils';
  4. import EventView, {fromSorts} from 'sentry/utils/discover/eventView';
  5. import type {Sort} from 'sentry/utils/discover/fields';
  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 {
  12. PRIMARY_RELEASE_ALIAS,
  13. SECONDARY_RELEASE_ALIAS,
  14. } from 'sentry/views/starfish/components/releaseSelector';
  15. import {useReleaseSelection} from 'sentry/views/starfish/queries/useReleases';
  16. import {SpanMetricsField} from 'sentry/views/starfish/types';
  17. import {COLD_START_TYPE} from 'sentry/views/starfish/views/appStartup/screenSummary/startTypeSelector';
  18. import {EventSamplesTable} from 'sentry/views/starfish/views/screens/screenLoadSpans/eventSamplesTable';
  19. import {useTableQuery} from 'sentry/views/starfish/views/screens/screensTable';
  20. const DEFAULT_SORT: Sort = {
  21. kind: 'desc',
  22. field: 'span.duration',
  23. };
  24. type Props = {
  25. cursorName: string;
  26. sortKey: string;
  27. transaction: string;
  28. footerAlignedPagination?: boolean;
  29. release?: string;
  30. showDeviceClassSelector?: boolean;
  31. };
  32. export function EventSamples({
  33. cursorName,
  34. transaction,
  35. release,
  36. sortKey,
  37. showDeviceClassSelector,
  38. footerAlignedPagination,
  39. }: Props) {
  40. const location = useLocation();
  41. const {selection} = usePageFilters();
  42. const {primaryRelease} = useReleaseSelection();
  43. const cursor = decodeScalar(location.query?.[cursorName]);
  44. const deviceClass = decodeScalar(location.query[SpanMetricsField.DEVICE_CLASS]) ?? '';
  45. const startType =
  46. decodeScalar(location.query[SpanMetricsField.APP_START_TYPE]) ?? COLD_START_TYPE;
  47. const searchQuery = new MutableSearch([
  48. `transaction:${transaction}`,
  49. `release:${release}`,
  50. startType
  51. ? `${SpanMetricsField.SPAN_OP}:${
  52. startType === COLD_START_TYPE ? 'app.start.cold' : 'app.start.warm'
  53. }`
  54. : 'span.op:[app.start.cold,app.start.warm]',
  55. '(',
  56. 'span.description:"Cold Start"',
  57. 'OR',
  58. 'span.description:"Warm Start"',
  59. ')',
  60. ...(deviceClass ? [`${SpanMetricsField.DEVICE_CLASS}:${deviceClass}`] : []),
  61. // TODO: Add this back in once we have the ability to filter by start type
  62. // `${SpanMetricsField.APP_START_TYPE}:${
  63. // startType || `[${COLD_START_TYPE},${WARM_START_TYPE}]`
  64. // }`,
  65. ]);
  66. const sort = fromSorts(decodeScalar(location.query[sortKey]))[0] ?? DEFAULT_SORT;
  67. const columnNameMap = {
  68. 'transaction.id': t(
  69. 'Event ID (%s)',
  70. release === primaryRelease ? PRIMARY_RELEASE_ALIAS : SECONDARY_RELEASE_ALIAS
  71. ),
  72. profile_id: t('Profile'),
  73. 'span.duration': t('Duration'),
  74. };
  75. const newQuery: NewQuery = {
  76. name: '',
  77. fields: ['transaction.id', 'project.name', 'profile_id', 'span.duration'],
  78. query: searchQuery.formatString(),
  79. dataset: DiscoverDatasets.SPANS_INDEXED,
  80. version: 2,
  81. projects: selection.projects,
  82. };
  83. const eventView = EventView.fromNewQueryWithLocation(newQuery, location);
  84. eventView.sorts = [sort];
  85. const {data, isLoading, pageLinks} = useTableQuery({
  86. eventView,
  87. enabled: defined(release),
  88. limit: 4,
  89. cursor,
  90. referrer: 'api.starfish.mobile-startup-event-samples',
  91. initialData: {data: []},
  92. });
  93. return (
  94. <EventSamplesTable
  95. cursorName={cursorName}
  96. eventIdKey="transaction.id"
  97. eventView={eventView}
  98. isLoading={defined(release) && isLoading}
  99. profileIdKey="profile_id"
  100. sortKey={sortKey}
  101. data={data}
  102. pageLinks={pageLinks}
  103. showDeviceClassSelector={showDeviceClassSelector}
  104. columnNameMap={columnNameMap}
  105. sort={sort}
  106. footerAlignedPagination={footerAlignedPagination}
  107. />
  108. );
  109. }