后台小程序开发的全方位指南
882
2022-10-20
用于ASGI框架的Sentry集成
Update Sentry now includes built-in support for ASGI. (Based on this implementation.)
Please see the documentation at https://docs.sentry.io/platforms/python/asgi/
Or the source code implementation at https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/asgi.py
As a result, this repository has now been placed in an "archived" state.
sentry-asgi
Sentry integration for ASGI frameworks.
Installation:
pip install sentry-asgi
Usage:
from sentry_asgi import SentryMiddlewareimport sentry_sdksentry_sdk.init(dsn=...)app = ...app = SentryMiddleware(app)
Here's a more complete example, using Starlette:
import sentry_sdkfrom sentry_asgi import SentryMiddlewaresentry_sdk.init(dsn=...)app = Starlette()@app.route("/")def homepage(request): raise ValueError("nope")app.add_middleware(SentryMiddleware)
Notes
Python version support
The Sentry SDK requires Python 3.7's contextvars support in order to properly tie messages and logging back to the request context that is added SentryMiddleware.
On 3.6 and below the SentryMiddleware will capture and log application exceptions just fine, but will not properly tie in logging, messages, or breadcrumbs for any code that runs within a threadpool executor or subtask.
ASGI frameworks should ensure that any thread pool executors preserve the contextvar context.
Endpoint information
It is recommended that frameworks populate an "endpoint" key in the ASGI scope, to indicate which view function or class should be logged by the middleware.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~