简体   繁体   English

如何捕获前端响应到Django的错误和异常数据以添加更多上下文

[英]How can I capture errors and exceptions data from frontend response to django to add more context

I want to receive some parameters with my error capture on django when something wrong on the front-end 当前端出现问题时,我想在django上接收一些参数以进行错误捕获

I have react frontend running on a django backend. 我有在Django后端上运行的前端反应。 Sentry is been used to capture errors and report. Sentry用于捕获错误和报告。

In settings.py: 在settings.py中:

SENTRY_DSN = os.environ.get("SENTRY_DSN")
if SENTRY_DSN:
    sentry_sdk.init(
        dsn=SENTRY_DSN,
        integrations=[DjangoIntegration()],
        environment=ENVIRONMENT,
        release=os.environ.get("HEROKU_RELEASE_VERSION")
        or "HEROKU_RELEASE_VERSION not set",
    )
    with configure_scope() as scope:
        scope.user = {"user": "broken lol"}

This is reporting the errors from entire app. 这是报告整个应用程序中的错误。

However, I want to add user ids to error Sentry reports. 但是,我想将用户ID添加到错误Sentry报告中。 To do that I need to capture the response from frontend and somehow get that into settings.py and replace the "broken lol" string with UserId 为此,我需要捕获来自前端的响应,并以某种方式将其放入settings.py中,并用UserId替换"broken lol"字符串

To capture user IDs from Django's user objects, set init(..., send_default_pii=True) . 要从Django的用户对象中捕获用户ID,请设置init(..., send_default_pii=True) We do not have this as default because this can be a footgun for privacy. 我们没有默认设置,因为这可能是保护隐私的步枪。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以更易读的方式显示从后端接收到的数据?我将 react 用于前端 - How can I display the data recieved from the backend in a more readable way?I use react for the Frontend 如何将图像添加到我的 django 数据库并在前端显示 - how can I add Image to my django database and display it in frontend 如何使用views.py捕获从android发送到Django服务器的响应? - How can I capture a response sent from android to Django server using views.py? 如何通过 Django 后端将数据从 HDFS 发送到 Angular 5 前端? - How can I send data from HDFS through Django backend to Angular 5 frontend? 如何添加用于对Django模型进行排序的例外? - How can I add exceptions for sorting Django models? 如何使用Elasticsearch在Django中从前端编辑/删除数据? - How do i edit/delete data from the frontend in Django with Elasticsearch? 如何使用 React 前端渲染来自 Django 模型的数据? - How would I render data from a Django model with a React frontend? 如何从 django 前端定时安排任务? - How can I schedule a task at time from django frontend? 如何将变量从 Django 的 render 方法的上下文参数传递给前端的 javascript 脚本? - How do I pass a variable from Django's render method's context param to a javascript script on the frontend? 如何从网络摄像头捕获图片并将其存储在 Django 的 ImageField 中? - How can I capture a picture from webcam and store it in a ImageField in Django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM