eventEntries.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. import {Fragment, useCallback, useEffect, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import {Location} from 'history';
  5. import uniq from 'lodash/uniq';
  6. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  7. import {Client} from 'sentry/api';
  8. import ErrorBoundary from 'sentry/components/errorBoundary';
  9. import EventContexts from 'sentry/components/events/contexts';
  10. import EventContextSummary from 'sentry/components/events/contextSummary';
  11. import EventDevice from 'sentry/components/events/device';
  12. import EventErrors, {Error} from 'sentry/components/events/errors';
  13. import EventAttachments from 'sentry/components/events/eventAttachments';
  14. import EventCause from 'sentry/components/events/eventCause';
  15. import EventCauseEmpty from 'sentry/components/events/eventCauseEmpty';
  16. import EventDataSection from 'sentry/components/events/eventDataSection';
  17. import EventExtraData from 'sentry/components/events/eventExtraData';
  18. import {EventSdk} from 'sentry/components/events/eventSdk';
  19. import {EventTags} from 'sentry/components/events/eventTags';
  20. import EventGroupingInfo from 'sentry/components/events/groupingInfo';
  21. import {EventPackageData} from 'sentry/components/events/packageData';
  22. import RRWebIntegration from 'sentry/components/events/rrwebIntegration';
  23. import EventSdkUpdates from 'sentry/components/events/sdkUpdates';
  24. import {DataSection} from 'sentry/components/events/styles';
  25. import EventUserFeedback from 'sentry/components/events/userFeedback';
  26. import ExternalLink from 'sentry/components/links/externalLink';
  27. import {t, tct} from 'sentry/locale';
  28. import space from 'sentry/styles/space';
  29. import {
  30. Entry,
  31. EntryType,
  32. Event,
  33. ExceptionValue,
  34. Group,
  35. IssueAttachment,
  36. IssueCategory,
  37. Organization,
  38. Project,
  39. SharedViewOrganization,
  40. Thread,
  41. } from 'sentry/types';
  42. import {DebugFile} from 'sentry/types/debugFiles';
  43. import {Image} from 'sentry/types/debugImage';
  44. import {isNotSharedOrganization} from 'sentry/types/utils';
  45. import {defined, objectIsEmpty} from 'sentry/utils';
  46. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  47. import withApi from 'sentry/utils/withApi';
  48. import withOrganization from 'sentry/utils/withOrganization';
  49. import {projectProcessingIssuesMessages} from 'sentry/views/settings/project/projectProcessingIssues';
  50. import findBestThread from './interfaces/threads/threadSelector/findBestThread';
  51. import getThreadException from './interfaces/threads/threadSelector/getThreadException';
  52. import EventEntry from './eventEntry';
  53. import EventReplay from './eventReplay';
  54. import EventTagsAndScreenshot from './eventTagsAndScreenshot';
  55. const MINIFIED_DATA_JAVA_EVENT_REGEX_MATCH =
  56. /^(([\w\$]\.[\w\$]{1,2})|([\w\$]{2}\.[\w\$]\.[\w\$]))(\.|$)/g;
  57. function isDataMinified(str: string | null) {
  58. if (!str) {
  59. return false;
  60. }
  61. return !![...str.matchAll(MINIFIED_DATA_JAVA_EVENT_REGEX_MATCH)].length;
  62. }
  63. function hasThreadOrExceptionMinifiedFrameData(definedEvent: Event, bestThread?: Thread) {
  64. if (!bestThread) {
  65. const exceptionValues: Array<ExceptionValue> =
  66. definedEvent.entries?.find(e => e.type === EntryType.EXCEPTION)?.data?.values ?? [];
  67. return !!exceptionValues.find(exceptionValue =>
  68. exceptionValue.stacktrace?.frames?.find(frame => isDataMinified(frame.module))
  69. );
  70. }
  71. const threadExceptionValues = getThreadException(definedEvent, bestThread)?.values;
  72. return !!(threadExceptionValues
  73. ? threadExceptionValues.find(threadExceptionValue =>
  74. threadExceptionValue.stacktrace?.frames?.find(frame =>
  75. isDataMinified(frame.module)
  76. )
  77. )
  78. : bestThread?.stacktrace?.frames?.find(frame => isDataMinified(frame.module)));
  79. }
  80. type ProGuardErrors = Array<Error>;
  81. type Props = Pick<React.ComponentProps<typeof EventEntry>, 'route' | 'router'> & {
  82. api: Client;
  83. location: Location;
  84. /**
  85. * The organization can be the shared view on a public issue view.
  86. */
  87. organization: Organization | SharedViewOrganization;
  88. project: Project;
  89. className?: string;
  90. event?: Event;
  91. group?: Group;
  92. isShare?: boolean;
  93. showExampleCommit?: boolean;
  94. showTagSummary?: boolean;
  95. };
  96. const EventEntries = ({
  97. organization,
  98. project,
  99. location,
  100. api,
  101. event,
  102. group,
  103. className,
  104. router,
  105. route,
  106. isShare = false,
  107. showExampleCommit = false,
  108. showTagSummary = true,
  109. }: Props) => {
  110. const [isLoading, setIsLoading] = useState(true);
  111. const [proGuardErrors, setProGuardErrors] = useState<ProGuardErrors>([]);
  112. const [attachments, setAttachments] = useState<IssueAttachment[]>([]);
  113. const orgSlug = organization.slug;
  114. const projectSlug = project.slug;
  115. const orgFeatures = organization?.features ?? [];
  116. const hasEventAttachmentsFeature = orgFeatures.includes('event-attachments');
  117. const replayId = event?.tags?.find(({key}) => key === 'replayId')?.value;
  118. const recordIssueError = useCallback(() => {
  119. if (!event || !event.errors || !(event.errors.length > 0)) {
  120. return;
  121. }
  122. const errors = event.errors;
  123. const errorTypes = errors.map(errorEntries => errorEntries.type);
  124. const errorMessages = errors.map(errorEntries => errorEntries.message);
  125. const platform = project.platform;
  126. // uniquify the array types
  127. trackAdvancedAnalyticsEvent('issue_error_banner.viewed', {
  128. organization: organization as Organization,
  129. group: event?.groupID,
  130. error_type: uniq(errorTypes),
  131. error_message: uniq(errorMessages),
  132. ...(platform && {platform}),
  133. });
  134. }, [event, organization, project.platform]);
  135. const fetchProguardMappingFiles = useCallback(
  136. async (query: string): Promise<Array<DebugFile>> => {
  137. try {
  138. const proguardMappingFiles = await api.requestPromise(
  139. `/projects/${orgSlug}/${projectSlug}/files/dsyms/`,
  140. {
  141. method: 'GET',
  142. query: {
  143. query,
  144. file_formats: 'proguard',
  145. },
  146. }
  147. );
  148. return proguardMappingFiles;
  149. } catch (error) {
  150. Sentry.captureException(error);
  151. // do nothing, the UI will not display extra error details
  152. return [];
  153. }
  154. },
  155. [api, orgSlug, projectSlug]
  156. );
  157. const checkProGuardError = useCallback(async () => {
  158. if (!event || event.platform !== 'java') {
  159. setIsLoading(false);
  160. return;
  161. }
  162. const hasEventErrorsProGuardMissingMapping = event.errors?.find(
  163. error => error.type === 'proguard_missing_mapping'
  164. );
  165. if (hasEventErrorsProGuardMissingMapping) {
  166. setIsLoading(false);
  167. return;
  168. }
  169. const newProGuardErrors: ProGuardErrors = [];
  170. const debugImages = event.entries?.find(e => e.type === EntryType.DEBUGMETA)?.data
  171. .images as undefined | Array<Image>;
  172. // When debugImages contains a 'proguard' entry, it must always be only one entry
  173. const proGuardImage = debugImages?.find(
  174. debugImage => debugImage?.type === 'proguard'
  175. );
  176. const proGuardImageUuid = proGuardImage?.uuid;
  177. // If an entry is of type 'proguard' and has 'uuid',
  178. // it means that the Sentry Gradle plugin has been executed,
  179. // otherwise the proguard id wouldn't be in the event.
  180. // But maybe it failed to upload the mappings file
  181. if (defined(proGuardImageUuid)) {
  182. if (isShare) {
  183. setIsLoading(false);
  184. return;
  185. }
  186. const proguardMappingFiles = await fetchProguardMappingFiles(proGuardImageUuid);
  187. if (!proguardMappingFiles.length) {
  188. newProGuardErrors.push({
  189. type: 'proguard_missing_mapping',
  190. message: projectProcessingIssuesMessages.proguard_missing_mapping,
  191. data: {mapping_uuid: proGuardImageUuid},
  192. });
  193. }
  194. setProGuardErrors(newProGuardErrors);
  195. setIsLoading(false);
  196. return;
  197. }
  198. if (proGuardImage) {
  199. Sentry.withScope(function (s) {
  200. s.setLevel('warning');
  201. if (event.sdk) {
  202. s.setTag('offending.event.sdk.name', event.sdk.name);
  203. s.setTag('offending.event.sdk.version', event.sdk.version);
  204. }
  205. Sentry.captureMessage('Event contains proguard image but not uuid');
  206. });
  207. }
  208. const threads: Array<Thread> =
  209. event.entries?.find(e => e.type === EntryType.THREADS)?.data?.values ?? [];
  210. const bestThread = findBestThread(threads);
  211. const hasThreadOrExceptionMinifiedData = hasThreadOrExceptionMinifiedFrameData(
  212. event,
  213. bestThread
  214. );
  215. if (hasThreadOrExceptionMinifiedData) {
  216. newProGuardErrors.push({
  217. type: 'proguard_potentially_misconfigured_plugin',
  218. message: tct(
  219. 'Some frames appear to be minified. Did you configure the [plugin]?',
  220. {
  221. plugin: (
  222. <ExternalLink href="https://docs.sentry.io/platforms/android/proguard/#gradle">
  223. Sentry Gradle Plugin
  224. </ExternalLink>
  225. ),
  226. }
  227. ),
  228. });
  229. }
  230. setProGuardErrors(newProGuardErrors);
  231. setIsLoading(false);
  232. }, [event, fetchProguardMappingFiles, isShare]);
  233. const fetchAttachments = useCallback(async () => {
  234. if (!event || isShare || !hasEventAttachmentsFeature) {
  235. return;
  236. }
  237. try {
  238. const response = await api.requestPromise(
  239. `/projects/${orgSlug}/${projectSlug}/events/${event.id}/attachments/`
  240. );
  241. setAttachments(response);
  242. } catch (error) {
  243. Sentry.captureException(error);
  244. addErrorMessage('An error occurred while fetching attachments');
  245. }
  246. }, [api, event, hasEventAttachmentsFeature, isShare, orgSlug, projectSlug]);
  247. const handleDeleteAttachment = useCallback(
  248. async (attachmentId: IssueAttachment['id']) => {
  249. if (!event) {
  250. return;
  251. }
  252. try {
  253. await api.requestPromise(
  254. `/projects/${orgSlug}/${projectSlug}/events/${event.id}/attachments/${attachmentId}/`,
  255. {
  256. method: 'DELETE',
  257. }
  258. );
  259. setAttachments(attachments.filter(attachment => attachment.id !== attachmentId));
  260. } catch (error) {
  261. Sentry.captureException(error);
  262. addErrorMessage('An error occurred while deleting the attachment');
  263. }
  264. },
  265. [api, attachments, event, orgSlug, projectSlug]
  266. );
  267. useEffect(() => {
  268. checkProGuardError();
  269. }, [checkProGuardError]);
  270. useEffect(() => {
  271. recordIssueError();
  272. }, [recordIssueError]);
  273. useEffect(() => {
  274. fetchAttachments();
  275. }, [fetchAttachments]);
  276. if (!event) {
  277. return (
  278. <LatestEventNotAvailable>
  279. <h3>{t('Latest Event Not Available')}</h3>
  280. </LatestEventNotAvailable>
  281. );
  282. }
  283. const hasMobileScreenshotsFeature = orgFeatures.includes('mobile-screenshots');
  284. const hasContext = !objectIsEmpty(event.user ?? {}) || !objectIsEmpty(event.contexts);
  285. const hasErrors = !objectIsEmpty(event.errors) || !!proGuardErrors.length;
  286. return (
  287. <div className={className} data-test-id={`event-entries-loading-${isLoading}`}>
  288. {hasErrors && !isLoading && (
  289. <EventErrors
  290. event={event}
  291. orgSlug={orgSlug}
  292. projectSlug={projectSlug}
  293. proGuardErrors={proGuardErrors}
  294. />
  295. )}
  296. {!isShare &&
  297. isNotSharedOrganization(organization) &&
  298. (showExampleCommit ? (
  299. <EventCauseEmpty event={event} organization={organization} project={project} />
  300. ) : (
  301. <EventCause project={project} event={event} group={group} />
  302. ))}
  303. {event.userReport && group && (
  304. <StyledEventUserFeedback
  305. report={event.userReport}
  306. orgId={orgSlug}
  307. issueId={group.id}
  308. includeBorder={!hasErrors}
  309. />
  310. )}
  311. {showTagSummary &&
  312. (hasMobileScreenshotsFeature ? (
  313. <EventTagsAndScreenshot
  314. event={event}
  315. organization={organization as Organization}
  316. projectId={projectSlug}
  317. location={location}
  318. isShare={isShare}
  319. hasContext={hasContext}
  320. attachments={attachments}
  321. onDeleteScreenshot={handleDeleteAttachment}
  322. />
  323. ) : (
  324. (!!(event.tags ?? []).length || hasContext) && (
  325. <StyledEventDataSection title={t('Tags')} type="tags">
  326. {hasContext && <EventContextSummary event={event} />}
  327. <EventTags
  328. event={event}
  329. organization={organization as Organization}
  330. projectId={projectSlug}
  331. location={location}
  332. />
  333. </StyledEventDataSection>
  334. )
  335. ))}
  336. <Entries
  337. definedEvent={event}
  338. projectSlug={projectSlug}
  339. group={group}
  340. organization={organization}
  341. route={route}
  342. router={router}
  343. />
  344. {hasContext && <EventContexts group={group} event={event} />}
  345. {event && !objectIsEmpty(event.context) && <EventExtraData event={event} />}
  346. {event && !objectIsEmpty(event.packages) && <EventPackageData event={event} />}
  347. {event && !objectIsEmpty(event.device) && <EventDevice event={event} />}
  348. {!isShare && hasEventAttachmentsFeature && (
  349. <EventAttachments
  350. event={event}
  351. orgId={orgSlug}
  352. projectId={projectSlug}
  353. location={location}
  354. attachments={attachments}
  355. onDeleteAttachment={handleDeleteAttachment}
  356. />
  357. )}
  358. {event.sdk && !objectIsEmpty(event.sdk) && (
  359. <EventSdk sdk={event.sdk} meta={event._meta?.sdk} />
  360. )}
  361. {!isShare && event?.sdkUpdates && event.sdkUpdates.length > 0 && (
  362. <EventSdkUpdates event={{sdkUpdates: event.sdkUpdates, ...event}} />
  363. )}
  364. {!isShare &&
  365. event.groupID &&
  366. group?.issueCategory !== IssueCategory.PERFORMANCE && (
  367. <EventGroupingInfo
  368. projectId={projectSlug}
  369. event={event}
  370. showGroupingConfig={orgFeatures.includes('set-grouping-config')}
  371. />
  372. )}
  373. {!isShare && (
  374. <MiniReplayView
  375. event={event}
  376. orgFeatures={orgFeatures}
  377. orgSlug={orgSlug}
  378. projectSlug={projectSlug}
  379. replayId={replayId}
  380. />
  381. )}
  382. </div>
  383. );
  384. };
  385. function Entries({
  386. definedEvent,
  387. projectSlug,
  388. group,
  389. organization,
  390. route,
  391. router,
  392. }: {
  393. definedEvent: Event;
  394. projectSlug: string;
  395. } & Pick<Props, 'group' | 'organization' | 'route' | 'router'>) {
  396. const entries = definedEvent.entries;
  397. if (!Array.isArray(entries)) {
  398. return null;
  399. }
  400. return (
  401. <Fragment>
  402. {(entries as Array<Entry>).map((entry, entryIdx) => (
  403. <ErrorBoundary
  404. key={`entry-${entryIdx}`}
  405. customComponent={
  406. <EventDataSection type={entry.type} title={entry.type}>
  407. <p>{t('There was an error rendering this data.')}</p>
  408. </EventDataSection>
  409. }
  410. >
  411. <EventEntry
  412. projectSlug={projectSlug}
  413. group={group}
  414. organization={organization}
  415. event={definedEvent}
  416. entry={entry}
  417. route={route}
  418. router={router}
  419. />
  420. </ErrorBoundary>
  421. ))}
  422. </Fragment>
  423. );
  424. }
  425. type MiniReplayViewProps = {
  426. event: Event;
  427. orgFeatures: string[];
  428. orgSlug: string;
  429. projectSlug: string;
  430. replayId: undefined | string;
  431. };
  432. function MiniReplayView({
  433. event,
  434. orgFeatures,
  435. orgSlug,
  436. projectSlug,
  437. replayId,
  438. }: MiniReplayViewProps) {
  439. const hasEventAttachmentsFeature = orgFeatures.includes('event-attachments');
  440. const hasSessionReplayFeature = orgFeatures.includes('session-replay-ui');
  441. if (replayId && hasSessionReplayFeature) {
  442. return (
  443. <EventReplay replayId={replayId} orgSlug={orgSlug} projectSlug={projectSlug} />
  444. );
  445. }
  446. if (hasEventAttachmentsFeature) {
  447. return (
  448. <RRWebIntegration
  449. event={event}
  450. orgId={orgSlug}
  451. projectId={projectSlug}
  452. renderer={children => (
  453. <StyledReplayEventDataSection type="context-replay" title={t('Replay')}>
  454. {children}
  455. </StyledReplayEventDataSection>
  456. )}
  457. />
  458. );
  459. }
  460. return null;
  461. }
  462. const StyledEventDataSection = styled(EventDataSection)`
  463. /* Hiding the top border because of the event section appears at this breakpoint */
  464. @media (max-width: 767px) {
  465. &:first-of-type {
  466. border-top: none;
  467. }
  468. }
  469. `;
  470. const LatestEventNotAvailable = styled('div')`
  471. padding: ${space(2)} ${space(4)};
  472. `;
  473. const ErrorContainer = styled('div')`
  474. /*
  475. Remove border on adjacent context summary box.
  476. Once that component uses emotion this will be harder.
  477. */
  478. & + .context-summary {
  479. border-top: none;
  480. }
  481. `;
  482. const BorderlessEventEntries = styled(EventEntries)`
  483. & ${DataSection} {
  484. margin-left: 0 !important;
  485. margin-right: 0 !important;
  486. padding: ${space(3)} 0 0 0;
  487. }
  488. & ${DataSection}:first-child {
  489. padding-top: 0;
  490. border-top: 0;
  491. }
  492. & ${ErrorContainer} {
  493. margin-bottom: ${space(2)};
  494. }
  495. `;
  496. type StyledEventUserFeedbackProps = {
  497. includeBorder: boolean;
  498. };
  499. const StyledEventUserFeedback = styled(EventUserFeedback)<StyledEventUserFeedbackProps>`
  500. border-radius: 0;
  501. box-shadow: none;
  502. padding: ${space(3)} ${space(4)} 0 40px;
  503. border: 0;
  504. ${p => (p.includeBorder ? `border-top: 1px solid ${p.theme.innerBorder};` : '')}
  505. margin: 0;
  506. `;
  507. const StyledReplayEventDataSection = styled(EventDataSection)`
  508. overflow: hidden;
  509. margin-bottom: ${space(3)};
  510. `;
  511. // TODO(ts): any required due to our use of SharedViewOrganization
  512. export default withOrganization<any>(withApi(EventEntries));
  513. export {BorderlessEventEntries};