【发布时间】:2019-09-08 17:46:10
【问题描述】:
我使用 django-restful 框架,当 ModelViewSet 发生错误时,我想将用户信息添加到 Sentry 的报告中。
我找到了 Sentry 的这个文档: https://docs.sentry.io/enriching-error-data/context/?_ga=1.219964441.1220115692.1472094716%3F_ga&platform=python#capturing-the-user
它给出了一些代码如下:
from sentry_sdk import configure_scope
with configure_scope() as scope:
scope.user = {"email": "john.doe@example.com"}
但我不知道如何正确使用它。我认为存在比以下更好的方法:
@list_route()
def fun_xxx(self, request, *args, **kwargs):
user = request.user
with configure_scope() as scope:
scope.user = {"id": user.id,......}
...some code may cause an error...
return Response({...})
谁能给我一些建议? :)
【问题讨论】:
-
如果您使用的是 Sentry Django client,则会自动包含此数据。
标签: django django-rest-framework sentry