Package Exports
- raven
- raven/lib/utils
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (raven) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Raven
Log errors and stack traces in Sentry from within your Node.js applications. Includes middleware support for Connect/Express.
All processing and sending happens asynchronously to not slow things down if/when Sentry is down or slow.
Installation
$ npm install ravenBasic Usage
var raven = require('raven');
var client = new raven.Client('{{ SENTRY_DSN }}');
client.createFromText('Hello, world!');Error logging
Logging an error
client.createFromError(new Error('Broke!'));Sentry Identifier
client.createFromText('Hello, world!', function(result) {
console.log(client.getIdent(result));
});client.createFromError(new Error('Broke!'), function(result) {
console.log(client.getIdent(result));
});Note: client.createFromText will also return the result directly without the need for a callback, such as: var result = client.createFromText('Hello, world!');
Catching global errors
For those times when you don't catch all errors in your application. ;)
client.patchGlobals();
// or
raven.patchGlobals(client);
// or
raven.patchGlobals('{{ SENTRY_DSN }}');Methods
new raven.Client(dsn[, options])
client.createFromText(string[,callback])
client.createFromError(Error[,callback])Integrations
Connect/Express middleware
The Raven middleware can be used as-is with either Connect or Express in the same way. Take note that in your middlewares, Raven must appear after your main handler to pick up any errors that may result from handling a request.
Connect
var connect = require('connect');
function mainHandler(req, res) {
throw new Error('Broke!');
}
function onError(err, req, res, next) {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500;
res.end(res.sentry+'\n');
}
connect(
connect.bodyParser(),
connect.cookieParser(),
mainHandler,
raven.middleware.connect('{{ SENTRY_DSN }}'),
onError, // optional error handler if you want to display the error id to a user
).listen(3000);Express
var app = require('express').createServer();
app.error(raven.middleware.express('{{ SENTRY_DSN }}'));
app.error(onError); // optional error handler if you want to display the error id to a user
app.get('/', function mainHandler(req, res) {
throw new Error('Broke!');
});
app.listen(3000);Todo
- Support for process.env.SENTRY_DSN
- More complete test coverage
- Travis CI
- More comments in code
- More third party integration
- Logging support for SQL