projectProcessingIssues.tsx 14 KB

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