eventSamples.tsx 4.2 KB

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