Raven
Node v0.11 compatible
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.
Compatibility
- 0.6.x
- 0.8.x
- 0.10.x
- 0.11.x
Raven 0.6+ requires Sentry 6.0+
Installation
$ npm install raven
Methods
String dsn Object optionsclientclientclient
Basic Usage
var raven = ;var client = '{{ SENTRY_DSN }}'; client;
You can specify a level in the second optional parameter. Default level is error
There are 5 logging levels (in order):
- debug (the least serious)
- info
- warning
- error
- fatal (the most serious)
var raven = ; var client = '{{ SENTRY_DSN }}'; client
Adding extra info to messages
var raven = ; var client = '{{ SENTRY_DSN }}'; client
Logging an error
client;
Logging a query
client;
Sentry Identifier
client;
client;
Note: client.captureMessage
will also return the result directly without the need for a callback, such as: var result = client.captureMessage('Hello, world!');
Events
If you really care if the event was logged or errored out, Client emits two events, logged
and error
:
client;clientclient;
Error Event
The event error is augmented with the original Sentry response object as well as the response body and statusCode for easier debugging.
client;
Environment variables
SENTRY_DSN
Optionally declare the DSN to use for the client through the environment. Initializing the client in your app won't require setting the DSN.
SENTRY_NAME
Optionally set the name for the client to use. What is name?
SENTRY_SITE
Optionally set the site for the client to use. What is site?
Catching global errors
For those times when you don't catch all errors in your application. ;)
client;// orraven;// orraven;
It is recommended that you don't leave the process running after receiving an uncaughtException
(http://nodejs.org/api/process.html#process_event_uncaughtexception), so an optional callback is provided to allow you to hook in something like:
client;
The callback is called after the event has been sent to the Sentry server.
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 = ; { throw 'Broke!';} { // The error id is attached to `res.sentry` to be returned // and optionally displayed to the user for support. resstatusCode = 500; res;};
Express
var app = ;app;app;app; // optional error handler if you want to display the error id to a userapp;app;
Note: raven.middleware.express
or raven.middleware.connect
must be added to the middleware stack before any other error handling middlewares or there's a chance that the error will never get to Sentry.
Coffeescript
In order to use raven-node with coffee-script or another library which overwrites Error.prepareStackTrace you might run into the exception "Traceback does not support Error.prepareStackTrace being defined already."
In order to not have raven-node (and the underlying raw-stacktrace library) require Traceback you can pass your own stackFunction in the options. For example:
var client = '{{ SENTRY_DSN }}' stackFunction: Your stack ;
So for example:
var client = '{{ SENTRY_DSN }}' stackFunction: ErrorprepareStackTrace;
Disable Raven
Pass false
as the DSN (or any falsey value).
client = processenvNODE_ENV === 'production' && '{{ SENTRY_DSN }}'
Note: We don't infer this from NODE_ENV
automatically anymore. It's up to you to implement whatever logic you'd like.
Support
You can find me on IRC. I troll in #sentry
on freenode
.