projectProcessingIssues.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. import {Component, Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {addLoadingMessage, clearIndicators} from 'sentry/actionCreators/indicator';
  5. import {Client} from 'sentry/api';
  6. import Access from 'sentry/components/acl/access';
  7. import AlertLink from 'sentry/components/alertLink';
  8. import {Button} from 'sentry/components/button';
  9. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  10. import Form from 'sentry/components/forms/form';
  11. import JsonForm from 'sentry/components/forms/jsonForm';
  12. import ExternalLink from 'sentry/components/links/externalLink';
  13. import LoadingError from 'sentry/components/loadingError';
  14. import LoadingIndicator from 'sentry/components/loadingIndicator';
  15. import Panel from 'sentry/components/panels/panel';
  16. import PanelAlert from 'sentry/components/panels/panelAlert';
  17. import PanelTable from 'sentry/components/panels/panelTable';
  18. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  19. import Tag from 'sentry/components/tag';
  20. import TimeSince from 'sentry/components/timeSince';
  21. import Version from 'sentry/components/version';
  22. import formGroups from 'sentry/data/forms/processingIssues';
  23. import {IconQuestion} from 'sentry/icons';
  24. import {t, tn} from 'sentry/locale';
  25. import {Organization, ProcessingIssue, ProcessingIssueItem} from 'sentry/types';
  26. import withApi from 'sentry/utils/withApi';
  27. import withOrganization from 'sentry/utils/withOrganization';
  28. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  29. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  30. export const projectProcessingIssuesMessages = {
  31. native_no_crashed_thread: t('No crashed thread found in crash report'),
  32. native_internal_failure: t('Internal failure when attempting to symbolicate: {error}'),
  33. native_bad_dsym: t('The debug information file used was broken.'),
  34. native_missing_optionally_bundled_dsym: t(
  35. 'An optional debug information file was missing.'
  36. ),
  37. native_missing_dsym: t('A required debug information file was missing.'),
  38. native_missing_system_dsym: t('A system debug information file was missing.'),
  39. native_missing_symbol: t(
  40. 'Could not resolve one or more frames in debug information file.'
  41. ),
  42. native_simulator_frame: t('Encountered an unprocessable simulator frame.'),
  43. native_unknown_image: t('A binary image is referenced that is unknown.'),
  44. proguard_missing_mapping: t('A proguard mapping file was missing.'),
  45. proguard_missing_lineno: t('A proguard mapping file does not contain line info.'),
  46. };
  47. const HELP_LINKS = {
  48. native_missing_dsym: 'https://docs.sentry.io/platforms/apple/dsym/',
  49. native_bad_dsym: 'https://docs.sentry.io/platforms/apple/dsym/',
  50. native_missing_system_dsym: 'https://develop.sentry.dev/self-hosted/',
  51. native_missing_symbol: 'https://develop.sentry.dev/self-hosted/',
  52. };
  53. type Props = {
  54. api: Client;
  55. organization: Organization;
  56. } & RouteComponentProps<{projectId: string}, {}>;
  57. type State = {
  58. error: boolean;
  59. expected: number;
  60. formData: object;
  61. loading: boolean;
  62. pageLinks: null | string;
  63. processingIssues: null | ProcessingIssue;
  64. reprocessing: boolean;
  65. };
  66. class ProjectProcessingIssues extends Component<Props, State> {
  67. state: State = {
  68. formData: {},
  69. loading: true,
  70. reprocessing: false,
  71. expected: 0,
  72. error: false,
  73. processingIssues: null,
  74. pageLinks: null,
  75. };
  76. componentDidMount() {
  77. this.fetchData();
  78. }
  79. fetchData = () => {
  80. const {organization} = this.props;
  81. const {projectId} = this.props.params;
  82. this.setState({
  83. expected: this.state.expected + 2,
  84. });
  85. this.props.api.request(`/projects/${organization.slug}/${projectId}/`, {
  86. success: data => {
  87. const expected = this.state.expected - 1;
  88. this.setState({
  89. expected,
  90. loading: expected > 0,
  91. formData: data.options,
  92. });
  93. },
  94. error: () => {
  95. const expected = this.state.expected - 1;
  96. this.setState({
  97. expected,
  98. error: true,
  99. loading: expected > 0,
  100. });
  101. },
  102. });
  103. this.props.api.request(
  104. `/projects/${organization.slug}/${projectId}/processingissues/?detailed=1`,
  105. {
  106. success: (data, _, resp) => {
  107. const expected = this.state.expected - 1;
  108. this.setState({
  109. expected,
  110. error: false,
  111. loading: expected > 0,
  112. processingIssues: data,
  113. pageLinks: resp?.getResponseHeader('Link') ?? null,
  114. });
  115. },
  116. error: () => {
  117. const expected = this.state.expected - 1;
  118. this.setState({
  119. expected,
  120. error: true,
  121. loading: expected > 0,
  122. });
  123. },
  124. }
  125. );
  126. };
  127. sendReprocessing = (e: React.MouseEvent<Element>) => {
  128. e.preventDefault();
  129. this.setState({
  130. loading: true,
  131. reprocessing: true,
  132. });
  133. addLoadingMessage(t('Started reprocessing\u2026'));
  134. const {organization} = this.props;
  135. const {projectId} = this.props.params;
  136. this.props.api.request(`/projects/${organization.slug}/${projectId}/reprocessing/`, {
  137. method: 'POST',
  138. success: () => {
  139. this.fetchData();
  140. this.setState({
  141. reprocessing: false,
  142. });
  143. },
  144. error: () => {
  145. this.setState({
  146. reprocessing: false,
  147. });
  148. },
  149. complete: () => {
  150. clearIndicators();
  151. },
  152. });
  153. };
  154. discardEvents = () => {
  155. const {organization} = this.props;
  156. const {projectId} = this.props.params;
  157. this.setState({
  158. expected: this.state.expected + 1,
  159. });
  160. this.props.api.request(
  161. `/projects/${organization.slug}/${projectId}/processingissues/discard/`,
  162. {
  163. method: 'DELETE',
  164. success: () => {
  165. const expected = this.state.expected - 1;
  166. this.setState({
  167. expected,
  168. error: false,
  169. loading: expected > 0,
  170. });
  171. // TODO (billyvg): Need to fix this
  172. // we reload to get rid of the badge in the sidebar
  173. window.location.reload();
  174. },
  175. error: () => {
  176. const expected = this.state.expected - 1;
  177. this.setState({
  178. expected,
  179. error: true,
  180. loading: expected > 0,
  181. });
  182. },
  183. }
  184. );
  185. };
  186. deleteProcessingIssues = () => {
  187. const {organization} = this.props;
  188. const {projectId} = this.props.params;
  189. this.setState({
  190. expected: this.state.expected + 1,
  191. });
  192. this.props.api.request(
  193. `/projects/${organization.slug}/${projectId}/processingissues/`,
  194. {
  195. method: 'DELETE',
  196. success: () => {
  197. const expected = this.state.expected - 1;
  198. this.setState({
  199. expected,
  200. error: false,
  201. loading: expected > 0,
  202. });
  203. // TODO (billyvg): Need to fix this
  204. // we reload to get rid of the badge in the sidebar
  205. window.location.reload();
  206. },
  207. error: () => {
  208. const expected = this.state.expected - 1;
  209. this.setState({
  210. expected,
  211. error: true,
  212. loading: expected > 0,
  213. });
  214. },
  215. }
  216. );
  217. };
  218. renderDebugTable() {
  219. let body: React.ReactNode;
  220. const {loading, error, processingIssues} = this.state;
  221. if (loading) {
  222. body = this.renderLoading();
  223. } else if (error) {
  224. body = <LoadingError onRetry={this.fetchData} />;
  225. } else if (
  226. processingIssues?.hasIssues ||
  227. processingIssues?.resolveableIssues ||
  228. processingIssues?.issuesProcessing
  229. ) {
  230. body = this.renderResults();
  231. } else {
  232. body = this.renderEmpty();
  233. }
  234. return body;
  235. }
  236. renderLoading() {
  237. return (
  238. <Panel>
  239. <LoadingIndicator />
  240. </Panel>
  241. );
  242. }
  243. renderEmpty() {
  244. return (
  245. <Panel>
  246. <EmptyStateWarning>
  247. <p>{t('Good news! There are no processing issues.')}</p>
  248. </EmptyStateWarning>
  249. </Panel>
  250. );
  251. }
  252. getProblemDescription(item: ProcessingIssueItem) {
  253. const msg = projectProcessingIssuesMessages[item.type];
  254. return msg || t('Unknown Error');
  255. }
  256. getImageName(path: string) {
  257. const pathSegments = path.split(/^([a-z]:\\|\\\\)/i.test(path) ? '\\' : '/');
  258. return pathSegments[pathSegments.length - 1];
  259. }
  260. renderProblem(item: ProcessingIssueItem) {
  261. const description = this.getProblemDescription(item);
  262. const helpLink = HELP_LINKS[item.type];
  263. return (
  264. <div>
  265. <span>{description}</span>{' '}
  266. {helpLink && (
  267. <ExternalLink href={helpLink}>
  268. <IconQuestion size="xs" />
  269. </ExternalLink>
  270. )}
  271. </div>
  272. );
  273. }
  274. renderDetails(item: ProcessingIssueItem) {
  275. const {release, dist} = item.data;
  276. let dsymUUID: React.ReactNode = null;
  277. let dsymName: React.ReactNode = null;
  278. let dsymArch: React.ReactNode = null;
  279. if (item.data._scope === 'native') {
  280. if (item.data.image_uuid) {
  281. dsymUUID = <code className="uuid">{item.data.image_uuid}</code>;
  282. }
  283. if (item.data.image_path) {
  284. dsymName = <em>{this.getImageName(item.data.image_path)}</em>;
  285. }
  286. if (item.data.image_arch) {
  287. dsymArch = item.data.image_arch;
  288. }
  289. }
  290. return (
  291. <span>
  292. {dsymUUID && <span> {dsymUUID}</span>}
  293. {dsymArch && <span> {dsymArch}</span>}
  294. {dsymName && <span> (for {dsymName})</span>}
  295. {(release || dist) && (
  296. <div>
  297. <Tag tooltipText={t('Latest Release Observed with Issue')}>
  298. {release ? <Version version={release} /> : t('none')}
  299. </Tag>{' '}
  300. <Tag tooltipText={t('Latest Distribution Observed with Issue')}>
  301. {dist || t('none')}
  302. </Tag>
  303. </div>
  304. )}
  305. </span>
  306. );
  307. }
  308. renderResolveButton() {
  309. const issues = this.state.processingIssues;
  310. if (issues === null || this.state.reprocessing) {
  311. return null;
  312. }
  313. if (issues.resolveableIssues <= 0) {
  314. return null;
  315. }
  316. const fixButton = tn(
  317. 'Click here to trigger processing for %s pending event',
  318. 'Click here to trigger processing for %s pending events',
  319. issues.resolveableIssues
  320. );
  321. return (
  322. <AlertLink priority="info" onClick={this.sendReprocessing}>
  323. {t('Pro Tip')}: {fixButton}
  324. </AlertLink>
  325. );
  326. }
  327. renderResults() {
  328. const {processingIssues} = this.state;
  329. let processingRow: React.ReactNode = null;
  330. if (processingIssues && processingIssues.issuesProcessing > 0) {
  331. processingRow = (
  332. <StyledPanelAlert type="info" showIcon>
  333. {tn(
  334. 'Reprocessing %s event …',
  335. 'Reprocessing %s events …',
  336. processingIssues.issuesProcessing
  337. )}
  338. </StyledPanelAlert>
  339. );
  340. }
  341. return (
  342. <Fragment>
  343. <h3>
  344. {t('Pending Issues')}
  345. <Access access={['project:write']}>
  346. {({hasAccess}) => (
  347. <Button
  348. size="sm"
  349. className="pull-right"
  350. disabled={!hasAccess}
  351. onClick={() => this.discardEvents()}
  352. >
  353. {t('Discard all')}
  354. </Button>
  355. )}
  356. </Access>
  357. </h3>
  358. <PanelTable headers={[t('Problem'), t('Details'), t('Events'), t('Last seen')]}>
  359. {processingRow}
  360. {processingIssues?.issues?.map((item, idx) => (
  361. <Fragment key={idx}>
  362. <div>{this.renderProblem(item)}</div>
  363. <div>{this.renderDetails(item)}</div>
  364. <div>{item.numEvents + ''}</div>
  365. <div>
  366. <TimeSince date={item.lastSeen} />
  367. </div>
  368. </Fragment>
  369. ))}
  370. </PanelTable>
  371. </Fragment>
  372. );
  373. }
  374. renderReprocessingSettings() {
  375. const access = new Set(this.props.organization.access);
  376. if (this.state.loading) {
  377. return this.renderLoading();
  378. }
  379. const {formData} = this.state;
  380. const {organization} = this.props;
  381. const {projectId} = this.props.params;
  382. return (
  383. <Form
  384. saveOnBlur
  385. onSubmitSuccess={this.deleteProcessingIssues}
  386. apiEndpoint={`/projects/${organization.slug}/${projectId}/`}
  387. apiMethod="PUT"
  388. initialData={formData}
  389. >
  390. <JsonForm
  391. access={access}
  392. forms={formGroups}
  393. renderHeader={() => (
  394. <PanelAlert type="warning">
  395. <TextBlock noMargin>
  396. {t(`Reprocessing does not apply to Minidumps. Even when enabled,
  397. Minidump events with processing issues will show up in the
  398. issues stream immediately and cannot be reprocessed.`)}
  399. </TextBlock>
  400. </PanelAlert>
  401. )}
  402. />
  403. </Form>
  404. );
  405. }
  406. render() {
  407. const {projectId} = this.props.params;
  408. const title = t('Processing Issues');
  409. return (
  410. <div>
  411. <SentryDocumentTitle title={title} projectSlug={projectId} />
  412. <SettingsPageHeader title={title} />
  413. <TextBlock>
  414. {t(
  415. `For some platforms the event processing requires configuration or
  416. manual action. If a misconfiguration happens or some necessary
  417. steps are skipped, issues can occur during processing. (The most common
  418. reason for this is missing debug symbols.) In these cases you can see
  419. all the problems here with guides of how to correct them.`
  420. )}
  421. </TextBlock>
  422. {this.renderDebugTable()}
  423. {this.renderResolveButton()}
  424. {this.renderReprocessingSettings()}
  425. </div>
  426. );
  427. }
  428. }
  429. const StyledPanelAlert = styled(PanelAlert)`
  430. grid-column: 1/5;
  431. `;
  432. export {ProjectProcessingIssues};
  433. export default withApi(withOrganization(ProjectProcessingIssues));