allEventsTable.tsx 7.0 KB

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