Bugsnag
Bugsnag is a comprehensive error monitoring library for Python applications, including frameworks like Django, Flask, and Tornado. It automatically detects and reports unhandled exceptions, and allows for manual reporting of handled errors, providing detailed diagnostic information to a central dashboard. The library is actively maintained, currently at version 4.8.1, with regular updates to support new Python features and integrations.
Warnings
- breaking Migrating from Bugsnag Python 3.x to 4.x requires Python 3.5+. Older Python versions are no longer supported. The `bugsnag.utils.ThreadLocals` utility has been removed.
- breaking The `Configuration.send_environment` option is now `False` by default in v4.x, meaning request context (like environment variables) will not be sent unless explicitly enabled. Setting unknown properties via `bugsnag.configure(**kwargs)` is no longer supported and will cause an error.
- breaking In Bugsnag 4.x, `use_ssl` and `Configuration.get_endpoint()` have been deprecated in favor of including the protocol (e.g., `https://`) directly in the `endpoint` configuration option.
- gotcha Automatic detection of unhandled exceptions in threads relies on `threading.excepthook`, which is only supported in Python 3.8 and above. For older Python 3 versions, unhandled exceptions in non-main threads might not be automatically reported.
- gotcha It is crucial to use `params_filters` to prevent sensitive data (e.g., passwords, credit card numbers) from being sent to Bugsnag in your error reports.
- gotcha The introduction of `__all__` lists in Bugsnag 4.x may affect existing integrations that use `from bugsnag import *` by changing which symbols are exposed during a wildcard import.
Install
-
pip install bugsnag
Imports
- bugsnag
import bugsnag
- BugsnagHandler
from bugsnag.handlers import BugsnagHandler
Quickstart
import bugsnag
import os
bugsnag.configure(
api_key=os.environ.get('BUGSNAG_API_KEY', 'YOUR_API_KEY_HERE'),
release_stage='development',
project_root=os.path.dirname(os.path.abspath(__file__)),
)
def might_fail():
raise ValueError("This is a test error!")
try:
might_fail()
except Exception as e:
print(f"Caught an error: {e}. Notifying Bugsnag...")
bugsnag.notify(e)
print("Notification sent.")
# To demonstrate unhandled error reporting, you would typically not catch it.
# For example, simply calling might_fail() outside a try-except block in a WSGI/ASGI app.