Node.js client for airbrake.io
Node.js client for airbrake.io.
npm install airbrake
The common use case for this module is to catch all
events on the
process object and send them to Airbrake:
var airbrake = require'airbrake'createClient"your project ID" "your api key";airbrakehandleExceptions;throw 'I am an uncaught exception';
Please note that the above will re-throw the exception after it has been successfully delivered to Airbrake, causing your process to exit with status 1.
This can optionally be disabled by passing false to
You probably never want to use this, unless you fully understand the problems with recovering from exceptions.
If you want more control over the delivery of your errors, you can also manually submit errors to Airbrake.
var airbrake = require'airbrake'createClient"your project ID" "your api key";var err = 'Something went terribly wrong';airbrakenotifyerrif err throw err;// Error has been delivered, url links to the error in airbrake;
By default only the errors from the production environment will get reported,
so make sure to put
production in your
A custom error handler will need to be set for Express:
var airbrake = require'airbrake'createClient"your project ID" "your api key";appuseairbrakeexpressHandler;
var airbrake = require'airbrake'createClient"your project ID" "your api key";appuseapprouter;appuseairbrakeexpressHandler;
var airbrake = require'airbrake'createClient"your project ID" "your api key";app.errorairbrakeexpressHandler;
This screenshot shows an Airbrake error send from this module:
notify() method automatically adds the following context information to
each delivered error:
err.typestring if set, or
err.stackas parsed by stack-trace)
err.componentstring if set);
err.actionstring if set);
process.env, merged all other properties of
err.paramsobject if set)
err.sessionobject if set)
airbrake.projectRootstring if set)
You can add additional context information by modifying the error properties listed above:
var airbrake = require'airbrake'createClient"your project ID" "your api key";var http = require'http';httpcreateServerif reqheaders'X-Secret' !== 'my secret'var err = '403 - Permission denied';reqwriteHead403;reqenderrmessage;errurl = requrl;errparams = ip: reqsocketremoteAddress;airbrakenotifyerr;;
uncaughtException events cannot be traced back to particular
requests, so you should still try to handle errors where they occur.
This client supports Airbrake's deployment tracking:
var airbrake = require'airbrake'createClient"your project ID" "your api key";var deployment =rev: '98103a8fa850d5eaf3666e419d8a0a93e535b1b2'repo: 'firstname.lastname@example.org:felixge/node-airbrake.git';airbraketrackDeploymentdeploymentif errthrow err;console.log'Tracked deployment of %s to %s' paramsrev paramsenv;;
Check out the
airbrake.trackDeployment() API docs below for a list of all
Airbrake.createClient() returns a new Airbrake instance.
projectId- Your application's Airbrake project ID.
key- Your application's Airbrake API key.
env- The name of the server environment this is running in.
Your application's Airbrake project ID.
Your application's Airbrake API key.
The name of the server environment this is running in.
The base url for errors. If
err.url is not set,
airbrake.host is used
err.url is a relative url starting with
'/', it is appended
err.url is an absolute url,
airbrake.host is ignored.
The root directory of this project.
The version of this app. Set to a semantic version number, or leave unset.
The protocol to use.
Do not post to Airbrake when running in these environments.
The timeout after which to give up trying to notify Airbrake in ms.
The HTTP/HTTPS proxy to use when making requests.
Additional request options that are merged with the default set of options that are passed to
Names of environment variables to send.
Names of environment variables to filter out.
process.on('uncaughtException') listener. When an uncaught
exception occurs, the error is sent to Airbrake, and then re-thrown to
kill the process.
A custom error handler that is used with Express. Integrate with Express
disableUncaughtException: Disables re-throwing and killing process on uncaught exception.
Sends the given
err to airbrake.
The callback parameter receives two arguments,
err is set if
the delivery to Airbrake failed.
cb is given, and the delivery fails, an
error event is emitted. If
there is no listener for this event, node will kill the process as well. This
is done to avoid silent error delivery failure.
Notifies Airbrake about a deployment.
params is an object with the following
env:The environment being deployed, defaults to
user:The user doing the deployment, defaults to
repo:The github url of this repository. Defaults to
git config --get remote.origin.url.
rev:The revision of this deployment. Defaults to
git rev-parse HEAD.
If you have feature ideas, please open an issue first, so we can discuss it.
Originally created by Felix Geisendörfer.
See all contributors.