Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit ef34859

Browse files
vladikoffvbudhram
authored andcommitted
feat(logs): add sentry support (#499), r=@vbudhram
1 parent 4ea0661 commit ef34859

File tree

4 files changed

+197
-157
lines changed

4 files changed

+197
-157
lines changed

lib/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ const conf = convict({
339339
doc: 'Hapi: a string with the value of the "Cache-Control" header when caching is disabled',
340340
format: String,
341341
default: 'private, no-cache, no-store, must-revalidate'
342+
},
343+
sentryDsn: {
344+
doc: 'Sentry DSN for error and log reporting',
345+
default: '',
346+
format: 'String',
347+
env: 'SENTRY_DSN'
342348
}
343349
});
344350

lib/server/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
const Hapi = require('hapi');
6+
const Raven = require('raven');
67

78
const AppError = require('../error');
89
const authBearer = require('../auth_bearer');
@@ -102,6 +103,28 @@ exports.create = function createServer() {
102103
}
103104
});
104105

106+
// configure Sentry
107+
const sentryDsn = config.sentryDsn;
108+
if (sentryDsn) {
109+
Raven.config(sentryDsn, {});
110+
server.on('request-error', function (request, err) {
111+
let exception = '';
112+
if (err && err.stack) {
113+
try {
114+
exception = err.stack.split('\n')[0];
115+
} catch (e) {
116+
// ignore bad stack frames
117+
}
118+
}
119+
120+
Raven.captureException(err, {
121+
extra: {
122+
exception: exception
123+
}
124+
});
125+
});
126+
}
127+
105128
server.ext('onPreResponse', function onPreResponse(request, next) {
106129
var response = request.response;
107130
if (response.isBoom) {

0 commit comments

Comments
 (0)