Sentry flagging www sites as error

I am using django (2.1.10) with sentry. I have the redirect_to_non_www module. There is no issue, yet sentry flags this. Am I missing a configuration option here?

Can you elaborate? I don’t understand what you mean.

Sure. I have domainname.com (fake name). I am using the python module django-redirect-to-non-www, so that when a user requests https://www.domainname.com, it will serve domainname (without the www)

I think I found the issue. Might not do anything with sentry. I’ll update when I fix it.

Edit: It doesn’t have anything to do with sentry. I am missing something on django and not properly handling the www request.

If this turns out to be an issue with Sentry, could you provide a link to the issue that Sentry shows you?

@untitaker taker Here’s the link:

https://sentry.io/organizations/zluwcv8urv/issues/1095471291/events/56465f2508e2411b96ff7c600b7f6b7e/?project=1495529

I am not sure if this is a django issue or sentry issue. It’s not exactly an error. Django’s get_current_site returns a site after running into this error. This is causing a lot of false “issues” and cluttering actual issues.

I can’t ignore all the Site.DoesNotExist errors, though currently, doing that (ignoring all) is the easiest solution. This happens when any user requests one of our sites with www.

I have a list of sites using django, and I need to configure sentry to ignore this error on these sites; but catch everything else.

Okay, I would use before-send to filter that exception type out so you at least don’t use your quota for this noise:

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, Site.DoesNotExist):
            return None
    return event

sentry_sdk.init(before_send=before_send)

It’s unclear to me how we would distinguish this error from legitimate programming errors from within the SDK.

That helps a lot. I am new to using sentry and the function you wrote gave me a proper direction to look things up. Thank you.

@untitaker - in regards to filtering the above exception - I put this snippet in the settings.py of my django project. However, at this point of code the setup is not complete. So, the site.doesnotexist might throw a NameError (“Site is not defined”). So far, I haven’t seen it.

Could you provide any insight here?

@BlitzKraft you could try to import the exception class within your before_send function (would wrap in a catch-all try-except) or do a match based on obj.__class__.__name__ instead of type.