Merge branch 'sentry-async' into 'develop'

Webpack: chunk Sentry to reduce entrypoint size

See merge request soapbox-pub/soapbox-fe!750
This commit is contained in:
Alex Gleason 2021-09-12 17:50:11 +00:00
commit 7eca5db9a9
2 changed files with 26 additions and 15 deletions

View file

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import * as Sentry from '@sentry/browser'; import { captureException } from 'soapbox/monitoring';
export default class ErrorBoundary extends React.PureComponent { export default class ErrorBoundary extends React.PureComponent {
@ -15,7 +15,7 @@ export default class ErrorBoundary extends React.PureComponent {
} }
componentDidCatch(error, info) { componentDidCatch(error, info) {
Sentry.captureException(error); captureException(error);
this.setState({ this.setState({
hasError: true, hasError: true,

View file

@ -1,8 +1,10 @@
import * as Sentry from '@sentry/react';
import { Integrations } from '@sentry/tracing';
import { NODE_ENV, SENTRY_DSN } from 'soapbox/build_config'; import { NODE_ENV, SENTRY_DSN } from 'soapbox/build_config';
export function start() { export const start = () => {
Promise.all([
import(/* webpackChunkName: "error" */'@sentry/react'),
import(/* webpackChunkName: "error" */'@sentry/tracing'),
]).then(([Sentry, { Integrations: Integrations }]) => {
Sentry.init({ Sentry.init({
dsn: SENTRY_DSN, dsn: SENTRY_DSN,
environment: NODE_ENV, environment: NODE_ENV,
@ -13,4 +15,13 @@ export function start() {
// for finer control // for finer control
tracesSampleRate: 1.0, tracesSampleRate: 1.0,
}); });
} }).catch(console.error);
};
export const captureException = error => {
import(/* webpackChunkName: "error" */'@sentry/react')
.then(Sentry => {
Sentry.captureException(error);
})
.catch(console.error);
};