Sanic错误处理程序,与Sentry集成
项目描述
Sentry错误处理程序,用于Sanic网络服务器
需求
python >= 3.5
安装
sanic-sentry-error-handler 应使用pip安装
pip install sanic-sentry-error-handler
用法
SENTRY_DSN - 应用程序的Sentry DSN
首先,我们将设置一个Sanic应用程序
>>> from sanic import Sanic
>>> from sanic_sentry import SanicSentryErrorHandler
>>> app = Sanic(__name__)
>>> app.error_handler = SanicSentryErrorHandler('http://public:secret@example.com/1')
如果您的应用程序使用Sanic异常处理视图,您可能考虑使用装饰器来拦截异常。
>>> from sanic import response, Sanic
>>> from sanic_sentry import SanicSentryErrorHandler
>>>
>>> sentry_client = SanicSentryErrorHandler('http://public:secret@example.com/1')
>>> app = Sanic(__name__)
>>>
>>>
>>> @app.exception([Exception, ])
>>> @sentry_client.intercept_exception
>>> def handle_exception_500(request, exception):
>>> return response.json({"description": "Internal Server Error"}, status=500)