JavaScript error tracking and monitoring library for Node.js and browser environments with telemetry, automatic error grouping, and real-time notifications
npx @tessl/cli install tessl/npm-rollbar@2.26.0Rollbar.js is a comprehensive JavaScript error tracking and monitoring library supporting both Node.js server-side and browser client-side environments. It provides real-time error tracking with automatic error grouping, telemetry breadcrumbs for debugging context, customizable notifications, and advanced search capabilities for filtering and analyzing errors.
npm install rollbarServer-side (Node.js):
const Rollbar = require('rollbar');Browser-side (ES6 modules):
import * as Rollbar from 'rollbar';
// or
const Rollbar = require('rollbar');Browser (UMD/Script tag):
<script src="https://cdn.rollbar.com/rollbar.umd.min.js"></script>
<!-- Rollbar is available as global variable -->TypeScript:
import * as Rollbar from 'rollbar';
// or
import Rollbar = require('rollbar');
// Types are included with the packageServer-side initialization:
const Rollbar = require('rollbar');
const rollbar = new Rollbar({
accessToken: 'YOUR_ACCESS_TOKEN',
environment: 'production'
});
// Log different severity levels
rollbar.info('Application started');
rollbar.error(new Error('Something went wrong'));Browser initialization:
const rollbar = new Rollbar({
accessToken: 'YOUR_CLIENT_ACCESS_TOKEN',
captureUncaught: true,
captureUnhandledRejections: true,
environment: 'production'
});
// Automatic error capture is enabled
// Manual logging also available
rollbar.error('User action failed');Rollbar.js is built around several key components:
Primary error and message logging functionality with multiple severity levels. Supports flexible argument patterns and automatic error enrichment.
function log(...args: LogArgument[]): LogResult;
function debug(...args: LogArgument[]): LogResult;
function info(...args: LogArgument[]): LogResult;
function warn(...args: LogArgument[]): LogResult;
function error(...args: LogArgument[]): LogResult;
function critical(...args: LogArgument[]): LogResult;
type LogArgument = string | Error | object | Callback | Date | any[] | undefined;
interface LogResult {
uuid: string;
}Comprehensive configuration system for customizing behavior, data collection, and filtering across different environments.
function configure(options: Configuration): Rollbar;
function global(options: Configuration): Rollbar;
interface Configuration {
accessToken?: string;
environment?: string;
endpoint?: string;
enabled?: boolean;
captureUncaught?: boolean;
captureUnhandledRejections?: boolean;
logLevel?: Level;
reportLevel?: Level;
maxItems?: number;
itemsPerMinute?: number;
scrubFields?: string[];
scrubHeaders?: string[];
// ... many more options
}Node.js specific features including Express middleware, AWS Lambda integration, and local variable capture.
function errorHandler(): ExpressErrorHandler;
function lambdaHandler<T>(handler: LambdaHandler<T>): LambdaHandler<T>;
function wrapCallback(callback: Function): Function;
type ExpressErrorHandler = (err: any, req: any, res: any, next: Function) => any;
type LambdaHandler<T> = (event: T, context: any, callback: Callback) => void | Promise<any>;Browser-specific error handling including global error capture, DOM event telemetry, and function wrapping.
function wrap(fn: Function, context?: any, before?: Function): Function;
function captureEvent(metadata: object, level: Level): TelemetryEvent;
interface TelemetryEvent {
level: Level;
type: string;
timestamp_ms: number;
body: object;
source: string;
uuid?: string;
}Comprehensive telemetry capture for debugging context including user interactions, network requests, and application events.
function captureEvent(metadata: object, level: Level): TelemetryEvent;
function captureError(err: Error, level: Level, rollbarUUID?: string): TelemetryEvent;
function captureLog(message: string, level: Level, rollbarUUID?: string): TelemetryEvent;
interface AutoInstrumentSettings {
network?: boolean;
networkResponseHeaders?: boolean | string[];
log?: boolean;
dom?: boolean;
navigation?: boolean;
connectivity?: boolean;
}React Native specific features for person management and enhanced error tracking in mobile applications.
function setPerson(personInfo: PersonInfo): void;
function clearPerson(): void;type Level = 'debug' | 'info' | 'warning' | 'error' | 'critical';
type MaybeError = Error | undefined | null;
type Dictionary = { [key: string]: unknown };
interface Callback<TResponse = any> {
(err: MaybeError, response: TResponse): void;
}
declare class Rollbar {
constructor(options?: Configuration);
static init(options: Configuration): Rollbar;
static setComponents(components: Components): void;
// All logging methods available as both static and instance methods
log(...args: LogArgument[]): LogResult;
debug(...args: LogArgument[]): LogResult;
info(...args: LogArgument[]): LogResult;
warn(...args: LogArgument[]): LogResult;
error(...args: LogArgument[]): LogResult;
critical(...args: LogArgument[]): LogResult;
configure(options: Configuration): Rollbar;
wait(callback: () => void): void;
lastError(): MaybeError;
}
interface Components {
telemeter?: TelemeterType;
instrumenter?: InstrumenterType;
polyfillJSON?: PolyfillJSONType;
wrapGlobals?: WrapGlobalsType;
scrub?: ScrubType;
truncation?: TruncationType;
}