Name: node_rollbar
Owner: SpatialDev
Description: A node.js client for the Rollbar error tracking service.
Forked from: rollbar/node_rollbar
Created: 2016-02-11 23:34:24.0
Updated: 2016-02-11 23:34:25.0
Pushed: 2016-02-09 18:49:47.0
Homepage: https://rollbar.com/docs/notifier/node_rollbar/
Size: 225
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Node.js library for reporting exceptions and other messages to Rollbar. Requires a Rollbar account.
nclude and initialize the rollbar library with your access token
rollbar = require("rollbar");
bar.init("POST_SERVER_ITEM_ACCESS_TOKEN");
ecord a generic message and send to rollbar
bar.reportMessage("Hello world!");
ore is required to automatically detect and report errors.
eep reading for details.
Be sure to replace `POST_SERVER_ITEM_ACCESS_TOKEN
with your project's ``
post_server_item``` access token, which you can find in the Rollbar.com interface.
Install using the node package manager, npm:
$ npm install --save rollbar
express = require('express');
rollbar = require('rollbar');
app = express();
get('/', function(req, res) {
...
se the rollbar error handler to send exceptions to your rollbar account
use(rollbar.errorHandler('POST_SERVER_ITEM_ACCESS_TOKEN'));
listen(6943);
In your main application, require and initialize using your access_token::
rollbar = require("rollbar");
bar.init("POST_SERVER_ITEM_ACCESS_TOKEN");
Other options can be passed into the init() function using a second parameter. E.g.:
onfigure the library to send errors to api.rollbar.com
bar.init("POST_SERVER_ITEM_ACCESS_TOKEN", {
vironment: "staging",
dpoint: "https://api.rollbar.com/api/1/"
Rollbar can be registered as a handler for any uncaught exceptions in your Node process:
options = {
Call process.exit(1) when an uncaught exception occurs but after reporting all
pending errors to Rollbar.
Default: false
itOnUncaughtException: true
bar.handleUncaughtExceptions("POST_SERVER_ITEM_ACCESS_TOKEN", options);
To report an exception that you have caught, use handleError
or the full-powered handleErrorWithPayloadData
:
rollbar = require('rollbar');
bar.init('POST_SERVER_ITEM_ACCESS_TOKEN');
{
meCode();
tch (e) {
llbar.handleError(e);
if you have a request object (or a function that returns one), pass it as the second arg
see below for details about what the request object is expected to be
llbar.handleError(e, request);
you can also pass a callback, which will be called upon success/failure
llbar.handleError(e, function(err2) {
if (err2) {
// an error occurred
} else {
// success
}
;
if you have a request and a callback, pass the callback last
llbar.handleError(e, request, callback);
to specify payload options - like extra data, or the level - use handleErrorWithPayloadData
llbar.handleErrorWithPayloadData(e, {level: "warning", custom: {someKey: "arbitrary value"}});
can also take request and callback, like handleError:
llbar.handleErrorWithPayloadData(e, {level: "info"}, request);
llbar.handleErrorWithPayloadData(e, {level: "info"}, callback);
llbar.handleErrorWithPayloadData(e, {level: "info"}, request, callback);
To report a string message, possibly along with additional context, use reportMessage
or the full-powered reportMessageWithPayloadData
.
rollbar = require('rollbar');
bar.init('POST_SERVER_ITEM_ACCESS_TOKEN');
eports a string message at the default severity level ("error")
bar.reportMessage("Timeout connecting to database");
eports a string message at the level "warning", along with a request and callback
nly the first param is required
alid severity levels: "critical", "error", "warning", "info", "debug"
bar.reportMessage("Response time exceeded threshold of 1s", "warning", request, callback);
eports a string message along with additional data conforming to the Rollbar API Schema
ocumented here: https://rollbar.com/docs/api/items_post/
nly the first two params are required
bar.reportMessageWithPayloadData("Response time exceeded threshold of 1s", {
level: "warning",
custom: {
threshold: 1,
timeElapsed: 2.3
}
request, callback);
If your Node.js application is responding to web requests, you can send data about the current request along with each report to Rollbar. This will allow you to replay requests, track events by browser, IP address, and much more.
handleError
, reportMessage
, handleErrorWithPayloadData
, and reportMessageWithPayloadData
all accept a request
parameter as the second, third, third, and third arguments respectively. If it is a function, it will be called and the result used.
If you're using Express, just pass the express request object. If you're using something custom, pass an object with these keys (all optional):
headers
: an object containing the request headersprotocol
: the request protocol (e.g. "https"
)url
: the URL starting after the domain name (e.g. "/index.html?foo=bar"
)method
: the request method (e.g. "GET"
)body
: the request body as a stringroute
: an object containing a 'path' key, which will be used as the “context” for the event (e.g. {path: "home/index"}
)Sensitive param names will be scrubbed from the request body and, if scrubHeaders
is configured, headers. See the scrubFields
and scrubHeaders
configuration options for details.
If your application has authenticated users, you can track which user (“person” in Rollbar parlance) was associated with each event.
If you're using the Passport authentication library, this will happen automatically when you pass the request object (which will have “user” attached). Otherwise, attach one of these keys to the request
object described in the previous section:
rollbar_person
or user
: an object like {id: "123", username: "foo", email: "foo@example.com"}
. id is required, others are optional.user_id
: the user id as an integer or string, or a function which when called will return the user idNote: in Rollbar, the id
is used to uniquely identify a person; email
and username
are supplemental and will be overwritten whenever a new value is received for an existing id
. The id
is a string up to 40 characters long.
rollbar.init("access token", optionsObj)
takes the following configuration options:
See the examples directory for more use cases.
For a full example of setting up a new Sails.js project with Rollbar integration see rollbar-sailsjs-example.
If you have any questions, feedback, etc., drop us a line at support@rollbar.com
For bug reports, please open an issue on GitHub.
The project is hosted on GitHub. If you'd like to contribute a change:
git checkout -b my-new-feature
)git commit -am 'Added some feature'
)git push origin my-new-feature
)We're using vows for testing. To run the tests, run: vows --spec test/*