OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How can I prevent sentry from capturing events for some uncaught exceptions and logging messages?

  • Thread starter Thread starter user85461
  • Start date Start date
U

user85461

Guest
As recommended by Sentry's docs [1][2] for their new unified python sdk (sentry_sdk), I've configured it with my Django application to capture events on all exceptions or "error"-level logs:

Code:
import sentry_sdk
import logging
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_logging = LoggingIntegration(
    level=logging.DEBUG,
    event_level=logging.ERROR
)
sentry_sdk.init(
    dsn="{{sentry_dsn}}",
    integrations=[DjangoIntegration(), sentry_logging]
)

However, since this hooks directly into python's logging module and internal exception handling, it means anything that uses this Django environment will be shipping events to sentry. There are some tasks (such as interactive manage.py commands, or work in the REPL) that need the Django environment, but for which I don't want events created in Sentry.

Is there a way to indicate to sentry that I'd like it to not capture events from exceptions or logging calls for the current task? Or a way to temporarily disable it after it's been globally configured?
<p>As recommended by Sentry's docs <a href="https://docs.sentry.io/platforms/python/logging/" rel="noreferrer">[1]</a><a href="https://docs.sentry.io/platforms/python/django/" rel="noreferrer">[2]</a> for their new unified python sdk (<code>sentry_sdk</code>), I've configured it with my Django application to capture events on all exceptions or "error"-level logs:</p>

<pre><code>import sentry_sdk
import logging
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_logging = LoggingIntegration(
level=logging.DEBUG,
event_level=logging.ERROR
)
sentry_sdk.init(
dsn="{{sentry_dsn}}",
integrations=[DjangoIntegration(), sentry_logging]
)
</code></pre>

<p>However, since this hooks directly into python's logging module and internal exception handling, it means anything that uses this Django environment will be shipping events to sentry. There are some tasks (such as interactive manage.py commands, or work in the REPL) that need the Django environment, but for which I <em>don't</em> want events created in Sentry.</p>

<p>Is there a way to indicate to sentry that I'd like it to <em>not</em> capture events from exceptions or <code>logging</code> calls for the current task? Or a way to temporarily disable it after it's been globally configured?</p>
 
Top