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 exceptions rescued by ActionDispatch #2264

Conversation

AlanGabbianelli
Copy link
Contributor

After upgrading to rails 6, we started seeing this error:
Mime::Type::InvalidMimeType "charset=utf-8" is not a valid MIME type
Example here:
https://sentry.io/organizations/govuk/issues/1549200925/?end=2020-03-06T12%3A00%3A23&environment=staging&project=202225&query=is%3Aunresolved+url%3Ahttps%3A%2F%2Fwww-origin.staging.govuk.digital%2Freport-an-unregistered-trader-or-business&start=2020-03-05T16%3A07%3A23&utc=true

This is because, even though these errors are rescued by ActionDispatch,
they still reach Sentry. Here's the explanation from Sentry's docs:

Rails catches exceptions in the ActionDispatch::ShowExceptions or
ActionDispatch::DebugExceptions middlewares, depending on the
environment. When rails_report_rescued_exceptions is true (it is by
default), Raven will report exceptions even when they are rescued by
these middlewares.

So, in order to stop this behaviour, we can set this option to be false.

Related PRs:

Trello card: https://trello.com/c/Ik7ulDXQ/1768-3-upgrade-frontend-to-rails-6

After upgrading to rails 6, we started seeing this error:
`Mime::Type::InvalidMimeType "charset=utf-8" is not a valid MIME type`
Example here:
https://sentry.io/organizations/govuk/issues/1549200925/?end=2020-03-06T12%3A00%3A23&environment=staging&project=202225&query=is%3Aunresolved+url%3Ahttps%3A%2F%2Fwww-origin.staging.govuk.digital%2Freport-an-unregistered-trader-or-business&start=2020-03-05T16%3A07%3A23&utc=true

This is because, even though these errors are rescued by ActionDispatch,
they still reach Sentry. Here's the explanation from Sentry's docs:
> Rails catches exceptions in the ActionDispatch::ShowExceptions or
> ActionDispatch::DebugExceptions middlewares, depending on the
> environment. When rails_report_rescued_exceptions is true (it is by
> default), Raven will report exceptions even when they are rescued by
> these middlewares.

So, in order to stop this behaviour, we can set this option to be false.

Related PRs:
- alphagov/email-alert-api#1138
- alphagov/govuk_app_config#137

Trello card: https://trello.com/c/Ik7ulDXQ/1768-3-upgrade-frontend-to-rails-6
@bevanloon bevanloon temporarily deployed to govuk-fronte-do-not-rep-nw7mdp March 6, 2020 18:46 Inactive
@thomasleese
Copy link
Contributor

Do we need both this change here and alphagov/govuk_app_config#137? It seems like we're likely to want to set rails_report_rescued_exceptions = false across all our applications, so should we set that in govuk_app_config instead. Presumably then we don't need to have so many Rails exceptions in the excluded_exceptions.

@kevindew
Copy link
Member

kevindew commented Mar 9, 2020

Oh this config option looks neat!

Toms suggestion to set this in govuk_app_config sounds great.

If you need a list of the rails default rescue responses they’re in this doc: https://guides.rubyonrails.org/configuring.html#configuring-action-dispatch

@AlanGabbianelli
Copy link
Contributor Author

AlanGabbianelli commented Mar 9, 2020

@thomasalanlee both changes have the effect of Mime::Type::InvalidMimeType not showing up in Sentry but they are different:

I think your suggested approach is better. If we take the config that acts on all errors and apply it to the gem that acts on all apps, we can stop all exceptions rescued by rails from appearing in Sentry for all apps that depend on govuk_app_config.

I'll close #2264 and alphagov/govuk_app_config#137 and open a new PR for that.

AlanGabbianelli pushed a commit to alphagov/govuk_app_config that referenced this pull request Mar 9, 2020
TL;DR: This stops exceptions rescued by rails from appearing in Sentry.

After upgrading `frontend` to rails 6, we started seeing this error:
`Mime::Type::InvalidMimeType "charset=utf-8" is not a valid MIME type`
Example here:
sentry.io/organizations/govuk/issues/1549200925/?end=2020-03-06T12%3A00%3A23&environment=staging&project=202225&query=is%3Aunresolved+url%3Ahttps%3A%2F%2Fwww-origin.staging.govuk.digital%2Freport-an-unregistered-trader-or-business&start=2020-03-05T16%3A07%3A23&utc=true

This is because, even though these errors are rescued by ActionDispatch,
they still reach Sentry. Here's the explanation from Sentry's docs:

> Rails catches exceptions in the ActionDispatch::ShowExceptions or
> ActionDispatch::DebugExceptions middlewares, depending on the
> environment. When rails_report_rescued_exceptions is true (it is by
> default), Raven will report exceptions even when they are rescued by
> these middlewares.

So, in order to stop this behaviour, we initially took a double
approach:
- set that option to be false for `frontend` in
[this PR](alphagov/frontend#2264) to stop all
exceptions rescued by rails (not only `Mime::Type::InvalidMimeType`)
from appearing in Sentry for `frontend`
- explicitly added `Mime::Type::InvalidMimeType` to the list of
excluded exceptions in
[this PR](#137) to stop
`Mime::Type::InvalidMimeType` from appearing in Sentry for all apps that
depend on `govuk_app_config`

Setting `rails_report_rescued_exceptions` to `false` here is better
because it will apply this config to all apps that depend on
`govuk_app_config`, making the two PRs above redundant and saving us
from making this change in every app.

Trello card: https://trello.com/c/Ik7ulDXQ/1768-3-upgrade-frontend-to-rails-6
AlanGabbianelli pushed a commit to alphagov/govuk_app_config that referenced this pull request Mar 9, 2020
TL;DR: This stops exceptions rescued by rails from appearing in Sentry.

After upgrading `frontend` to rails 6, we started seeing this error:
`Mime::Type::InvalidMimeType "charset=utf-8" is not a valid MIME type`
Example here:
https://www.sentry.io/organizations/govuk/issues/1549200925/?end=2020-03-06T12%3A00%3A23&environment=staging&project=202225&query=is%3Aunresolved+url%3Ahttps%3A%2F%2Fwww-origin.staging.govuk.digital%2Freport-an-unregistered-trader-or-business&start=2020-03-05T16%3A07%3A23&utc=true

This is because, even though these errors are rescued by ActionDispatch,
they still reach Sentry. Here's the explanation from Sentry's docs:

> Rails catches exceptions in the ActionDispatch::ShowExceptions or
> ActionDispatch::DebugExceptions middlewares, depending on the
> environment. When rails_report_rescued_exceptions is true (it is by
> default), Raven will report exceptions even when they are rescued by
> these middlewares.

So, in order to stop this behaviour, we initially took a double
approach:
- set that option to be false for `frontend` in
[this PR](alphagov/frontend#2264) to stop all
exceptions rescued by rails (not only `Mime::Type::InvalidMimeType`)
from appearing in Sentry for `frontend`
- explicitly added `Mime::Type::InvalidMimeType` to the list of
excluded exceptions in
[this PR](#137) to stop
`Mime::Type::InvalidMimeType` from appearing in Sentry for all apps that
depend on `govuk_app_config`

Setting `rails_report_rescued_exceptions` to `false` here is better
because it will apply this config to all apps that depend on
`govuk_app_config`, making the two PRs above redundant and saving us
from making this change in every app.

Trello card: https://trello.com/c/Ik7ulDXQ/1768-3-upgrade-frontend-to-rails-6
@AlanGabbianelli
Copy link
Contributor Author

Closing this in favour of alphagov/govuk_app_config#138

@AlanGabbianelli AlanGabbianelli deleted the do-not-report-exceptions-rescued-by-ActionDispatch branch March 9, 2020 11:32
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 this pull request may close these issues.

4 participants