allEventsTable.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import {useEffect, useMemo, useState} from 'react';
  2. import type {Location} from 'history';
  3. import {getSampleEventQuery} from 'sentry/components/events/eventStatisticalDetector/eventComparison/eventDisplay';
  4. import LoadingError from 'sentry/components/loadingError';
  5. import {
  6. PlatformCategory,
  7. profiling as PROFILING_PLATFORMS,
  8. } from 'sentry/data/platformCategories';
  9. import {t} from 'sentry/locale';
  10. import type {EventTransaction} from 'sentry/types/event';
  11. import type {Group} from 'sentry/types/group';
  12. import {IssueCategory, IssueType} from 'sentry/types/group';
  13. import type {Organization} from 'sentry/types/organization';
  14. import type {PlatformKey} from 'sentry/types/project';
  15. import EventView from 'sentry/utils/discover/eventView';
  16. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  17. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  18. import {platformToCategory} from 'sentry/utils/platform';
  19. import {useApiQuery} from 'sentry/utils/queryClient';
  20. import {decodeSorts} from 'sentry/utils/queryString';
  21. import {projectCanLinkToReplay} from 'sentry/utils/replays/projectSupportsReplay';
  22. import {useRoutes} from 'sentry/utils/useRoutes';
  23. import EventsTable from 'sentry/views/performance/transactionSummary/transactionEvents/eventsTable';
  24. interface Props {
  25. group: Group;
  26. issueId: string;
  27. location: Location;
  28. organization: Organization;
  29. excludedTags?: string[];
  30. }
  31. const makeGroupPreviewRequestUrl = ({groupId}: {groupId: string}) => {
  32. return `/issues/${groupId}/events/latest/`;
  33. };
  34. function AllEventsTable(props: Props) {
  35. const {location, organization, issueId, excludedTags, group} = props;
  36. const config = getConfigForIssueType(props.group, group.project);
  37. const [error, setError] = useState<string>('');
  38. const routes = useRoutes();
  39. const {fields, columnTitles} = useEventColumns(group, organization);
  40. const now = useMemo(() => Date.now(), []);
  41. const endpointUrl = makeGroupPreviewRequestUrl({
  42. groupId: group.id,
  43. });
  44. const queryEnabled = group.issueCategory === IssueCategory.PERFORMANCE;
  45. const {data, isPending, isLoadingError} = useApiQuery<EventTransaction>([endpointUrl], {
  46. staleTime: 60000,
  47. enabled: queryEnabled,
  48. });
  49. // TODO: this is a temporary way to check whether
  50. // perf issue is backed by occurrences or transactions
  51. // Once migration to the issue platform is complete a call to /latest should be removed
  52. const groupIsOccurrenceBacked = !!data?.occurrence;
  53. const eventView: EventView = EventView.fromLocation(props.location);
  54. if (config.usesIssuePlatform) {
  55. eventView.dataset = DiscoverDatasets.ISSUE_PLATFORM;
  56. }
  57. eventView.fields = fields.map(fieldName => ({field: fieldName}));
  58. eventView.sorts = decodeSorts(location.query.sort).filter(sort =>
  59. fields.includes(sort.field)
  60. );
  61. useEffect(() => {
  62. setError('');
  63. }, [eventView.query]);
  64. if (!eventView.sorts.length) {
  65. eventView.sorts = [{field: 'timestamp', kind: 'desc'}];
  66. }
  67. eventView.statsPeriod = '90d';
  68. const isRegressionIssue =
  69. group.issueType === IssueType.PERFORMANCE_DURATION_REGRESSION ||
  70. group.issueType === IssueType.PERFORMANCE_ENDPOINT_REGRESSION;
  71. let idQuery = `issue.id:${issueId}`;
  72. if (group.issueCategory === IssueCategory.PERFORMANCE && !groupIsOccurrenceBacked) {
  73. idQuery = `performance.issue_ids:${issueId} event.type:transaction`;
  74. } else if (isRegressionIssue && groupIsOccurrenceBacked) {
  75. const {transaction, aggregateRange2, breakpoint} =
  76. data?.occurrence?.evidenceData ?? {};
  77. // Surface the "bad" events that occur after the breakpoint
  78. idQuery = getSampleEventQuery({
  79. transaction,
  80. durationBaseline: aggregateRange2,
  81. addUpperBound: false,
  82. });
  83. eventView.dataset = DiscoverDatasets.DISCOVER;
  84. eventView.start = new Date(breakpoint * 1000).toISOString();
  85. eventView.end = new Date(now).toISOString();
  86. eventView.statsPeriod = undefined;
  87. }
  88. eventView.project = [parseInt(group.project.id, 10)];
  89. eventView.query = `${idQuery} ${props.location.query.query || ''}`;
  90. if (error || isLoadingError) {
  91. return (
  92. <LoadingError message={error || isLoadingError} onRetry={() => setError('')} />
  93. );
  94. }
  95. return (
  96. <EventsTable
  97. eventView={eventView}
  98. location={location}
  99. issueId={issueId}
  100. isRegressionIssue={isRegressionIssue}
  101. organization={organization}
  102. routes={routes}
  103. excludedTags={excludedTags}
  104. projectSlug={group.project.slug}
  105. customColumns={['minidump']}
  106. setError={(msg: string | undefined) => setError(msg ?? '')}
  107. transactionName=""
  108. columnTitles={columnTitles.slice()}
  109. referrer="api.issues.issue_events"
  110. isEventLoading={queryEnabled ? isPending : false}
  111. />
  112. );
  113. }
  114. type ColumnInfo = {columnTitles: string[]; fields: string[]};
  115. export const useEventColumns = (group: Group, organization: Organization): ColumnInfo => {
  116. return useMemo(() => {
  117. const isPerfIssue = group.issueCategory === IssueCategory.PERFORMANCE;
  118. const isReplayEnabled =
  119. organization.features.includes('session-replay') &&
  120. projectCanLinkToReplay(organization, group.project);
  121. // profiles only exist on transactions, so this only works with
  122. // performance issues, and not errors
  123. const isProfilingEnabled = isPerfIssue && organization.features.includes('profiling');
  124. const {fields: platformSpecificFields, columnTitles: platformSpecificColumnTitles} =
  125. getPlatformColumns(group.project.platform ?? group.platform, {
  126. isProfilingEnabled,
  127. isReplayEnabled,
  128. });
  129. const fields: string[] = [
  130. 'id',
  131. 'timestamp',
  132. 'title',
  133. 'transaction',
  134. 'release',
  135. 'environment',
  136. 'user.display',
  137. 'device',
  138. 'os',
  139. ...platformSpecificFields,
  140. 'trace',
  141. ...(isPerfIssue ? ['transaction.duration'] : []),
  142. ];
  143. const columnTitles: string[] = [
  144. t('Event ID'),
  145. t('Timestamp'),
  146. t('Title'),
  147. t('Transaction'),
  148. t('Release'),
  149. t('Environment'),
  150. t('User'),
  151. t('Device'),
  152. t('OS'),
  153. ...platformSpecificColumnTitles,
  154. t('Trace'),
  155. ...(isPerfIssue ? [t('Total Duration')] : []),
  156. t('Minidump'),
  157. ];
  158. return {
  159. fields,
  160. columnTitles,
  161. };
  162. }, [group, organization]);
  163. };
  164. const getPlatformColumns = (
  165. platform: PlatformKey | undefined,
  166. options: {isProfilingEnabled: boolean; isReplayEnabled: boolean}
  167. ): ColumnInfo => {
  168. const backendServerlessColumnInfo = {
  169. fields: ['url', 'runtime'],
  170. columnTitles: [t('URL'), t('Runtime')],
  171. };
  172. const categoryToColumnMap: Record<PlatformCategory, ColumnInfo> = {
  173. [PlatformCategory.BACKEND]: backendServerlessColumnInfo,
  174. [PlatformCategory.SERVERLESS]: backendServerlessColumnInfo,
  175. [PlatformCategory.FRONTEND]: {
  176. fields: ['url', 'browser'],
  177. columnTitles: [t('URL'), t('Browser')],
  178. },
  179. [PlatformCategory.MOBILE]: {
  180. fields: ['url'],
  181. columnTitles: [t('URL')],
  182. },
  183. [PlatformCategory.DESKTOP]: {
  184. fields: [],
  185. columnTitles: [],
  186. },
  187. [PlatformCategory.OTHER]: {
  188. fields: [],
  189. columnTitles: [],
  190. },
  191. };
  192. const platformCategory = platformToCategory(platform);
  193. const platformColumns = categoryToColumnMap[platformCategory];
  194. if (options.isReplayEnabled) {
  195. platformColumns.fields.push('replayId');
  196. platformColumns.columnTitles.push(t('Replay'));
  197. }
  198. if (options.isProfilingEnabled && platform && PROFILING_PLATFORMS.includes(platform)) {
  199. platformColumns.columnTitles.push(t('Profile'));
  200. platformColumns.fields.push('profile.id');
  201. }
  202. return platformColumns;
  203. };
  204. export default AllEventsTable;