Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger causes Sentry issue #37

Closed
simon-ccoms opened this issue Sep 11, 2024 · 14 comments · Fixed by #39
Closed

Logger causes Sentry issue #37

simon-ccoms opened this issue Sep 11, 2024 · 14 comments · Fixed by #39

Comments

@simon-ccoms
Copy link

The use of logger.error in validators causes an issue to be created in my Sentry integration whenever a recaptcha field fails for whatever reason.

I don't really care about these failures, as it's probably nothing to do with me - it's probably a valid reason for failure (score too low or whatever) - so I don't really want a new issue to be generated every time it happens. But I can't switch off the logger.

@llybin
Copy link
Owner

llybin commented Sep 11, 2024

            logger.error(
                "ReCAPTCHA validation failed due to value of action '%s'"
                " is not equal with defined '%s'.",
                action,
                self.recaptcha_action,
            )

perhaps it should be warning or even info level.

@simon-ccoms
Copy link
Author

Yeah, that should work. There's a couple of logger.error calls in that module - I'm getting caught on one of the others but I guess they should all be info level.

@llybin
Copy link
Owner

llybin commented Sep 11, 2024

let's see

http errors/request fails, I think it's an error

        logger.error(
            "ReCAPTCHA validation failed due to: %s",
            check_captcha.error_codes,
        )
        raise ValidationError(self.messages["captcha_invalid"], code="captcha_invalid")

it's probably the wrong key, nothing will work expected, imho it's an error

            logger.error(
                "The response contains score, reCAPTCHA v2 response doesn't"
                " contains score, probably secret key for reCAPTCHA v3",
            )
            raise ValidationError(self.messages["captcha_error"], code="captcha_error")

it's probably the wrong key, nothing will work expected, imho it's an error

            logger.error(
                "The response not contains score, reCAPTCHA v3 response must"
                " contains score, probably secret key for reCAPTCHA v2",
            )
            raise ValidationError(self.messages["captcha_error"], code="captcha_error")

it's INFO, sure it's not an error, this is legitimate logic

            logger.error(
                "ReCAPTCHA validation failed due to score of %s"
                " being lower than the required amount for action '%s'.",
                self.score,
                action,
            )

data sent for validation for another action, configuration problem/hackers/client bug/something similar like that
warning?

            logger.error(
                "ReCAPTCHA validation failed due to value of action '%s'"
                " is not equal with defined '%s'.",
                action,
                self.recaptcha_action,
            )

@simon-ccoms
Copy link
Author

That first one is the one I'm getting a lot of and it's not the wrong key. It's "browser error" which is some sort of network failure, I think. So not a lot I can do about it and the user can just try again and hope. Either way, I don't want it to cause an issue that I have to try and fix because I can't fix it.

@llybin
Copy link
Owner

llybin commented Sep 11, 2024

"ReCAPTCHA validation failed due to: %s", -- this one? what is in the details?

@simon-ccoms
Copy link
Author

ReCAPTCHA validation failed due to: ["browser-error"]

@llybin
Copy link
Owner

llybin commented Sep 11, 2024

@llybin llybin linked a pull request Sep 11, 2024 that will close this issue
@llybin
Copy link
Owner

llybin commented Sep 11, 2024

@simon-ccoms
Copy link
Author

Ugh, I didn't realise that the newer versions of your library require newer versions of Django and we're on a pretty old version so I can't use this fix, unfortunately.

@llybin
Copy link
Owner

llybin commented Sep 11, 2024

I will create a release with this change from previous version tomorrow

@llybin
Copy link
Owner

llybin commented Sep 11, 2024

Screenshot_20240911-222629

@simon-ccoms
Copy link
Author

Yeah, we're way behind - long story - we're on Django 2.2.9!

@llybin
Copy link
Owner

llybin commented Sep 11, 2024

Sorry, but support of 2.2 was removed 2 years ago d71a378

the time to ask bosses to make time to upgrade a stack :)

@llybin
Copy link
Owner

llybin commented Sep 11, 2024

There are 5 options:

  1. But you will mute real errors
LOGGING = {
    ...
    'loggers': {
        'drf_recaptcha: {
            'handlers': ['console'],
            'level': 'INFO',
        },
    },
}
  1. Mute in Sentry this error
  2. Sentry allow pre filter messages, see Sentry doc
  3. Upgrade to 4.2 Django (as far as I remember, it wasn't painful, not like with 1.* to 2.0)
  4. Monkey patch validator functions or copy into project this lib and modify

llybin added a commit that referenced this issue Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants