Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Rollbar is a real-time error tracking and monitoring tool for JavaScript applications. It helps developers to detect, diagnose, and fix errors in their applications by providing detailed error reports and notifications.
Error Tracking
Rollbar can automatically capture and report uncaught exceptions and unhandled promise rejections. This helps in tracking errors that occur in the application.
const Rollbar = require('rollbar');
const rollbar = new Rollbar({
accessToken: 'YOUR_ACCESS_TOKEN',
captureUncaught: true,
captureUnhandledRejections: true
});
// Example of tracking an error
try {
throw new Error('Test error');
} catch (e) {
rollbar.error(e);
}
Custom Logging
Rollbar allows custom logging of messages, warnings, and info messages. This can be useful for tracking specific events or conditions in the application.
const Rollbar = require('rollbar');
const rollbar = new Rollbar({
accessToken: 'YOUR_ACCESS_TOKEN'
});
// Log a custom message
rollbar.log('Custom log message');
// Log a warning
rollbar.warning('This is a warning');
// Log an info message
rollbar.info('This is an info message');
Telemetry
Rollbar can capture telemetry data such as console logs, network requests, and DOM events. This helps in understanding the context in which an error occurred.
const Rollbar = require('rollbar');
const rollbar = new Rollbar({
accessToken: 'YOUR_ACCESS_TOKEN',
captureUncaught: true,
captureUnhandledRejections: true,
autoInstrument: true
});
// Example of adding custom telemetry data
rollbar.configure({
payload: {
telemetry: [
{ type: 'log', level: 'info', body: 'Custom telemetry data' }
]
}
});
Sentry is another popular error tracking and monitoring tool. It provides similar functionalities to Rollbar, including real-time error tracking, performance monitoring, and detailed error reports. Sentry also supports a wide range of programming languages and frameworks.
Airbrake is an error monitoring tool that provides real-time error tracking and detailed error reports. It offers similar features to Rollbar, such as capturing uncaught exceptions and custom logging. Airbrake also integrates with various development tools and services.
Bugsnag is an error monitoring tool that helps developers to detect, diagnose, and fix errors in their applications. It provides similar functionalities to Rollbar, including real-time error tracking, custom logging, and detailed error reports. Bugsnag also offers features like user tracking and release tracking.
Node.js library for reporting exceptions and other messages to Rollbar. Requires a Rollbar account.
// include and initialize the rollbar library with your access token
var rollbar = require("rollbar");
rollbar.init("POST_SERVER_ITEM_ACCESS_TOKEN");
// record a generic message and send to rollbar
rollbar.reportMessage("Hello world!");
// more is required to automatically detect and report errors.
// keep 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
var express = require('express');
var rollbar = require('rollbar');
var app = express();
app.get('/', function(req, res) {
// ...
});
// Use the rollbar error handler to send exceptions to your rollbar account
app.use(rollbar.errorHandler('POST_SERVER_ITEM_ACCESS_TOKEN'));
app.listen(6943);
In your main application, require and initialize using your access_token::
var rollbar = require("rollbar");
rollbar.init("POST_SERVER_ITEM_ACCESS_TOKEN");
Other options can be passed into the init() function using a second parameter. E.g.:
// Queue up and report messages/exceptions to rollbar every 5 seconds
rollbar.init("POST_SERVER_ITEM_ACCESS_TOKEN", {handler: "setInterval", handlerInterval: 5});
When you are finished using rollbar, clean up any remaining items in the queue using the shutdown function:
rollbar.shutdown();
Rollbar can be registered as a handler for any uncaught exceptions in your Node process:
var options = {
// Call process.exit(1) when an uncaught exception occurs but after reporting all
// pending errors to Rollbar.
//
// Default: false
exitOnUncaughtException: true
};
rollbar.handleUncaughtExceptions("POST_SERVER_ITEM_ACCESS_TOKEN", options);
To report an exception that you have caught, use handleError
or the full-powered handleErrorWithPayloadData
:
var rollbar = require('rollbar');
rollbar.init('POST_SERVER_ITEM_ACCESS_TOKEN');
try {
someCode();
} catch (e) {
rollbar.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
rollbar.handleError(e, request);
// you can also pass a callback, which will be called upon success/failure
rollbar.handleError(e, function(err2) {
if (err2) {
// an error occurred
} else {
// success
}
});
// if you have a request and a callback, pass the callback last
rollbar.handleError(e, request, callback);
// to specify payload options - like extra data, or the level - use handleErrorWithPayloadData
rollbar.handleErrorWithPayloadData(e, {level: "warning", custom: {someKey: "arbitrary value"}});
// can also take request and callback, like handleError:
rollbar.handleErrorWithPayloadData(e, {level: "info"}, request);
rollbar.handleErrorWithPayloadData(e, {level: "info"}, callback);
rollbar.handleErrorWithPayloadData(e, {level: "info"}, request, callback);
}
To report a string message, possibly along with additional context, use reportMessage
or the full-powered reportMessageWithPayloadData
.
var rollbar = require('rollbar');
rollbar.init('POST_SERVER_ITEM_ACCESS_TOKEN');
// reports a string message at the default severity level ("error")
rollbar.reportMessage("Timeout connecting to database");
// reports a string message at the level "info", along with a request and callback
// only the first param is required
// valid severity levels: "critical", "error", "warning", "info", "debug"
rollbar.reportMessage("Response time exceeded threshold of 1s", "warning", request, callback);
// reports a string message along with additional data conforming to the Rollbar API Schema
// documented here: https://rollbar.com/docs/api/items_post/
// only the first two params are required
rollbar.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:
Default: 10
e.g. 'master'
e.g. '868ff435d6a480929103452e5ebe8671c5c89f77'
Default: 'https://api.rollbar.com/api/1/'
Default: 'unspecified'
Default: inline
Default: 3
Default: hostname returned from os.hostname()
e.g. '/Users/bob/Development'
Default: ['passwd', 'password', 'secret', 'confirm_password', 'password_confirmation']
Default: []
Default: true
See the examples directory for more use cases.
The default configuration uses the inline
handler which will cause errors to be reported to Rollbar at the time they occur. This works well for small applications but can quickly become a problem for high-throughput apps. For better performance, the setInterval
handler is recommended since it queues up errors before sending them.
When using a handler besides inline
, you should make sure to call rollbar.shutdown()
in order to flush all errors before exiting.
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/*
FAQs
Effortlessly track and debug errors in your JavaScript applications with Rollbar. This package includes advanced error tracking features and an intuitive interface to help you identify and fix issues more quickly.
The npm package rollbar receives a total of 280,275 weekly downloads. As such, rollbar popularity was classified as popular.
We found that rollbar demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.