projectProcessingIssues.tsx 14 KB

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