我有一个基于django(3.2.10)和sentry sdk(1.16.0)的项目

from os import getenv


SENTRY_URL = getenv('SENTRY_URL')

if SENTRY_URL:
    from sentry_sdk import init
    from sentry_sdk.integrations.django import DjangoIntegration
    from sentry_sdk.integrations.redis import RedisIntegration
    from sentry_sdk.integrations.celery import CeleryIntegration

    init(
        dsn=SENTRY_URL,
        integrations=[DjangoIntegration(), RedisIntegration(), CeleryIntegration()],
        traces_sample_rate=1.0,
        send_default_pii=True,
        debug=True,
    )

我有一个从Exception继承的CustomError

每次我引发CustomError sentry时,sdk都会将其发送到dsn url.

我想忽略某类错误或类似的东西.

推荐答案

您可以传递一个过滤要发送的错误的函数:

from os import getenv


SENTRY_URL = getenv('SENTRY_URL')

if SENTRY_URL:
    from sentry_sdk import init
    from sentry_sdk.integrations.django import DjangoIntegration
    from sentry_sdk.integrations.redis import RedisIntegration
    from sentry_sdk.integrations.celery import CeleryIntegration
  
    def before_send(event, hint):
       if 'exc_info' in hint:
          exc_type, exc_value, tb = hint['exc_info']
          if isinstance(exc_value, CustomError):  # Replace CustomError with your custom error 
             return None
       return event

    init(
        dsn=SENTRY_URL,
        integrations=[DjangoIntegration(), RedisIntegration(), CeleryIntegration()],
        traces_sample_rate=1.0,
        send_default_pii=True,
        debug=True,
        before_send=before_send
    )

您可以在documentation中找到更多信息.

Python相关问答推荐

如何更改分组条形图中条形图的 colored颜色 ?

Pandas:将多级列名改为一级

Django REST Framework:无法正确地将值注释到多对多模型,不断得到错误字段名称字段对模型无效'<><>

需要帮助重新调整python fill_between与数据点

在matplotlib中删除子图之间的间隙_mosaic

在Python中使用if else或使用regex将二进制数据如111转换为001""

如何在Python中使用Pandas将R s Tukey s HSD表转换为相关矩阵''

Flash只从html表单中获取一个值

在不同的帧B中判断帧A中的子字符串,每个帧的大小不同

Python Pandas—时间序列—时间戳缺失时间精确在00:00

在方法中设置属性值时,如何处理语句不可达[Unreacable]";的问题?

在matplotlib中使用不同大小的标记顶部添加批注

polars:有效的方法来应用函数过滤列的字符串

如何反转一个框架中列的值?

删除Dataframe中的第一个空白行并重新索引列

我怎么才能用拉夫分拣呢?

Pythonquests.get(Url)返回Colab中的空内容

如何在python tkinter中绑定键盘上的另一个回车?

迭代工具组合不会输出大于3的序列

try 第二次训练新的JAX+Equinox模型时,具有多个元素的数组的真值不明确(&Q)