bugsnag / bugsnag-python

Official BugSnag error monitoring and error reporting for django, flask, tornado and other python apps.
https://docs.bugsnag.com/platforms/python/
MIT License
86 stars 42 forks source link

Support the Sanic framework #320

Open robd003 opened 2 years ago

robd003 commented 2 years ago

I'd like to use BugSnag on my Sanic backends

johnkiely1 commented 2 years ago

Hi @robd003, We have added a backlog item to consider official support for Sanic. We will let you know of updates. However, in the meantime, we believe you can probably implement this yourself using the Sanic custom error handlers.

Something like the following should trigger an error and report it to Bugsnag. Perhaps you could modify this to your needs.

from sanic import Sanic
from sanic.response import json
from sanic.handlers import ErrorHandler
import bugsnag
​
​
bugsnag.configure(api_key='your-api-key-here')
​
app = Sanic("my-hello-world-app")
​
​
class BugsnagErrorHandler(ErrorHandler):
    def default(self, request, exception):
        bugsnag.auto_notify(exception)
        return super().default(request, exception)
​
app.error_handler = BugsnagErrorHandler()
​
​
@app.route('/')
async def will_make_an_error(request):
    raise Exception('oh no')
​
if __name__ == '__main__':
    app.run()
robd003 commented 2 years ago

Great, I'll give that a try.