eventEntries.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import {Location} from 'history';
  5. import {Client} from 'app/api';
  6. import ErrorBoundary from 'app/components/errorBoundary';
  7. import EventContexts from 'app/components/events/contexts';
  8. import EventContextSummary from 'app/components/events/contextSummary/contextSummary';
  9. import EventDevice from 'app/components/events/device';
  10. import EventErrors, {Error} from 'app/components/events/errors';
  11. import EventAttachments from 'app/components/events/eventAttachments';
  12. import EventCause from 'app/components/events/eventCause';
  13. import EventCauseEmpty from 'app/components/events/eventCauseEmpty';
  14. import EventDataSection from 'app/components/events/eventDataSection';
  15. import EventExtraData from 'app/components/events/eventExtraData/eventExtraData';
  16. import EventSdk from 'app/components/events/eventSdk';
  17. import EventTags from 'app/components/events/eventTags/eventTags';
  18. import EventGroupingInfo from 'app/components/events/groupingInfo';
  19. import EventPackageData from 'app/components/events/packageData';
  20. import RRWebIntegration from 'app/components/events/rrwebIntegration';
  21. import EventSdkUpdates from 'app/components/events/sdkUpdates';
  22. import {DataSection} from 'app/components/events/styles';
  23. import EventUserFeedback from 'app/components/events/userFeedback';
  24. import ExternalLink from 'app/components/links/externalLink';
  25. import {t, tct} from 'app/locale';
  26. import space from 'app/styles/space';
  27. import {
  28. ExceptionValue,
  29. Group,
  30. Organization,
  31. Project,
  32. SharedViewOrganization,
  33. } from 'app/types';
  34. import {DebugFile} from 'app/types/debugFiles';
  35. import {Image} from 'app/types/debugImage';
  36. import {Entry, EntryType, Event} from 'app/types/event';
  37. import {Thread} from 'app/types/events';
  38. import {isNotSharedOrganization} from 'app/types/utils';
  39. import {defined, objectIsEmpty} from 'app/utils';
  40. import {analytics} from 'app/utils/analytics';
  41. import withApi from 'app/utils/withApi';
  42. import withOrganization from 'app/utils/withOrganization';
  43. import {projectProcessingIssuesMessages} from 'app/views/settings/project/projectProcessingIssues';
  44. import findBestThread from './interfaces/threads/threadSelector/findBestThread';
  45. import getThreadException from './interfaces/threads/threadSelector/getThreadException';
  46. import EventEntry from './eventEntry';
  47. const MINIFIED_DATA_JAVA_EVENT_REGEX_MATCH = /^(([\w\$]\.[\w\$]{1,2})|([\w\$]{2}\.[\w\$]\.[\w\$]))(\.|$)/g;
  48. const defaultProps = {
  49. isShare: false,
  50. showExampleCommit: false,
  51. showTagSummary: true,
  52. };
  53. type ProGuardErrors = Array<Error>;
  54. type Props = {
  55. /**
  56. * The organization can be the shared view on a public issue view.
  57. */
  58. organization: Organization | SharedViewOrganization;
  59. project: Project;
  60. location: Location;
  61. api: Client;
  62. event?: Event;
  63. group?: Group;
  64. className?: string;
  65. } & typeof defaultProps;
  66. type State = {
  67. isLoading: boolean;
  68. proGuardErrors: ProGuardErrors;
  69. };
  70. class EventEntries extends React.Component<Props, State> {
  71. static defaultProps = defaultProps;
  72. state: State = {
  73. isLoading: true,
  74. proGuardErrors: [],
  75. };
  76. componentDidMount() {
  77. this.checkProGuardError();
  78. this.recordIssueError();
  79. }
  80. shouldComponentUpdate(nextProps: Props, nextState: State) {
  81. const {event, showExampleCommit} = this.props;
  82. return (
  83. (event && nextProps.event && event.id !== nextProps.event.id) ||
  84. showExampleCommit !== nextProps.showExampleCommit ||
  85. nextState.isLoading !== this.state.isLoading
  86. );
  87. }
  88. async fetchProguardMappingFiles(query: string): Promise<Array<DebugFile>> {
  89. const {api, organization, project} = this.props;
  90. try {
  91. const proguardMappingFiles = await api.requestPromise(
  92. `/projects/${organization.slug}/${project.slug}/files/dsyms/`,
  93. {
  94. method: 'GET',
  95. query: {
  96. query,
  97. file_formats: 'proguard',
  98. },
  99. }
  100. );
  101. return proguardMappingFiles;
  102. } catch (error) {
  103. Sentry.captureException(error);
  104. // do nothing, the UI will not display extra error details
  105. return [];
  106. }
  107. }
  108. isDataMinified(str: string | null) {
  109. if (!str) {
  110. return false;
  111. }
  112. return !![...str.matchAll(MINIFIED_DATA_JAVA_EVENT_REGEX_MATCH)].length;
  113. }
  114. hasThreadOrExceptionMinifiedFrameData(event: Event, bestThread?: Thread) {
  115. if (!bestThread) {
  116. const exceptionValues: Array<ExceptionValue> =
  117. event.entries?.find(e => e.type === EntryType.EXCEPTION)?.data?.values ?? [];
  118. return !!exceptionValues.find(exceptionValue =>
  119. exceptionValue.stacktrace?.frames?.find(frame =>
  120. this.isDataMinified(frame.module)
  121. )
  122. );
  123. }
  124. const threadExceptionValues = getThreadException(event, bestThread)?.values;
  125. return !!(threadExceptionValues
  126. ? threadExceptionValues.find(threadExceptionValue =>
  127. threadExceptionValue.stacktrace?.frames?.find(frame =>
  128. this.isDataMinified(frame.module)
  129. )
  130. )
  131. : bestThread?.stacktrace?.frames?.find(frame => this.isDataMinified(frame.module)));
  132. }
  133. async checkProGuardError() {
  134. const {event, isShare} = this.props;
  135. if (!event || event.platform !== 'java') {
  136. this.setState({isLoading: false});
  137. return;
  138. }
  139. const hasEventErrorsProGuardMissingMapping = event.errors?.find(
  140. error => error.type === 'proguard_missing_mapping'
  141. );
  142. if (hasEventErrorsProGuardMissingMapping) {
  143. this.setState({isLoading: false});
  144. return;
  145. }
  146. const proGuardErrors: ProGuardErrors = [];
  147. const debugImages = event.entries?.find(e => e.type === EntryType.DEBUGMETA)?.data
  148. .images as undefined | Array<Image>;
  149. // When debugImages contains a 'proguard' entry, it must always be only one entry
  150. const proGuardImage = debugImages?.find(
  151. debugImage => debugImage?.type === 'proguard'
  152. );
  153. const proGuardImageUuid = proGuardImage?.uuid;
  154. // If an entry is of type 'proguard' and has 'uuid',
  155. // it means that the Sentry Gradle plugin has been executed,
  156. // otherwise the proguard id wouldn't be in the event.
  157. // But maybe it failed to upload the mappings file
  158. if (defined(proGuardImageUuid)) {
  159. if (isShare) {
  160. this.setState({isLoading: false});
  161. return;
  162. }
  163. const proguardMappingFiles = await this.fetchProguardMappingFiles(
  164. proGuardImageUuid
  165. );
  166. if (!proguardMappingFiles.length) {
  167. proGuardErrors.push({
  168. type: 'proguard_missing_mapping',
  169. message: projectProcessingIssuesMessages.proguard_missing_mapping,
  170. data: {mapping_uuid: proGuardImageUuid},
  171. });
  172. }
  173. this.setState({proGuardErrors, isLoading: false});
  174. return;
  175. } else {
  176. if (proGuardImage) {
  177. Sentry.withScope(function (s) {
  178. s.setLevel(Sentry.Severity.Warning);
  179. if (event.sdk) {
  180. s.setTag('offending.event.sdk.name', event.sdk.name);
  181. s.setTag('offending.event.sdk.version', event.sdk.version);
  182. }
  183. Sentry.captureMessage('Event contains proguard image but not uuid');
  184. });
  185. }
  186. }
  187. const threads: Array<Thread> =
  188. event.entries?.find(e => e.type === EntryType.THREADS)?.data?.values ?? [];
  189. const bestThread = findBestThread(threads);
  190. const hasThreadOrExceptionMinifiedData = this.hasThreadOrExceptionMinifiedFrameData(
  191. event,
  192. bestThread
  193. );
  194. if (hasThreadOrExceptionMinifiedData) {
  195. proGuardErrors.push({
  196. type: 'proguard_potentially_misconfigured_plugin',
  197. message: tct(
  198. 'Some frames appear to be minified. Did you configure the [plugin]?',
  199. {
  200. plugin: (
  201. <ExternalLink href="https://docs.sentry.io/platforms/android/proguard/#gradle">
  202. Sentry Gradle Plugin
  203. </ExternalLink>
  204. ),
  205. }
  206. ),
  207. });
  208. // This capture will be removed once we're confident with the level of effectiveness
  209. Sentry.withScope(function (s) {
  210. s.setLevel(Sentry.Severity.Warning);
  211. if (event.sdk) {
  212. s.setTag('offending.event.sdk.name', event.sdk.name);
  213. s.setTag('offending.event.sdk.version', event.sdk.version);
  214. }
  215. Sentry.captureMessage(
  216. !proGuardImage
  217. ? 'No Proguard is used at all, but a frame did match the regex'
  218. : "Displaying ProGuard warning 'proguard_potentially_misconfigured_plugin' for suspected event"
  219. );
  220. });
  221. }
  222. this.setState({proGuardErrors, isLoading: false});
  223. }
  224. recordIssueError() {
  225. const {organization, project, event} = this.props;
  226. if (!event || !event.errors || !(event.errors.length > 0)) {
  227. return;
  228. }
  229. const errors = event.errors;
  230. const errorTypes = errors.map(errorEntries => errorEntries.type);
  231. const errorMessages = errors.map(errorEntries => errorEntries.message);
  232. const orgId = organization.id;
  233. const platform = project.platform;
  234. analytics('issue_error_banner.viewed', {
  235. org_id: orgId ? parseInt(orgId, 10) : null,
  236. group: event?.groupID,
  237. error_type: errorTypes,
  238. error_message: errorMessages,
  239. ...(platform && {platform}),
  240. });
  241. }
  242. renderEntries(event: Event) {
  243. const {project, organization, group} = this.props;
  244. const entries = event.entries;
  245. if (!Array.isArray(entries)) {
  246. return null;
  247. }
  248. return (entries as Array<Entry>).map((entry, entryIdx) => (
  249. <ErrorBoundary
  250. key={`entry-${entryIdx}`}
  251. customComponent={
  252. <EventDataSection type={entry.type} title={entry.type}>
  253. <p>{t('There was an error rendering this data.')}</p>
  254. </EventDataSection>
  255. }
  256. >
  257. <EventEntry
  258. projectSlug={project.slug}
  259. groupId={group?.id}
  260. organization={organization}
  261. event={event}
  262. entry={entry}
  263. />
  264. </ErrorBoundary>
  265. ));
  266. }
  267. render() {
  268. const {
  269. className,
  270. organization,
  271. group,
  272. isShare,
  273. project,
  274. event,
  275. showExampleCommit,
  276. showTagSummary,
  277. location,
  278. } = this.props;
  279. const {proGuardErrors, isLoading} = this.state;
  280. const features = new Set(organization?.features);
  281. const hasQueryFeature = features.has('discover-query');
  282. if (!event) {
  283. return (
  284. <div style={{padding: '15px 30px'}}>
  285. <h3>{t('Latest Event Not Available')}</h3>
  286. </div>
  287. );
  288. }
  289. const hasContext = !objectIsEmpty(event.user) || !objectIsEmpty(event.contexts);
  290. const hasErrors = !objectIsEmpty(event.errors) || !!proGuardErrors.length;
  291. return (
  292. <div className={className} data-test-id={`event-entries-loading-${isLoading}`}>
  293. {hasErrors && !isLoading && (
  294. <EventErrors
  295. event={event}
  296. orgSlug={organization.slug}
  297. projectSlug={project.slug}
  298. proGuardErrors={proGuardErrors}
  299. />
  300. )}
  301. {!isShare &&
  302. isNotSharedOrganization(organization) &&
  303. (showExampleCommit ? (
  304. <EventCauseEmpty organization={organization} project={project} />
  305. ) : (
  306. <EventCause
  307. organization={organization}
  308. project={project}
  309. event={event}
  310. group={group}
  311. />
  312. ))}
  313. {event?.userReport && group && (
  314. <StyledEventUserFeedback
  315. report={event.userReport}
  316. orgId={organization.slug}
  317. issueId={group.id}
  318. includeBorder={!hasErrors}
  319. />
  320. )}
  321. {hasContext && showTagSummary && <EventContextSummary event={event} />}
  322. {showTagSummary && (
  323. <EventTags
  324. event={event}
  325. organization={organization as Organization}
  326. projectId={project.slug}
  327. location={location}
  328. hasQueryFeature={hasQueryFeature}
  329. />
  330. )}
  331. {this.renderEntries(event)}
  332. {hasContext && <EventContexts group={group} event={event} />}
  333. {event && !objectIsEmpty(event.context) && <EventExtraData event={event} />}
  334. {event && !objectIsEmpty(event.packages) && <EventPackageData event={event} />}
  335. {event && !objectIsEmpty(event.device) && <EventDevice event={event} />}
  336. {!isShare && features.has('event-attachments') && (
  337. <EventAttachments
  338. event={event}
  339. orgId={organization.slug}
  340. projectId={project.slug}
  341. location={location}
  342. />
  343. )}
  344. {event?.sdk && !objectIsEmpty(event.sdk) && <EventSdk sdk={event.sdk} />}
  345. {!isShare && event?.sdkUpdates && event.sdkUpdates.length > 0 && (
  346. <EventSdkUpdates event={{sdkUpdates: event.sdkUpdates, ...event}} />
  347. )}
  348. {!isShare && event?.groupID && (
  349. <EventGroupingInfo
  350. projectId={project.slug}
  351. event={event}
  352. showGroupingConfig={features.has('set-grouping-config')}
  353. />
  354. )}
  355. {!isShare && features.has('event-attachments') && (
  356. <RRWebIntegration
  357. event={event}
  358. orgId={organization.slug}
  359. projectId={project.slug}
  360. />
  361. )}
  362. </div>
  363. );
  364. }
  365. }
  366. const ErrorContainer = styled('div')`
  367. /*
  368. Remove border on adjacent context summary box.
  369. Once that component uses emotion this will be harder.
  370. */
  371. & + .context-summary {
  372. border-top: none;
  373. }
  374. `;
  375. const BorderlessEventEntries = styled(EventEntries)`
  376. & ${/* sc-selector */ DataSection} {
  377. padding: ${space(3)} 0 0 0;
  378. }
  379. & ${/* sc-selector */ DataSection}:first-child {
  380. padding-top: 0;
  381. border-top: 0;
  382. }
  383. & ${/* sc-selector */ ErrorContainer} {
  384. margin-bottom: ${space(2)};
  385. }
  386. `;
  387. type StyledEventUserFeedbackProps = {
  388. includeBorder: boolean;
  389. };
  390. const StyledEventUserFeedback = styled(EventUserFeedback)<StyledEventUserFeedbackProps>`
  391. border-radius: 0;
  392. box-shadow: none;
  393. padding: 20px 30px 0 40px;
  394. border: 0;
  395. ${p => (p.includeBorder ? `border-top: 1px solid ${p.theme.innerBorder};` : '')}
  396. margin: 0;
  397. `;
  398. // TODO(ts): any required due to our use of SharedViewOrganization
  399. export default withOrganization<any>(withApi(EventEntries));
  400. export {BorderlessEventEntries};