Skip to content

Commit cf8fd0d

Browse files
committed
Merge pull request #97 from SparkartGroupInc/sentry-integration
Sentry integration
2 parents 7910117 + ab80667 commit cf8fd0d

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

lib/preprocessor.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var Preprocessor = function( preprocessor_path, options ){
2121

2222
var server = options.server;
2323
var logger = server.logger;
24+
var raven_client = server.raven_client;
2425
var preprocessor = this;
2526
var data = this.data = '{}';
2627
this.path = preprocessor_path;
@@ -29,8 +30,17 @@ var Preprocessor = function( preprocessor_path, options ){
2930
this.process = function( context, callback ){
3031

3132
workers( context, this.path, function( err, preprocessed_context ){
32-
if( err ){
33+
// preprocessor errors don't bubble up
34+
// so log them here
35+
if( err ){
3336
logger.log( 'Preprocessor Error:\n'+ err.stack, 0 );
37+
if( raven_client ){
38+
raven_client.captureError( err, {
39+
extra: {
40+
context: context
41+
}
42+
});
43+
}
3444
if( callback ) return callback( context );
3545
}
3646
if( callback ) return callback( preprocessed_context );

lib/server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const DEFAULT_PORT = 8080;
44
const DEFAULT_LIVERELOAD_PORT = 35729;
55
const DEFAULT_DEV_ASSETS_MAX_AGE = 0;
66
const DEFAULT_PROD_ASSETS_MAX_AGE = 1000 * 60 * 60 * 24 * 365; // 1 year, in ms
7+
const SENTRY_DSN = process.env.SENTRY_DSN;
8+
const SENTRY_LEVEL = process.env.SENTRY_LEVEL;
79

810
// native
911
var fs = require('fs');
@@ -26,6 +28,7 @@ handlebars_helper.help( Handlebars );
2628
var express_handlebars = require('express3-handlebars');
2729
var chokidar = require('chokidar');
2830
var glob = require('glob');
31+
var raven = require('raven');
2932

3033
// our party! \o/
3134
var Page = require('./page.js');
@@ -99,6 +102,15 @@ var SolidusServer = function( options ){
99102
}));
100103
// catch-all middleware at the end of the stack for 404 handling
101104
router.use( router.router );
105+
// log express errors to sentry
106+
// log uncaught exceptions to sentry and exit
107+
if( SENTRY_DSN ){
108+
router.use( raven.middleware.express( SENTRY_DSN ) );
109+
var raven_client = solidus_server.raven_client = new raven.Client( SENTRY_DSN );
110+
raven_client.patchGlobal( function(){
111+
process.exit(1);
112+
});
113+
}
102114
router.use( function( req, res, next ){
103115
res.status( 404 );
104116
// it's cheaper to check this than to fs.exists the notfound path

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"glob": "~3.2.6",
3535
"handlebars": "~1.0.12",
3636
"handlebars-helper": "~0.0.9",
37-
"worker-farm": "~0.3.1"
37+
"worker-farm": "~0.3.1",
38+
"raven": "^0.6.2"
3839
},
3940
"devDependencies": {
4041
"mocha": "~1.9.0",

0 commit comments

Comments
 (0)