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

Do not report rendered errors except 500 #51107

Conversation

nvasilevski
Copy link
Contributor

TLDR Context

#51050 change results in error tracking service being polluted with ActionController::RoutingError which are not actionable and we don't want them there

Context

In 4067c95 ActionDispatch::Executor started to report all errors, even the ones that were "handled" by the application. This leads to errors like ActionController::RoutingError polluting error trackers while not being actionable since they do not represent an exceptional situation.

This commit changes the behavior to only report errors that are not considered "handled" based on the ActionDispatch::ExceptionWrapper.rescue_responses list.

Alternative solution

What I have considered and what might actually be a better solution for the long-term is to report "handled" exceptions as handled: true. This way subscribers can decide how they want to proceed reporting something that has already been handled. Example: While I strongly believe that ActionController::RoutingError should not be presented on the error tracker in the same way as something like raise "boom", I can see that some applications may want to soft-report them in a way that doesn't trigger any alerts and doesn't require any attention. For example It's totally expected to have ActionController::RoutingError exceptions but if the number of ActionController::RoutingError spikes it may indicate that either some link that used to be accessible became unaccessible or a wrong link was posted/rendered somewhere which makes such event actionable and worth reporting.

But regardless, ActionController::RoutingError (and similar) exceptions should not suddenly be reported as part of a patch version upgrade. It should be a major change with perhaps a configuration option to allow applications to adapt and make a decision on how to proceed.

I'm open for the discussion and eager to learn what are yours expectations on this behavior!

@rails-bot rails-bot bot added the actionpack label Feb 16, 2024
@@ -15,7 +15,9 @@ def call(env)
begin
response = @app.call(env)
if rendered_error = env["action_dispatch.exception"]
@executor.error_reporter.report(rendered_error, handled: false, source: "application.action_dispatch")
unless ExceptionWrapper.rescue_response?(rendered_error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this here, why we just don't add it to env["action_dispatch.exception"] if it isn't rescuable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do that. But we can add the exception to a different key in the env only if we want it to be reported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, my biggest concern was the use of ExceptionWrapper.rescue_response? in the executor. Feels like executor shouldn't ideally know about the wrapper.

We can't do that

Just to make sure we have the same understanding. Is that because exceptions_app (ActionDispatch::PublicExceptions by default) expects action_dispatch.exception header to be present?
What if we still pass the header to exceptions_app but drop it afterwards?

I guess using a different key makes more sense, I just wasn't sure if it's okay to add more headers. Let me try that!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I added a "action_dispatch.report_exception" boolean flag to indicate whether the exception should be reported or not. I felt like it's excessive to have two headers pointing to the same exception in case if it needs to be reported.

@nvasilevski nvasilevski force-pushed the report-handled-action-dispatch-errors-differently branch 2 times, most recently from 15003e6 to 5d5cc03 Compare February 16, 2024 18:29
@nvasilevski
Copy link
Contributor Author

cc @fractaledmind as you initially reported the issue and I was wondering if this tweak still aligns with your vision of the problem

In `4067c9565a5da78a72e375a2d959000147f02c34` `ActionDispatch::Executor`
started to report all errors, even the ones that were "handled" by the application.
This leads to errors like `ActionController::RoutingError` polluting error trackers
while not being actionable since they do not represent an exceptional situation.

This commit changes the behavior to only report errors that are not
considered "handled" based on the `ActionDispatch::ExceptionWrapper.rescue_responses` list.
@rafaelfranca rafaelfranca force-pushed the report-handled-action-dispatch-errors-differently branch from 5d5cc03 to a8d1d92 Compare February 16, 2024 19:19
@rafaelfranca rafaelfranca merged commit b8de253 into rails:main Feb 16, 2024
3 of 4 checks passed
@rafaelfranca rafaelfranca deleted the report-handled-action-dispatch-errors-differently branch February 16, 2024 19:35
rafaelfranca added a commit that referenced this pull request Feb 16, 2024
…-errors-differently

Do not report rendered errors except 500
@fractaledmind
Copy link
Contributor

I believe this does still solve the original problem. I like your thought for a future next step to set handled to true or false depending and then letting the subscribers decide what they want to do.

I will read the details of the rescuable check to ensure that it isn't too strict, but I expect it isn't and all important errors would be reported with this change.

rafaelfranca added a commit that referenced this pull request Feb 16, 2024
…-errors-differently

Do not report rendered errors except 500
@byroot
Copy link
Member

byroot commented Feb 16, 2024

What I have considered and what might actually be a better solution for the long-term is to report "handled" exceptions as handled: true. This way subscribers can decide how they want to proceed reporting something that has already been handled.

handled: true semantic, is to say that it didn't translate to a user visible error (e.g. connection error to the cache). Here it's different, it's more to mean it didn't end up as a server error.

So I think the current patch is fine, no need for a followup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants