bugsnag-python icon indicating copy to clipboard operation
bugsnag-python copied to clipboard

Support the Sanic framework

Open robd003 opened this issue 3 years ago • 2 comments

I'd like to use BugSnag on my Sanic backends

robd003 avatar Jun 04 '22 19:06 robd003

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()

johnkiely1 avatar Jun 09 '22 09:06 johnkiely1

Great, I'll give that a try.

robd003 avatar Jun 10 '22 15:06 robd003