Zum Inhalt springen

Rollbar Cheat Sheet

Overview

Rollbar is a cloud-based error monitoring and crash reporting platform that provides real-time visibility into application errors across your entire stack. It automatically groups similar errors, tracks error trends across deploys, and integrates with development workflows through Jira, GitHub, Slack, and PagerDuty to accelerate debugging and resolution.

Rollbar supports SDKs for JavaScript, Python, Ruby, PHP, Java, .NET, Go, Node.js, iOS, Android, and more. Key features include AI-assisted grouping, automated issue creation, deploy tracking, people tracking, telemetry breadcrumbs, and RQL (Rollbar Query Language) for searching through error data.

Installation

# JavaScript (Browser)
npm install rollbar

# Node.js
npm install rollbar

# Python
pip install rollbar

# Ruby
gem install rollbar

# PHP
composer require rollbar/rollbar

# Go
go get github.com/rollbar/rollbar-go

# .NET
dotnet add package Rollbar

Core Configuration

Node.js

const Rollbar = require("rollbar");

const rollbar = new Rollbar({
  accessToken: "POST_SERVER_ITEM_ACCESS_TOKEN",
  environment: process.env.NODE_ENV || "development",
  codeVersion: "1.2.0",
  captureUncaught: true,
  captureUnhandledRejections: true,
  payload: {
    server: {
      root: process.cwd(),
      host: "web-01",
    },
  },
});

// Express middleware
app.use(rollbar.errorHandler());

JavaScript (Browser)

const rollbarConfig = {
  accessToken: "POST_CLIENT_ITEM_ACCESS_TOKEN",
  environment: "production",
  captureUncaught: true,
  captureUnhandledRejections: true,
  payload: {
    client: {
      javascript: {
        source_map_enabled: true,
        code_version: "1.2.0",
        guess_uncaught_frames: true,
      },
    },
  },
};

const rollbar = new Rollbar(rollbarConfig);

Python / Django

import rollbar

rollbar.init(
    access_token="POST_SERVER_ITEM_ACCESS_TOKEN",
    environment="production",
    code_version="1.2.0",
    root=os.path.dirname(os.path.realpath(__file__)),
)

# Django settings.py
MIDDLEWARE = [
    "rollbar.contrib.django.middleware.RollbarNotifierMiddleware",
    # ... other middleware
]

ROLLBAR = {
    "access_token": "POST_SERVER_ITEM_ACCESS_TOKEN",
    "environment": "production",
    "code_version": "1.2.0",
    "root": BASE_DIR,
}

Manual Error Reporting

// Log levels: critical, error, warning, info, debug
rollbar.error("Something went wrong");
rollbar.critical("Database connection lost");
rollbar.warning("Deprecated API endpoint called");
rollbar.info("User signed up", { userId: "123" });
rollbar.debug("Cache miss for key", { key: "user:123" });

// Report caught exceptions
try {
  processPayment(order);
} catch (err) {
  rollbar.error(err, { orderId: order.id, amount: order.total });
}

// Report with custom data
rollbar.error("API timeout", {
  endpoint: "/api/users",
  timeout: 30000,
  retryCount: 3,
});
# Python error reporting
import rollbar

rollbar.report_message("User signup failed", level="error",
    extra_data={"user_id": "123", "step": "email_verification"})

try:
    process_order(order_id)
except Exception:
    rollbar.report_exc_info(
        extra_data={"order_id": order_id, "amount": 99.99}
    )

Person Tracking

// Set user context
rollbar.configure({
  payload: {
    person: {
      id: "user-123",
      username: "jdoe",
      email: "jdoe@example.com",
    },
  },
});

Telemetry / Breadcrumbs

// Automatic telemetry captures console, network, DOM events
const rollbar = new Rollbar({
  accessToken: "TOKEN",
  autoInstrument: {
    network: true,
    log: true,
    dom: true,
    navigation: true,
    connectivity: true,
  },
  maxTelemetryEvents: 50,
});

Deploy Tracking

# Notify Rollbar of a deploy via API
curl -X POST https://api.rollbar.com/api/1/deploy \
  -H "Content-Type: application/json" \
  -d '{
    "access_token": "POST_SERVER_ITEM_ACCESS_TOKEN",
    "environment": "production",
    "revision": "'$(git rev-parse HEAD)'",
    "local_username": "'$(whoami)'",
    "rollbar_username": "jdoe",
    "comment": "Deployed v1.2.0"
  }'

Source Maps

# Upload source maps via API
curl -X POST https://api.rollbar.com/api/1/sourcemap \
  -F access_token=POST_SERVER_ITEM_ACCESS_TOKEN \
  -F version=1.2.0 \
  -F minified_url=https://example.com/static/app.min.js \
  -F source_map=@dist/app.min.js.map

RQL (Rollbar Query Language)

-- Find all critical errors in the last 24 hours
SELECT * FROM item_occurrence
WHERE item.level = 'critical'
AND timestamp > unix_timestamp() - 86400

-- Count errors by environment
SELECT item.environment, count(*)
FROM item_occurrence
GROUP BY item.environment

-- Find errors affecting a specific user
SELECT * FROM item_occurrence
WHERE body.person.id = 'user-123'

-- Top errors by occurrence count
SELECT item.title, count(*) AS cnt
FROM item_occurrence
GROUP BY item.title
ORDER BY cnt DESC
LIMIT 20

Advanced Usage

Custom Fingerprinting

rollbar.configure({
  payload: {
    fingerprint: "custom-group-key",
  },
});

// Per-occurrence fingerprint
rollbar.error("Payment failed", {
  fingerprint: "payment-failure-stripe",
});

Transform Payload

const rollbar = new Rollbar({
  accessToken: "TOKEN",
  transform: function (payload) {
    // Scrub sensitive data
    if (payload.body?.request?.headers) {
      delete payload.body.request.headers["Authorization"];
    }
    // Add custom data
    payload.data.custom = {
      buildId: process.env.BUILD_ID,
    };
  },
});

Check/Ignore Functions

const rollbar = new Rollbar({
  accessToken: "TOKEN",
  checkIgnore: function (isUncaught, args, payload) {
    // Ignore errors from bots
    if (payload?.data?.client?.javascript?.browser?.includes("bot")) {
      return true;
    }
    return false;
  },
});

Configuration Options

OptionDescription
accessTokenProject access token (required)
environmentCurrent environment name
codeVersionGit SHA or version string
captureUncaughtAuto-capture uncaught exceptions
captureUnhandledRejectionsAuto-capture promise rejections
hostSafeListDomains to monitor (browser)
hostBlockListDomains to ignore (browser)
scrubFieldsFields to redact from payloads
logLevelMinimum level to report
verboseEnable verbose SDK logging

Troubleshooting

IssueSolution
Events not appearingVerify access token has write permissions; check environment filter
Source maps not resolvingEnsure code_version matches between config and upload
Duplicate itemsReview custom fingerprinting; check grouping settings
Rate limit exceededFilter noisy errors with checkIgnore; adjust sampling
Missing stack tracesEnable source maps; check guess_uncaught_frames for browser
Person data not showingVerify person object has id field set
Deploy not linking to itemsEnsure revision matches code_version in SDK config
Payload too largeReduce telemetry events with maxTelemetryEvents; scrub large objects