-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tectual
committed
Oct 17, 2015
0 parents
commit 4fc71c2
Showing
5 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Logs | ||
logs | ||
*.log | ||
*.swp | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# Commenting this out is preferred by some people, see | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
# Users Environment Variables | ||
.lock-wscript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
(function() { | ||
var GoodRollbar, Hoek, SafeJson, Squeeze, _, defaults, rollbar; | ||
|
||
rollbar = require('rollbar'); | ||
|
||
Hoek = require('hoek'); | ||
|
||
Squeeze = require('good-squeeze').Squeeze; | ||
|
||
SafeJson = require('good-squeeze').SafeJson; | ||
|
||
_ = require('lodash'); | ||
|
||
defaults = { | ||
accessToken: null, | ||
exitOnUncaughtException: true, | ||
rollbar: { | ||
environment: process.env.NODE_ENV || 'development', | ||
endpoint: "https://api.rollbar.com/api/1/" | ||
} | ||
}; | ||
|
||
GoodRollbar = (function() { | ||
function GoodRollbar(events, config) { | ||
if (config == null) { | ||
config = {}; | ||
} | ||
this._settings = Hoek.applyToDefaults(defaults, config); | ||
this._streams = { | ||
squeeze: Squeeze(events), | ||
stringify: SafeJson(null, { | ||
separator: '\n' | ||
}) | ||
}; | ||
} | ||
|
||
GoodRollbar.prototype.init = function(stream, emitter, callback) { | ||
console.log('######## INIT GOOD ROLLBAR'); | ||
rollbar.handleUncaughtExceptions(this._settings.accessToken, { | ||
exitOnUncaughtException: this._settings.exitOnUncaughtException | ||
}); | ||
rollbar.init(this._settings.accessToken, this._settings.rollbar); | ||
this._streams.squeeze.on('data', (function(_this) { | ||
return function(data) { | ||
var error, request, url; | ||
error = null; | ||
_.each(data.log, function(log) { | ||
if (_.includes(log.tags, 'error')) { | ||
return error = log; | ||
} | ||
}); | ||
if (error != null) { | ||
request = null; | ||
_.each(data.log, function(log) { | ||
if (_.includes(log.tags, 'received')) { | ||
return request = log; | ||
} | ||
}); | ||
url = data.instance.split('://'); | ||
request = { | ||
headers: { | ||
host: url[1] | ||
}, | ||
url: request.data.url, | ||
method: data.method, | ||
protocol: url[0], | ||
route: { | ||
path: data.path | ||
} | ||
}; | ||
return rollbar.handleError(error.data, request); | ||
} | ||
}; | ||
})(this)); | ||
stream.pipe(this._streams.squeeze); | ||
return callback(); | ||
}; | ||
|
||
return GoodRollbar; | ||
|
||
})(); | ||
|
||
module.exports.attributes = { | ||
pkg: require('../package.json') | ||
}; | ||
|
||
module.exports = function(events, config) { | ||
if (config == null) { | ||
config = {}; | ||
} | ||
console.log('######## NEW GOOD ROLLBAR'); | ||
return new GoodRollbar(events, config); | ||
}; | ||
|
||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
gulp = require 'gulp' | ||
coffee = require 'gulp-coffee' | ||
|
||
gulp.task 'build', -> | ||
|
||
src = 'src/**' | ||
dest = 'build' | ||
|
||
gulp.src( src ) | ||
.pipe( coffee() ) | ||
.pipe( gulp.dest dest ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "good-hapi-rollbar", | ||
"version": "0.1.0", | ||
"description": "Good Rollbar reporter for Hapi.js", | ||
"main": "build/main", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:tectual/good-hapi-rollbar.git" | ||
}, | ||
"keywords": [ | ||
"good", | ||
"hapi", | ||
"rollbar", | ||
"error", | ||
"reporting" | ||
], | ||
"author": "Arash Kay <[email protected]> (http://tectual.com.au/)", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/tectual/good-hapi-rollbar/issues" | ||
}, | ||
"homepage": "https://github.com/tectual/good-hapi-rollbar", | ||
"dependencies": { | ||
"good-squeeze": "^2.1.0", | ||
"hoek": "^2.16.3", | ||
"lodash": "^3.10.1", | ||
"rollbar": "^0.5.8" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "^1.10.0", | ||
"gulp": "^3.9.0", | ||
"gulp-coffee": "^2.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
rollbar = require 'rollbar' | ||
Hoek = require 'hoek' | ||
Squeeze = require('good-squeeze').Squeeze | ||
SafeJson = require('good-squeeze').SafeJson | ||
_ = require 'lodash' | ||
|
||
defaults = { | ||
accessToken: null | ||
exitOnUncaughtException: true | ||
rollbar: { | ||
environment: process.env.NODE_ENV || 'development' | ||
endpoint: "https://api.rollbar.com/api/1/" | ||
} | ||
} | ||
|
||
class GoodRollbar | ||
|
||
constructor: (events, config={}) -> | ||
@_settings = Hoek.applyToDefaults defaults, config | ||
@_streams= | ||
squeeze: Squeeze events | ||
stringify: SafeJson(null, { separator: '\n' }) | ||
|
||
init: (stream, emitter, callback) -> | ||
console.log '######## INIT GOOD ROLLBAR' | ||
rollbar.handleUncaughtExceptions @_settings.accessToken, { exitOnUncaughtException: @_settings.exitOnUncaughtException } | ||
|
||
rollbar.init @_settings.accessToken, @_settings.rollbar | ||
|
||
@_streams.squeeze.on 'data', (data) => | ||
error = null | ||
_.each data.log, (log) -> | ||
error = log if _.includes log.tags, 'error' | ||
if error? | ||
request = null | ||
_.each data.log, (log) -> | ||
request = log if _.includes log.tags, 'received' | ||
url = data.instance.split('://') | ||
request = | ||
headers: | ||
host: url[1] | ||
url: request.data.url | ||
method: data.method | ||
protocol: url[0] | ||
route: | ||
path: data.path | ||
rollbar.handleError(error.data, request) | ||
|
||
stream.pipe(@_streams.squeeze) | ||
|
||
callback() | ||
|
||
module.exports.attributes = | ||
pkg: require('../package.json') | ||
|
||
module.exports = (events, config={}) -> | ||
console.log '######## NEW GOOD ROLLBAR' | ||
new GoodRollbar events, config |