Skip to main content

Python exception notifier for Airbrake

Project description

Build Status

Installation

pybrake requires Python 3.5+.

pip install -U pybrake

Usage

Creating notifier:

import pybrake


notifier = pybrake.Notifier(project_id=123,
                            project_key='abc',
                            environment='production')

Sending errors to Airbrake:

try:
    raise ValueError('hello')
except Exception as err:
    future = notifier.notify(err)
    # future has type concurrent.futures.Future
    notice = future.result()

By default notify sends errors asynchronously using ThreadPoolExecutor and returns a concurrent.futures.Future, but synchronous API is also available:

notice = notifier.notify_sync(err)
if 'id' in notice:
    print(notice['id'])
else:
    print(notice['error'])

You can also set custom params on all reported notices:

def my_filter(notice):
    notice['params']['myparam'] = 'myvalue'
    return notice

notifier.add_filter(my_filter)

Or ignore notices:

def my_filter(notice):
    if notice['context']['environment'] == 'development':
        # Ignore notices in development environment.
        return None
    return notice

notifier.add_filter(my_filter)

Logging integration

pybrake provide logging handler that sends your logs to Airbrake:

import logging
import pybrake


airbrake_handler = pybrake.LoggingHandler(notifier=notifier,
                                          level=logging.ERROR)

logger = logging.getLogger('test')
logger.addHandler(airbrake_handler)

logger.error('something bad happened')

Development

Running tests:

pip install -r test-requirements.txt
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybrake-0.1.2.tar.gz (7.5 kB view details)

Uploaded Source

File details

Details for the file pybrake-0.1.2.tar.gz.

File metadata

  • Download URL: pybrake-0.1.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pybrake-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a4ad148c24805939df5d147efca3a64903c6e0e084d69c122bae6ba33cc0a638
MD5 a91b55c5cf0f663a3fd2c778207a3e42
BLAKE2b-256 2c6689d4acd72f83d485d25244ff5cb67a64b33e6d6d48af2407ebbe71b48483

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page