I have Sentry configured to capture all errors from a Django+Celery application. It works ok, but I'm finding an obnoxious use case is when I have to restart my Celery workers, PostgreSQL database or messaging server, which causes thousands of various kinds of "database/messaging server cannot be reached" errors. This pollutes the Sentry reports, and sometimes even exceeds my event quota.
Their docs mention an "ignore_exceptions" parameter, but it's in their old deprecated client that I'm not using, nor is recommended to be used for new projects. How would you do this in the new API?
Using Try Exceptblock to catch the ZeroDivisionError exception and ignore it. In the above code, we catch the ZeroDivisionError exception and use pass to ignore it. So, when this exception happens, nothing will be thrown and the program will just keep running by ignoring the zero number.
The Sentry SDK will automatically capture and report any unhandled error that happens in your application runtime without any additional configuration or explicit handling.
Step 2: Handle the errorGo to your email and open the notification from Sentry. Click "View on Sentry" to view the full details and context of this error in your Sentry account. Note that Sentry aggregates similar errors (events) into one issue. In your account, scroll down to the "Exception" stack trace.
You can use before-send to filter errors by arbitrary criteria. Since it's unclear what you actually want to filter by, here's an example that filters by type. However, you can extend it with custom logic to e.g. match by exception message.
import sentry_sdk
def before_send(event, hint):
if 'exc_info' in hint:
exc_type, exc_value, tb = hint['exc_info']
if isinstance(exc_value, (IgnoredErrorFoo, IgnoredErrorBar)):
return None
return event
sentry_sdk.init(before_send=before_send)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With