From 60b552027b03745ac6b7933d08d3a13792e558de Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 12 Mar 2014 17:20:49 +0100 Subject: [PATCH] Add optional support for rollbar Re-targets to 1.10.0 Also installs an uncaught exception handler Closes #150 --- NEWS.md | 7 +++- app.js | 16 +++++++- config/environments/production.js.example | 9 +++++ config/environments/staging.js.example | 9 +++++ lib/cartodb/log4js_rollbar.js | 49 +++++++++++++++++++++++ npm-shrinkwrap.json | 13 +++++- package.json | 5 ++- 7 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 lib/cartodb/log4js_rollbar.js diff --git a/NEWS.md b/NEWS.md index 2fae4aa5..e6fcb303 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,14 @@ -1.9.1 -- 2014-MM-DD +1.10.0 -- 2014-MM-DD ------------------- +New features: + + - Add optional support for rollbar (#150) + Enhancements: - Include tiler version in startup log + - Install an uncaught exception handler 1.9.0 -- 2014-03-10 ------------------- diff --git a/app.js b/app.js index 70f75558..cf9724f2 100755 --- a/app.js +++ b/app.js @@ -30,13 +30,22 @@ global.environment = require(__dirname + '/config/environments/' + ENV); _.extend(global.settings, global.environment); global.log4js = require('log4js') -log4js.configure({ +log4js_config = { appenders: [ { type: "console", layout: { type:'basic' } } ], replaceConsole:true -}); +}; +if ( global.environment.rollbar ) { + log4js_config.appenders.push({ + type: __dirname + "/lib/cartodb/log4js_rollbar.js", + options: global.environment.rollbar + }); +} + +log4js.configure(log4js_config); +global.logger = log4js.getLogger(); // Include cartodb_windshaft only _after_ the "global" variable is set // See https://github.com/Vizzuality/Windshaft-cartodb/issues/28 @@ -71,3 +80,6 @@ process.on('SIGUSR2', function() { ws.dumpCacheStats(); }); +process.on('uncaughtException', function(err) { + logger.error('Caught exception: ' + err); +}); diff --git a/config/environments/production.js.example b/config/environments/production.js.example index e828f2c8..1f3403d9 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -122,6 +122,15 @@ var config = { https: 'cartocdn.global.ssl.fastly.net' } } + // Optional rollbar support + ,rollbar: { + token: 'secret', + // See http://github.com/rollbar/node_rollbar#configuration-reference + options: { + endpoint: 'https://api.rollbar.com/api/1/', + handler: 'inline' + } + } }; module.exports = config; diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index dabaf9bf..397327da 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -122,6 +122,15 @@ var config = { https: 'cartocdn.global.ssl.fastly.net' } } + // Optional rollbar support + ,rollbar: { + token: 'secret', + // See http://github.com/rollbar/node_rollbar#configuration-reference + options: { + endpoint: 'https://api.rollbar.com/api/1/', + handler: 'inline' + } + } }; module.exports = config; diff --git a/lib/cartodb/log4js_rollbar.js b/lib/cartodb/log4js_rollbar.js new file mode 100644 index 00000000..08ccc13d --- /dev/null +++ b/lib/cartodb/log4js_rollbar.js @@ -0,0 +1,49 @@ +var rollbar = require("rollbar"); + +/** + * Rollbar Appender. Sends logging events to Rollbar using node-rollbar + * + * @param config object with rollbar configuration data + * { + * token: 'your-secret-token', + * options: node-rollbar options + * } + */ +function rollbarAppender(config) { + + var opt = config.options; + rollbar.init(opt.token, opt.options); + + return function(loggingEvent) { +/* +For logger.trace('one','two','three'): +{ startTime: Wed Mar 12 2014 16:27:40 GMT+0100 (CET), + categoryName: '[default]', + data: [ 'one', 'two', 'three' ], + level: { level: 5000, levelStr: 'TRACE' }, + logger: { category: '[default]', _events: { log: [Object] } } } +*/ + + // Levels: + // TRACE 5000 + // DEBUG 10000 + // INFO 20000 + // WARN 30000 + // ERROR 40000 + // FATAL 50000 + // + // We only log error and higher errors + // + if ( loggingEvent.level.level < 40000 ) return; + + rollbar.reportMessage(loggingEvent.data); + }; +} + +function configure(config) { + return rollbarAppender(config); +} + +exports.name = "rollbar"; +exports.appender = rollbarAppender; +exports.configure = configure; diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 899f6271..f493447e 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "windshaft-cartodb", - "version": "1.9.0", + "version": "1.10.0", "dependencies": { "node-varnish": { "version": "0.2.0", @@ -425,6 +425,17 @@ } } }, + "rollbar": { + "version": "0.3.1", + "dependencies": { + "node-uuid": { + "version": "1.4.1" + }, + "lru-cache": { + "version": "2.2.4" + } + } + }, "strftime": { "version": "0.6.2" }, diff --git a/package.json b/package.json index ff939c2f..36c2843e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "windshaft-cartodb", - "version": "1.9.1", + "version": "1.10.0", "description": "A map tile server for CartoDB", "keywords": [ "cartodb" @@ -31,7 +31,8 @@ "redis-mpool": "http://github.com/CartoDB/node-redis-mpool/tarball/0.0.4", "mapnik": "~0.7.22", "lzma": "~1.2.3", - "log4js": "~0.6.10" + "log4js": "~0.6.10", + "rollbar": "~0.3.1" }, "devDependencies": { "mocha": "1.14.0",