如何忽略Sentry(不要发送它们)的某些错误?

发布于 2025-02-11 07:23:31 字数 697 浏览 0 评论 0原文

我有一个基于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,
    )

我都会从例外继承一个自定义词,

每次提出CustomError Sentry-SDK时,

然后将其发送给DSN-url。我想忽略一些错误或类似的错误。 我该怎么做?

I have a project based on django (3.2.10) and sentry-sdk (1.16.0)
There is my sentry-init file:

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,
    )

I have a CustomError inherited from Exception

Every time I raise the CustomError sentry-sdk sends it to the dsn-url.

I want to ignore some class of error or something like this.
How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痞味浪人 2025-02-18 07:23:31

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

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
    )

您可以在文档

You can pass a function that filters the errors to be sent:

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
    )

You can find more info in the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文