question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sentry is not filtering out NotAuthenticatedError from Django

See original GitHub issue

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.5.8

Steps to Reproduce

I am using Django(2.0.13) with graphql. Steps:

  1. Init sentry with before_send method and filter out NotAuthenticated Exception i.e. return None for this error.
  2. Raise an NotAuthenticated exception in your code for a request.
  3. Notice that error is still reported to sentry.io and not filtered out.

Code sample:

from django.core.exceptions import PermissionDenied
from rest_framework.exceptions import NotAuthenticated, AuthenticationFailed

def before_send(event, hint):
        """Filter out following exceptions from sentry, since these are quite common"""
        if 'exc_info' in hint:
            exc_type, exc_value, tb = hint['exc_info']
            if isinstance(exc_value, (
                    NotAuthenticated,
                    AuthenticationFailed,
                    PermissionError,
                    PermissionDenied,
            )):
                return None
        return event


sentry_sdk.init(
            dsn=env("DJANGO_SENTRY_DSN"),
            integrations=[DjangoIntegration(), CeleryIntegration()],
            send_default_pii=True,
            debug=env.bool('DJANGO_SENTRY_DEBUG', default=False),
            before_send=before_send,
        )

Expected Result

NotAuthenticated exception should not be sent to sentry.io.

Actual Result

NotAuthenticated sent to sentry.io.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mshoaibprocommented, Mar 31, 2022

Thank you so much. I really appreciate it.

0reactions
mshoaibprocommented, Mar 31, 2022

It answers my question - if you like, you can close this issue or perhaps leave it open for enhancement. It’s all up to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filtering for Django - Sentry Documentation
The Sentry SDKs have several configuration options to help you filter out events. We also offer Inbound Filters to filter events in sentry.io....
Read more >
How can I filter out errors on sentry to avoid consuming my ...
According to the sentry documentation on quota usage, events filtered via inbound filters are not affecting your quota.
Read more >
Filtering and Sampling Events for Django
When a string or a non-error object is raised, Sentry creates a synthetic exception so you can get a basic stack trace. This...
Read more >
Allow filtering/custom handling of with_locals values #217
I am trying to figure out if the Django integration should change the ... a local variable in the stack of an error...
Read more >
Sentry is great for tracking Django errors - Matt's Dev Blog
You've deployed a Django app to a webserver and now it's not working. Your app is throwing 500 Internal Server Errors - what's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found