skip to navigation
skip to content

Not Logged In

rollbar 0.7.3

Logs exceptions and other data to Rollbar. Provides a generic interface, as well as a Django middleware and a Pyramid tween.

Latest Version: 0.10.1

# Rollbar notifier for Python [![Build Status](](

Python notifier for reporting exceptions, errors, and log messages to [Rollbar](

## Quick start

Install using pip:

pip install rollbar

import rollbar
rollbar.init('POST_SERVER_ITEM_ACCESS_TOKEN', 'production') # access_token, environment

except IOError:
rollbar.report_message('Got an IOError in the main loop', 'warning')
# catch-all

## Requirements

- Python 2.6, 2.7, 3.2 or 3.3
- requests 0.12+
- A Rollbar account

## Configuration

### Django

In your ````, add ``'rollbar.contrib.django.middleware.RollbarNotifierMiddleware'`` as the last item in ``MIDDLEWARE_CLASSES``:

# ... other middleware classes ...

Add these configuration variables in ````:

'environment': 'development' if DEBUG else 'production',
'branch': 'master',
'root': '/absolute/path/to/code/root',

Be sure to replace ```POST_SERVER_ITEM_ACCESS_TOKEN``` with your project's ```post_server_item``` access token, which you can find in the interface.

### Pyramid

In your ``ini`` file (e.g. ``production.ini``), add ``rollbar.contrib.pyramid`` to the end of your ``pyramid.includes``:

pyramid.includes =

Add these rollbar configuration variables:

rollbar.access_token = POST_SERVER_ITEM_ACCESS_TOKEN
rollbar.environment = production
rollbar.branch = master
rollbar.root = %(here)s

Be sure to replace ```POST_SERVER_ITEM_ACCESS_TOKEN``` with your project's ```post_server_item``` access token, which you can find in the interface.

The above will configure rollbar to catch and report all exceptions that occur in your Pyramid app. However, if there are any middleware
applications that wrap your app, Rollbar will not be able to catch exceptions.

In order to catch exceptions from Pyramid and middleware code, you will need to create a ```pipeline``` where the rollbar middleware wraps your Pyramid app.

Change your ```ini``` file to use a ```pipeline```:




pipeline =

pyramid.includes =

environment = production
branch = master
root = %(here)s

Unfortunately, the Rollbar tween and the Rollbar filter configurations contains duplicated information. We'll look into fixing this in future versions.

### Flask

Check out [rollbar-flask-example](

### Bottle

Import the plugin and install!
Can be installed globally or on a per route basis.

import bottle
from rollbar.contrib.bottle import RollbarBottleReporter

rbr = RollbarBottleReporter(access_token='POST_SERVER_ITEM_ACCESS_TOKEN', environment='production') #setup rollbar

bottle.install(rbr) #install globally

def raise_error():
When navigating to /, we'll get a regular 500 page from bottle,
as well as have the error below listed on Rollbar.
raise Exception('Hello, Rollbar!')

if __name__ == '__main__':'localhost', port=8080)

Be sure to replace ```POST_SERVER_ITEM_ACCESS_TOKEN``` with your project's ```post_server_item``` access token, which you can find in the interface.

### Other

For generic Python or a non-Django/non-Pyramid framework just initialize the Rollbar library with your access token and environment.

rollbar.init('POST_SERVER_ITEM_ACCESS_TOKEN', environment='production')

Other options can be passed as keyword arguments. See the reference below for all options.

### Command-line usage

pyrollbar comes with a command-line tool that can be used with other UNIX utilities to create an ad-hoc monitoring solution.

e.g. Report all 5xx haproxy requests as ```warning```

tail -f /var/log/haproxy.log | awk '{print $11,$0}' | grep '^5' | awk '{$1="";print "warning",$0}' | rollbar -t $POST_SERVER_ITEM_ACCESS_TOKEN -e production -v

e.g. Test an access token

rollbar -t $POST_SERVER_ITEM_ACCESS_TOKEN -e test debug testing access token

#### Reference

$ rollbar --help
Usage: rollbar [options]

--version show program's version number and exit
-h, --help show this help message and exit
-t ACCESS_TOKEN, --access_token=ACCESS_TOKEN
You project's access token from
The environment to report errors and messages to.
The Rollbar API endpoint url to send data to.
-m HANDLER, --handler=HANDLER
The method in which to report errors.
-v, --verbose Print verbose output.

## Usage

The Django and Pyramid integration will automatically report uncaught exceptions to Rollbar.

### Exceptions

To report a caught exception to Rollbar, use ```rollbar.report_exc_info()```:

# or if you have a webob-like request object, pass that as well:
# rollbar.report_exc_info(sys.exc_info(), request)

### Logging

You can also send any other log messages you want, using ```rollbar.report_message()```:

except IOError:
rollbar.report_message('Got an IOError while trying to do_something()', 'warning')
# report_message() also accepts a request object:
#rollbar.report_message('message here', 'warning', request)

### Examples

Here's a full example, integrating into a simple Gevent app.

Sample Gevent application with Rollbar integration.
import sys
import logging

from gevent.pywsgi import WSGIServer
import rollbar
import webob

# configure logging so that rollbar's log messages will appear

def application(environ, start_response):
request = webob.Request(environ)
status = '200 OK'
headers = [('Content-Type', 'text/html')]
start_response(status, headers)

yield '<p>Hello world</p>'

# will raise a NameError about 'bar' not being defined
foo = bar
# report full exception info
rollbar.report_exc_info(sys.exc_info(), request)

# and/or, just send a string message with a level
rollbar.report_message("Here's a message", 'info', request)

yield '<p>Caught an exception</p>'

# initialize rollbar with an access token and environment name
rollbar.init('POST_SERVER_ITEM_ACCESS_TOKEN', 'development')

# now start the wsgi server
WSGIServer(('', 8000), application).serve_forever()

## Configuration reference

<dd>Access token from your Rollbar project
<dd>Controls whether or not Rollbar will report any data

Default: ```True```

<dd>The method for reporting rollbar items to

One of:

- blocking -- runs in main thread
- thread -- spawns a new thread
- agent -- writes messages to a log file for consumption by rollbar-agent

Default: ```thread```

<dd>If ```handler``` is ```agent```, the path to the log file. Filename must end in ```.rollbar```
<dd>Name of the checked-out branch.

Default: ```master```

<dd>URL items are posted to.

Default: ``````

<dd>Environment name. Any string up to 255 chars is OK. For best results, use "production" for your production environment.
<dd>List of tuples in the form ```(class, level)``` where ```class``` is an Exception class you want to always filter to the respective ```level```. Any subclasses of the given ```class``` will also be matched.

Valid levels: ```'critical'```, ```'error'```, ```'warning'```, ```'info'```, ```'debug'``` and ```'ignored'```.

Use ```'ignored'``` if you want an Exception (sub)class to never be reported to Rollbar.

Any exceptions not found in this configuration setting will default to ```'error'```.

Django `````` example (and Django default):

from django.http import Http404

'exception_level_filters': [
(Http404, 'warning')

In a Pyramid ``ini`` file, define each tuple as an individual whitespace delimited line, for example:

rollbar.exception_level_filters =
pyramid.exceptions.ConfigurationError critical

<dd>Absolute path to the root of your application, not including the final ```/```.
<dd>List of field names to scrub out of POST. Values will be replaced with astrickses. If overridiing, make sure to list all fields you want to scrub, not just fields you want to add to the default. Param names are converted to lowercase before comparing against the scrub list.

Default: ```['passwd', 'password', 'secret', 'confirm_password', 'password_confirmation']```

<dd>Timeout for any HTTP requests made to the Rollbar API (in seconds).

Default: ```3```

<dd>When True, ```logging.basicConfig()``` will be called to set up the logging system. Set to False to skip this call. If using Flask, you'll want to set to ```False```. If using Pyramid or Django, ```True``` should be fine.

Default: ```True```


## Help / Support

If you run into any issues, please email us at [](

You can also find us in IRC: [#rollbar on](irc://

For bug reports, please [open an issue on GitHub](

## Contributing

1. Fork it
2. Create your feature branch (```git checkout -b my-new-feature```).
3. Commit your changes (```git commit -am 'Added some feature'```)
4. Push to the branch (```git push origin my-new-feature```)
5. Create new Pull Request

Tests are in `rollbar/test`. To run the tests: `python test`  
File Type Py Version Uploaded on Size
rollbar-0.7.3.tar.gz (md5) Source 2014-05-02 23KB
  • Downloads (All Versions):
  • 679 downloads in the last day
  • 4660 downloads in the last week
  • 19001 downloads in the last month