pyrollbar is a generic library for reporting exceptions and other messages to Rollbar:
import rollbar rollbar.init('YOUR_ACCESS_TOKEN', 'production') # access_token, environment try: main_app_loop() except IOError: rollbar.report_message('Got an IOError in the main loop', 'warning') except: # catch-all rollbar.report_exc_info()
pyrollbar requires:
- Python 2.6 or 2.7
- requests 0.12+
- a Rollbar account
Install using pip:
pip install rollbar
For generic Python or a non-Django/non-Pyramid framework, follow these instructions:
Somewhere in your initialization code, call rollbar.init() with your access_token:
rollbar.init('YOUR_ACCESS_TOKEN_HERE', environment='production')
Other options can be passed as keyword arguments. See the reference below for all options.
If you are integrating with Django, follow these instructions:
In your
settings.py
, add'rollbar.contrib.django.middleware.RollbarNotifierMiddleware'
as the last item inMIDDLEWARE_CLASSES
:MIDDLEWARE_CLASSES = ( # ... other middleware classes ... 'rollbar.contrib.django.middleware.RollbarNotifierMiddleware', )
Add these configuration variables in
settings.py
:ROLLBAR = { 'access_token': 'YOUR_ACCESS_TOKEN_HERE', 'environment': 'development' if DEBUG else 'production', 'branch': 'master', 'root': '/absolute/path/to/code/root', }
If you are integrating with Pyramid, follow these instructions:
In your
ini
file (e.g.production.ini
), addrollbar.contrib.pyramid
to the end of yourpyramid.includes
:[app:main] pyramid.includes = pyramid_debugtoolbar rollbar.contrib.pyramid
Add these rollbar configuration variables:
[app:main] rollbar.access_token = YOUR_ACCESS_TOKEN_HERE rollbar.environment = production rollbar.branch = master rollbar.root = %(here)s
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 apipeline
:From [app:main] ... To [pipeline:main] pipeline = rollbar YOUR_APP_NAME [app:YOUR_APP_NAME] pyramid.includes = pyramid_debugtoolbar rollbar.contrib.pyramid [filter:rollbar] access_token = YOUR_ACCESS_TOKEN_HERE 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.
The Django and Pyramid integration will automatically report uncaught exceptions to Rollbar.
Call rollbar.report_exc_info()
to report an exception, or rollbar.report_message()
to report an arbitrary string message. See the docstrings for more info.
- access_token
- Access token from your Rollbar project
- handler
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
- environment
- Environment name. Any string up to 255 chars is OK. For best results, use "production" for your production environment.
- root
- Absolute path to the root of your application, not including the final
/
. - branch
Name of the checked-out branch.
default:
master
- agent.log_file
- If
handler
isagent
, the path to the log file. Filename must end in.rollbar
- endpoint
URL items are posted to.
default:
https://api.rollbar.com/api/1/item/
- scrub_fields
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']
- exception_level_filters
List of tuples in the form
(class, level)
whereclass
is an Exception class you want to always filter to the respectivelevel
. Any subclasses of the givenclass
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
settings.py
example (and Django default):from django.http import Http404 ROLLBAR = { ... '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 ...
Get in touch! We'd love to hear what you think and we're happy to help.
- Email us:
[email protected]
- IRC:
#rollbar.com
onirc.freenode.net
- Want to contribute? Send a pull request at https://github.com/rollbar/pyrollbar