Hook up Sentry for error reporting (#1885)
This commit is contained in:
Родитель
d0cc614159
Коммит
190b8a91d4
|
@ -10,6 +10,7 @@ module.exports = {
|
|||
// Since by definition client-side code is public these config keys
|
||||
// must not contain sensitive data.
|
||||
clientConfigKeys: [
|
||||
'allowErrorSimulation',
|
||||
'appName',
|
||||
'amoCDN',
|
||||
'apiHost',
|
||||
|
|
|
@ -63,6 +63,7 @@ module.exports = {
|
|||
// Since by definition client-side code is public these config keys
|
||||
// must not contain sensitive data.
|
||||
clientConfigKeys: [
|
||||
'allowErrorSimulation',
|
||||
'amoCDN',
|
||||
'apiHost',
|
||||
'apiPath',
|
||||
|
@ -175,4 +176,10 @@ module.exports = {
|
|||
fxaConfig: null,
|
||||
|
||||
proxyEnabled: false,
|
||||
|
||||
// If true, enable a route that explicitly triggers a server error
|
||||
// to test our internal error handler.
|
||||
allowErrorSimulation: false,
|
||||
|
||||
sentryDsn: process.env.SENTRY_DSN || null,
|
||||
};
|
||||
|
|
|
@ -30,4 +30,6 @@ module.exports = {
|
|||
],
|
||||
},
|
||||
},
|
||||
|
||||
allowErrorSimulation: true,
|
||||
};
|
||||
|
|
|
@ -28,4 +28,6 @@ module.exports = {
|
|||
],
|
||||
},
|
||||
},
|
||||
|
||||
allowErrorSimulation: true,
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// Put any test configuration overrides here.
|
||||
module.exports = {
|
||||
apiHost: 'https://localhost',
|
||||
allowErrorSimulation: true,
|
||||
};
|
||||
|
|
|
@ -102,7 +102,7 @@
|
|||
"command": "mocha --compilers js:babel-register --timeout 10000 tests/server/amo",
|
||||
"env": {
|
||||
"NODE_PATH": "./:./src",
|
||||
"NODE_ENV": "production",
|
||||
"NODE_ENV": "test",
|
||||
"NODE_APP_INSTANCE": "amo",
|
||||
"TRACKING_ENABLED": "false"
|
||||
}
|
||||
|
@ -193,6 +193,7 @@
|
|||
"normalize.css": "5.0.0",
|
||||
"normalizr": "3.2.2",
|
||||
"piping": "0.3.2",
|
||||
"raven": "1.1.2",
|
||||
"react": "15.4.2",
|
||||
"react-addons-css-transition-group": "15.4.2",
|
||||
"react-cookie": "1.0.4",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import config from 'config';
|
||||
import React from 'react';
|
||||
import { IndexRoute, Route } from 'react-router';
|
||||
|
||||
import SimulateError from 'core/containers/SimulateError';
|
||||
import LoginRequired from 'core/containers/LoginRequired';
|
||||
import HandleLogin from 'core/containers/HandleLogin';
|
||||
|
||||
|
@ -19,5 +21,8 @@ export default (
|
|||
<Route path="user" component={UserPage} />
|
||||
</Route>
|
||||
<Route path="fxa-authenticate" component={HandleLogin} />
|
||||
{config.get('allowErrorSimulation') ? (
|
||||
<Route path="simulate-error/" component={SimulateError} />
|
||||
) : null}
|
||||
</Route>
|
||||
);
|
||||
|
|
|
@ -2,6 +2,7 @@ import config from 'config';
|
|||
import React from 'react';
|
||||
import { IndexRoute, Route } from 'react-router';
|
||||
|
||||
import SimulateError from 'core/containers/SimulateError';
|
||||
import HandleLogin from 'core/containers/HandleLogin';
|
||||
|
||||
import AddonReviewList from './components/AddonReviewList';
|
||||
|
@ -33,6 +34,9 @@ export default (
|
|||
<Route path="404/" component={NotFound} />
|
||||
<Route path="500/"
|
||||
component={config.get('isDevelopment') ? ServerError : NotFound} />
|
||||
{config.get('allowErrorSimulation') ? (
|
||||
<Route path="simulate-error/" component={SimulateError} />
|
||||
) : null}
|
||||
<Route path=":visibleAddonType/" component={LandingPage} />
|
||||
<Route path="*" component={NotFound} />
|
||||
</Route>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
import log from 'core/logger';
|
||||
|
||||
// This HOC can be connected to a route to test internal error handling.
|
||||
export default () => {
|
||||
log.info('Simulating an error');
|
||||
throw new Error('This is a simulated error');
|
||||
};
|
|
@ -7,6 +7,7 @@ import { oneLine } from 'common-tags';
|
|||
import config from 'config';
|
||||
import Express from 'express';
|
||||
import helmet from 'helmet';
|
||||
import Raven from 'raven';
|
||||
import cookie from 'react-cookie';
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/server';
|
||||
|
@ -115,6 +116,15 @@ function baseServer(routes, createStore, { appInstanceName = appName } = {}) {
|
|||
const app = new Express();
|
||||
app.disable('x-powered-by');
|
||||
|
||||
const sentryDsn = config.get('sentryDsn');
|
||||
if (sentryDsn) {
|
||||
Raven.config(sentryDsn).install();
|
||||
app.use(Raven.errorHandler());
|
||||
} else {
|
||||
log.warn(
|
||||
'Sentry reporting is disabled; Set config.sentryDsn to enable it.');
|
||||
}
|
||||
|
||||
app.use(logRequests);
|
||||
|
||||
// Set HTTP Strict Transport Security headers
|
||||
|
|
|
@ -4,6 +4,7 @@ import { Router, Route } from 'react-router';
|
|||
|
||||
import GenericError from 'core/components/ErrorPage/GenericError';
|
||||
import NotFound from 'core/components/ErrorPage/NotFound';
|
||||
import SimulateError from 'core/containers/SimulateError';
|
||||
|
||||
import App from './containers/App';
|
||||
import DiscoPane from './containers/DiscoPane';
|
||||
|
@ -18,6 +19,9 @@ export default (
|
|||
<Route path="/:lang/firefox/404" component={NotFound} />
|
||||
<Route path="/:lang/firefox/500"
|
||||
component={config.get('isDevelopment') ? GenericError : NotFound} />
|
||||
{config.get('allowErrorSimulation') ? (
|
||||
<Route path="/:lang/firefox/simulate-error/" component={SimulateError} />
|
||||
) : null}
|
||||
<Route path="*" component={NotFound} />
|
||||
</Router>
|
||||
);
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import React from 'react';
|
||||
import { renderIntoDocument } from 'react-addons-test-utils';
|
||||
|
||||
import SimulateError from 'core/containers/SimulateError';
|
||||
|
||||
describe('SimulateError', () => {
|
||||
it('simulates an error', () => {
|
||||
assert.throws(
|
||||
() => renderIntoDocument(<SimulateError />),
|
||||
/simulated error/);
|
||||
});
|
||||
});
|
|
@ -3,7 +3,7 @@ import request from 'supertest-as-promised';
|
|||
|
||||
import { checkSRI, parseCSP, runTestServer } from '../helpers';
|
||||
|
||||
describe('Search App GET requests', () => {
|
||||
describe('Admin views', () => {
|
||||
let app;
|
||||
|
||||
before(() => runTestServer({ app: 'admin' })
|
||||
|
@ -30,4 +30,8 @@ describe('Search App GET requests', () => {
|
|||
.get('/search')
|
||||
.expect(200)
|
||||
.then((res) => checkSRI(res)));
|
||||
|
||||
it('can simulate a thrown error', () => request(app)
|
||||
.get('/simulate-error/')
|
||||
.expect(500));
|
||||
});
|
||||
|
|
|
@ -62,4 +62,8 @@ describe('AMO GET Requests', () => {
|
|||
assert.equal(res.header.location,
|
||||
'/en-US/firefox/search/');
|
||||
}));
|
||||
|
||||
it('can simulate a thrown error', () => request(app)
|
||||
.get('/en-US/firefox/simulate-error/')
|
||||
.expect(500));
|
||||
});
|
||||
|
|
|
@ -58,4 +58,8 @@ describe('Discovery Pane GET requests', () => {
|
|||
.then((res) => {
|
||||
assert.equal(res.header['strict-transport-security'], 'max-age=31536000');
|
||||
}));
|
||||
|
||||
it('can simulate a thrown error', () => request(app)
|
||||
.get('/en-US/firefox/simulate-error/')
|
||||
.expect(500));
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче