Adding Sentry
This commit is contained in:
parent
c26bf26bd1
commit
6cff032efb
@ -8,6 +8,7 @@
|
||||
"eslint:recommended",
|
||||
"plugin:react/recommended"
|
||||
],
|
||||
"parser": "babel-eslint",
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
|
@ -1 +1,8 @@
|
||||
require('./src/site.css');
|
||||
import * as Sentry from '@sentry/browser';
|
||||
|
||||
import 'site.css';
|
||||
|
||||
export const onClientEntry = () => {
|
||||
Sentry.getCurrentHub().getClient().getOptions().enabled =
|
||||
(navigator.doNotTrack !== '1' && window.doNotTrack !== '1');
|
||||
};
|
||||
|
@ -19,6 +19,15 @@ module.exports = {
|
||||
anonymize: true,
|
||||
respectDNT: true
|
||||
}
|
||||
},
|
||||
{
|
||||
resolve: 'gatsby-plugin-sentry',
|
||||
options: {
|
||||
dsn: process.env.SENTRY_DSN,
|
||||
environment: process.env.DEPLOY_ENV || process.env.NODE_ENV,
|
||||
debug: (process.env.NODE_ENV !== 'production'),
|
||||
release: buildId
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
@ -35,6 +35,7 @@
|
||||
"gatsby-plugin-google-analytics": "^2.0.8",
|
||||
"gatsby-plugin-postcss": "^2.0.2",
|
||||
"gatsby-plugin-react-helmet": "^3.0.5",
|
||||
"gatsby-plugin-sentry": "^1.0.0",
|
||||
"postcss-cssnext": "^3.1.0",
|
||||
"postcss-import": "^12.0.1",
|
||||
"prop-types": "^15.6.2",
|
||||
|
@ -2,17 +2,20 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Helmet } from 'react-helmet';
|
||||
|
||||
import SentryBoundary from 'components/SentryBoundary';
|
||||
import Header from 'components/Header';
|
||||
import Footer from 'components/Footer';
|
||||
|
||||
const Layout = ({ title, children }) => <React.Fragment>
|
||||
const Layout = ({ title, children }) => <SentryBoundary>
|
||||
<Helmet>
|
||||
<title>{ title ? `Regexper - ${ title }` : 'Regexper' }</title>
|
||||
</Helmet>
|
||||
<Header />
|
||||
{ children }
|
||||
<SentryBoundary>
|
||||
{ children }
|
||||
</SentryBoundary>
|
||||
<Footer />
|
||||
</React.Fragment>;
|
||||
</SentryBoundary>;
|
||||
|
||||
Layout.propTypes = {
|
||||
title: PropTypes.string,
|
||||
|
39
src/components/SentryBoundary/index.js
Normal file
39
src/components/SentryBoundary/index.js
Normal file
@ -0,0 +1,39 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import * as Sentry from '@sentry/browser';
|
||||
|
||||
import SentryError from 'components/SentryError';
|
||||
|
||||
class SentryBoundary extends React.Component {
|
||||
state = {
|
||||
hasError: false
|
||||
}
|
||||
|
||||
static getDerivedStateFromError() {
|
||||
return { hasError: true };
|
||||
}
|
||||
|
||||
componentDidCatch(error, errorInfo) {
|
||||
Sentry.captureException(error, errorInfo);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { hasError } = this.state;
|
||||
const { children } = this.props;
|
||||
|
||||
if (hasError) {
|
||||
return <SentryError />;
|
||||
} else {
|
||||
return children;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SentryBoundary.propTypes = {
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.arrayOf(PropTypes.node),
|
||||
PropTypes.node
|
||||
]).isRequired
|
||||
};
|
||||
|
||||
export default SentryBoundary;
|
22
src/components/SentryError/index.js
Normal file
22
src/components/SentryError/index.js
Normal file
@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
import * as Sentry from '@sentry/browser';
|
||||
|
||||
import Message from 'components/Message';
|
||||
|
||||
class SentryError extends React.Component {
|
||||
reportError = event => {
|
||||
event.preventDefault();
|
||||
|
||||
if (Sentry.lastEventId()) {
|
||||
Sentry.showReportDialog();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return <Message type="error" heading="An error has occurred">
|
||||
<p>This error has been logged. You may also <a href="#error-report" onClick={ this.reportError }>fill out a report</a>.</p>
|
||||
</Message>;
|
||||
}
|
||||
}
|
||||
|
||||
export default SentryError;
|
61
yarn.lock
61
yarn.lock
@ -806,6 +806,58 @@
|
||||
react-lifecycles-compat "^3.0.4"
|
||||
warning "^3.0.0"
|
||||
|
||||
"@sentry/browser@latest":
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-4.4.2.tgz#8d361778962ef8ab1540e4ebbf64d485903abdf1"
|
||||
integrity sha512-km5p3hPz+aoY4UiEvYxAdRJAbIK30urZSuMs/3zAUVe+8Zij0IHjHmdi9JtrMqpn+rAcWCxtRmFSYlkiKjdSUg==
|
||||
dependencies:
|
||||
"@sentry/core" "4.4.2"
|
||||
"@sentry/types" "4.4.2"
|
||||
"@sentry/utils" "4.4.2"
|
||||
tslib "^1.9.3"
|
||||
|
||||
"@sentry/core@4.4.2":
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-4.4.2.tgz#562526bc634c087f04bbca68b09cedc4b41cc64d"
|
||||
integrity sha512-hJyAodTCf4sZfVdf41Rtuzj4EsyzYq5rdMZ+zc2Vinwdf8D0/brHe91fHeO0CKXEb2P0wJsrjwMidG/ccq/M8A==
|
||||
dependencies:
|
||||
"@sentry/hub" "4.4.2"
|
||||
"@sentry/minimal" "4.4.2"
|
||||
"@sentry/types" "4.4.2"
|
||||
"@sentry/utils" "4.4.2"
|
||||
tslib "^1.9.3"
|
||||
|
||||
"@sentry/hub@4.4.2":
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-4.4.2.tgz#1399556fda06fb83c4f186c4aa842725f520159c"
|
||||
integrity sha512-oe9ytXkTWyD+QmOpVzHAqTbRV4Hc0ee2Nt6HvrDtRmlXzQxfvTWG2F8KYT6w8kzqg5klnuRpnsmgTTV3KuNBVQ==
|
||||
dependencies:
|
||||
"@sentry/types" "4.4.2"
|
||||
"@sentry/utils" "4.4.2"
|
||||
tslib "^1.9.3"
|
||||
|
||||
"@sentry/minimal@4.4.2":
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-4.4.2.tgz#13fffc6b17a2401b6a79947838a637626ab80b10"
|
||||
integrity sha512-GEZZiNvVgqFAESZhAe3vjwTInn13lI2bSI3ItQN4RUWKL/W4n/fwVoDJbkb1U8aWxanuMnRDEpKwyQv6zYTZfw==
|
||||
dependencies:
|
||||
"@sentry/hub" "4.4.2"
|
||||
"@sentry/types" "4.4.2"
|
||||
tslib "^1.9.3"
|
||||
|
||||
"@sentry/types@4.4.2":
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-4.4.2.tgz#f38dd3bc671cd2f5983a85553aebeac9c2286b17"
|
||||
integrity sha512-QyQd6PKKIyjJgaq/RQjsxPJEWbXcuiWZ9RvSnhBjS5jj53HEzkM1qkbAFqlYHJ1DTJJ1EuOM4+aTmGzHe93zuA==
|
||||
|
||||
"@sentry/utils@4.4.2":
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-4.4.2.tgz#e05a47e135ecef29e63a996f59aee8c8f792c222"
|
||||
integrity sha512-j/Ad8G1abHlJdD2q7aWWbSOSeWB5M5v1R1VKL8YPlwEbSvvmEQWePhBKFI0qlnKd2ObdUQsj86pHEXJRSFNfCw==
|
||||
dependencies:
|
||||
"@sentry/types" "4.4.2"
|
||||
tslib "^1.9.3"
|
||||
|
||||
"@types/configstore@^2.1.1":
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/configstore/-/configstore-2.1.1.tgz#cd1e8553633ad3185c3f2f239ecff5d2643e92b6"
|
||||
@ -4718,6 +4770,13 @@ gatsby-plugin-react-helmet@^3.0.5:
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.0.0"
|
||||
|
||||
gatsby-plugin-sentry@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/gatsby-plugin-sentry/-/gatsby-plugin-sentry-1.0.0.tgz#746307a27f5382a9a787fa86ac812b947f8bebc5"
|
||||
integrity sha512-6eq9RBpXXL76Ag0jp33NoWofji1jr2dhkfcJBhzAtKlztgRpkiOwm0OXrBspAa0Nu6PEPrJsEWoLAZ96w8Hj9w==
|
||||
dependencies:
|
||||
"@sentry/browser" latest
|
||||
|
||||
gatsby-react-router-scroll@^2.0.2:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/gatsby-react-router-scroll/-/gatsby-react-router-scroll-2.0.2.tgz#d8046ce2f3bfa52ef6ec55804007d976b0bb6bef"
|
||||
@ -9806,7 +9865,7 @@ trim-right@^1.0.1:
|
||||
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
|
||||
integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=
|
||||
|
||||
tslib@^1.6.0, tslib@^1.9.0:
|
||||
tslib@^1.6.0, tslib@^1.9.0, tslib@^1.9.3:
|
||||
version "1.9.3"
|
||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
|
||||
integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==
|
||||
|
Loading…
Reference in New Issue
Block a user