allEventsTable.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import {useEffect, 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 endpointUrl = makeGroupPreviewRequestUrl({
  43. groupId: group.id,
  44. });
  45. const queryEnabled = group.issueCategory === IssueCategory.PERFORMANCE;
  46. const {data, isLoading, isLoadingError} = useApiQuery<EventTransaction>([endpointUrl], {
  47. staleTime: 60000,
  48. enabled: queryEnabled,
  49. });
  50. // TODO: this is a temporary way to check whether
  51. // perf issue is backed by occurrences or transactions
  52. // Once migration to the issue platform is complete a call to /latest should be removed
  53. const groupIsOccurrenceBacked = !!data?.occurrence;
  54. const eventView: EventView = EventView.fromLocation(props.location);
  55. if (
  56. config.usesIssuePlatform ||
  57. (group.issueCategory === IssueCategory.PERFORMANCE && groupIsOccurrenceBacked)
  58. ) {
  59. eventView.dataset = DiscoverDatasets.ISSUE_PLATFORM;
  60. }
  61. eventView.fields = fields.map(fieldName => ({field: fieldName}));
  62. eventView.sorts = decodeSorts(location).filter(sort => fields.includes(sort.field));
  63. useEffect(() => {
  64. setError('');
  65. }, [eventView.query]);
  66. if (!eventView.sorts.length) {
  67. eventView.sorts = [{field: 'timestamp', kind: 'desc'}];
  68. }
  69. eventView.statsPeriod = '90d';
  70. let idQuery = `issue.id:${issueId}`;
  71. if (group.issueCategory === IssueCategory.PERFORMANCE && !groupIsOccurrenceBacked) {
  72. idQuery = `performance.issue_ids:${issueId} event.type:transaction`;
  73. } else if (
  74. group.issueType === IssueType.PERFORMANCE_DURATION_REGRESSION &&
  75. groupIsOccurrenceBacked
  76. ) {
  77. const {transaction, aggregateRange2, breakpoint, requestEnd} =
  78. data?.occurrence?.evidenceData ?? {};
  79. // Surface the "bad" events that occur after the breakpoint
  80. idQuery = getSampleEventQuery({
  81. transaction,
  82. durationBaseline: aggregateRange2,
  83. addUpperBound: false,
  84. });
  85. eventView.dataset = DiscoverDatasets.DISCOVER;
  86. eventView.start = new Date(breakpoint * 1000).toISOString();
  87. eventView.end = new Date(requestEnd * 1000).toISOString();
  88. eventView.statsPeriod = undefined;
  89. }
  90. eventView.project = [parseInt(group.project.id, 10)];
  91. eventView.query = `${idQuery} ${props.location.query.query || ''}`;
  92. if (error || isLoadingError) {
  93. return (
  94. <LoadingError message={error || isLoadingError} onRetry={() => setError('')} />
  95. );
  96. }
  97. return (
  98. <EventsTable
  99. eventView={eventView}
  100. location={location}
  101. issueId={issueId}
  102. organization={organization}
  103. routes={routes}
  104. excludedTags={excludedTags}
  105. projectSlug={group.project.slug}
  106. customColumns={['minidump']}
  107. setError={(msg: string | undefined) => setError(msg ?? '')}
  108. transactionName=""
  109. columnTitles={columnTitles.slice()}
  110. referrer="api.issues.issue_events"
  111. isEventLoading={queryEnabled ? isLoading : false}
  112. />
  113. );
  114. }
  115. type ColumnInfo = {columnTitles: string[]; fields: string[]};
  116. const getColumns = (group: Group, organization: Organization): ColumnInfo => {
  117. const isPerfIssue = group.issueCategory === IssueCategory.PERFORMANCE;
  118. const isReplayEnabled =
  119. organization.features.includes('session-replay') &&
  120. projectCanLinkToReplay(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. 'transaction',
  132. 'title',
  133. 'release',
  134. 'environment',
  135. 'user.display',
  136. 'device',
  137. 'os',
  138. ...platformSpecificFields,
  139. ...(isPerfIssue ? ['transaction.duration'] : []),
  140. 'timestamp',
  141. ];
  142. const columnTitles: string[] = [
  143. t('event id'),
  144. t('transaction'),
  145. t('title'),
  146. t('release'),
  147. t('environment'),
  148. t('user'),
  149. t('device'),
  150. t('os'),
  151. ...platformSpecificColumnTitles,
  152. ...(isPerfIssue ? [t('total duration')] : []),
  153. t('timestamp'),
  154. t('minidump'),
  155. ];
  156. return {
  157. fields,
  158. columnTitles,
  159. };
  160. };
  161. const getPlatformColumns = (
  162. platform: PlatformKey | undefined,
  163. options: {isProfilingEnabled: boolean; isReplayEnabled: boolean}
  164. ): ColumnInfo => {
  165. const backendServerlessColumnInfo = {
  166. fields: ['url', 'runtime'],
  167. columnTitles: [t('url'), t('runtime')],
  168. };
  169. const categoryToColumnMap: Record<PlatformCategory, ColumnInfo> = {
  170. [PlatformCategory.BACKEND]: backendServerlessColumnInfo,
  171. [PlatformCategory.SERVERLESS]: backendServerlessColumnInfo,
  172. [PlatformCategory.FRONTEND]: {
  173. fields: ['url', 'browser'],
  174. columnTitles: [t('url'), t('browser')],
  175. },
  176. [PlatformCategory.MOBILE]: {
  177. fields: ['url'],
  178. columnTitles: [t('url')],
  179. },
  180. [PlatformCategory.DESKTOP]: {
  181. fields: [],
  182. columnTitles: [],
  183. },
  184. [PlatformCategory.OTHER]: {
  185. fields: [],
  186. columnTitles: [],
  187. },
  188. };
  189. const platformCategory = platformToCategory(platform);
  190. const platformColumns = categoryToColumnMap[platformCategory];
  191. if (options.isReplayEnabled) {
  192. platformColumns.fields.push('replayId');
  193. platformColumns.columnTitles.push(t('replay'));
  194. }
  195. if (options.isProfilingEnabled && platform && PROFILING_PLATFORMS.includes(platform)) {
  196. platformColumns.columnTitles.push(t('profile'));
  197. platformColumns.fields.push('profile.id');
  198. }
  199. return platformColumns;
  200. };
  201. export default AllEventsTable;