sentry-python
sentry-python copied to clipboard
ignore_errors parameter cannot ignore the specified exceptions.
Environment
SaaS (https://sentry.io/)
Steps to Reproduce
sentry_sdk.init(
dsn=os.getenv("SENTRY_DSN"),
integrations=[FlaskIntegration()],
environment=env,
ignore_errors=[AuthException]
)
AuthException
inherits from Exception
Expected Result
ignore AuthException
Actual Result
AuthException
is still captured
Product Area
Unknown
Link
No response
DSN
No response
Version
No response
Assigning to @getsentry/support for routing ⏲️
Routing to @getsentry/product-owners-settings-integrations for triage ⏲️
Routing to @getsentry/product-owners-settings-auth for triage ⏲️
@ReneGreen27 can you please transfer this issue to the SDK specific repository. This is not an Auth issue
@ReneGreen27 can you please transfer this issue to the SDK specific repository. This is not an Auth issue
maybe you don't understand my mind, I mean that ignore_errors
parameter does not work, instead of Auth issue
Hey @yuqiuwen, thanks for writing in.
I can't reproduce the issue. Here's my small Flask app:
import sentry_sdk
from flask import Flask
class AuthException(Exception):
pass
sentry_sdk.init(
dsn=<DSN>,
debug=True,
ignore_errors=[AuthException],
)
app = Flask(__name__)
@app.route("/autherror")
def auth_error():
raise AuthException('oh no')
return "ok"
Requesting /autherror
results in an Internal Server Error, as expected, but the AuthException
is not sent to Sentry.
Could you provide a minimal reproducible example to help us reproduce?
Hey @yuqiuwen, thanks for writing in.
I can't reproduce the issue. Here's my small Flask app:
import sentry_sdk from flask import Flask class AuthException(Exception): pass sentry_sdk.init( dsn=<DSN>, debug=True, ignore_errors=[AuthException], ) app = Flask(__name__) @app.route("/autherror") def auth_error(): raise AuthException('oh no') return "ok"
Requesting
/autherror
results in an Internal Server Error, as expected, but theAuthException
is not sent to Sentry.Could you provide a minimal reproducible example to help us reproduce?
this is my code:
class AuthException(Exception):
def __init__(self, message="", code: Enum = AppCode.AUTH_ERROR, errmsg=None):
super().__init__(message)
self.code = code.value
self.errmsg = errmsg
however, it worked for me using before_send
def before_send(event, hint):
if "exc_info" in hint:
exc_type, exc_value, tb = hint["exc_info"]
if isinstance(exc_value, (AuthException,)):
return None
return event
@yuqiuwen before_send
is another way to do it, great that that works for you. I'd still like to understand why ignore_errors
doesn't though, but for that I'd need a full example of a small app where ignore_errors
doesn't work. So far with my small app as outlined above (with your AuthException
) it all works as expected.
@yuqiuwen
before_send
is another way to do it, great that that works for you. I'd still like to understand whyignore_errors
doesn't though, but for that I'd need a full example of a small app whereignore_errors
doesn't work. So far with my small app as outlined above (with yourAuthException
) it all works as expected.
Maybe I see , because of logging the error, is right? if i don't log the error, it works well.
@app.errorhandler(AuthException)
def handle_auth_error(e):
logger.error(traceback.format_exc())
return make_response(str(e), code=e.code, errmsg=e.errmsg)
Maybe I see , because of logging the error, is right? if i don't log the error, it works well.
@app.errorhandler(AuthException) def handle_auth_error(e): logger.error(traceback.format_exc()) return make_response(str(e), code=e.code, errmsg=e.errmsg)
Right, it's our logging integration capturing it. Thanks for digging into it!
I think this could be solved by improving our ignored error detection to do something similar like you did in your before_send
.
I will put this in our backlog.
Maybe I see , because of logging the error, is right? if i don't log the error, it works well.
@app.errorhandler(AuthException) def handle_auth_error(e): logger.error(traceback.format_exc()) return make_response(str(e), code=e.code, errmsg=e.errmsg)
Right, it's our logging integration capturing it. Thanks for digging into it!
I think this could be solved by improving our ignored error detection to do something similar like you did in your
before_send
.I will put this in our backlog.
here's another question. Why is the log output incomplete?
here's another question. Why is the log output incomplete?
@yuqiuwen Where are you seeing this? Can you please send the URL of the page in Sentry?
here's another question. Why is the log output incomplete?
@yuqiuwen Where are you seeing this? Can you please send the URL of the page in Sentry?
This is the output of error.log, the part after the red line is truncated in the sentry
It probably got truncated by some part of the system because it was too long. Not sure off the top of my head if this is the SDK or the server doing this. Potentially might also just be a display thing. If you check the event JSON in Sentry (the button with the curly brackets), do you see the whole message?
It probably got truncated by some part of the system because it was too long. Not sure off the top of my head if this is the SDK or the server doing this. Potentially might also just be a display thing. If you check the event JSON in Sentry (the button with the curly brackets), do you see the whole message?
click the button still only shows part of the log
@yuqiuwen that is just our server side truncation because the message is too long. The ideal way is to not let this captured by logging but as a normal exception so that this goes into the stacktrace and not serialized into the message string.
You can also use logging.error('bla', exc_info=True)
and the stacktrace will be added to the sentry event.