Skip to content

production not seeing most exceptions #12

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

Closed
holman opened this issue Feb 7, 2024 · 14 comments · May be fixed by #15
Closed

production not seeing most exceptions #12

holman opened this issue Feb 7, 2024 · 14 comments · May be fixed by #15

Comments

@holman
Copy link

holman commented Feb 7, 2024

Hi! Digging the project thus far; really like the idea for something more straightforward, particularly for greenfield apps! Kudos.

I've got a weird situation that for some reason I can't sort out what might be happening. solid_errors works well and as-intended in development, but I'm having some issues in production- namely, it's not picking up any new exceptions generated by the app.

  • database tables were created and exist
  • a simple raise "boom" in a controller doesn't get caught and inserted into the errors table
  • solid_errors does get listed as a subscriber in Rails.error

If I manually trigger an exception using Rails' error API in the console, it shows up correctly:

Rails.error.record do
  1 + '1' # raises TypeError
end

Probably something obvious I'm missing, but just was a bit confusing since the app I'm trying it in is pretty straightforward; shouldn't be many changes from a stock production.rb at this point.

@fractaledmind
Copy link
Owner

Could you share the repo for me to debug?

@holman
Copy link
Author

holman commented Feb 7, 2024

Unfortunately it’s not a public repo.

@fractaledmind
Copy link
Owner

That's ok. I have reproduced the issue on my end. After some initial exploration, it appears that this is "standard" Rails behavior; that is, in production Rails doesn't report exceptions to the error reporter when the errors occur within the HTTP request lifecycle. The short answer, for now, is that in production Rails renders exceptions instead of raising exceptions, and the current code only reports raised exceptions.

I am trying to find someone who might know if there is any way to configure Rails to report rendered exceptions in production. There might not be such a config presently tho. If not, then I will work to open a PR to Rails to fix this major limitation of the error reporter. But, for now, there is no fix I can find. I will keep you updated here as I learn more tho.

@fractaledmind
Copy link
Owner

@holman: Can you test that this branch solves your problem? Update your Gemfile with this:

gem "solid_errors", github: "fractaledmind/solid_errors", branch: "patch-executor"

I don't like that I have to patch a Rails internal, but for now, that is the solution I can find.

@holman
Copy link
Author

holman commented Feb 7, 2024

Pretty wild hole we're in here!

I switched the branch, but strangely not seeing any difference.

@fractaledmind
Copy link
Owner

Now that is interesting, because it is working for me in production. If you get the chance to debug, you could add some manual logging to the patched Executor and see [1] if the patched Executor is being called, [2] if there is an action_dispatch.exception present, [3] if yes to both, if the error reporter present at that line is the one with the SolidErrors subscriber.

In my case, the problem simply that Rails only reports raised exceptions, and it swallows exceptions in production to render error pages. This patch to the executor to pull out any logged exceptions (stored in the action_dispatch.exception header) and report them is correctly storing errors and occurrences for me in my production application. So, I'm not immediately sure what might be different for you. I will need your help to debug on your side.

@fractaledmind
Copy link
Owner

I just connected this conversation to the issue that I have opened in Rails. Hopefully, someone at some point will get involved there and we can start making our way to a solution in Rails itself, because to my mind this is clearly a Rails bug. An error reporter that doesn't report errors in production is just about useless. I never expected it to not work in production (and, I didn't realize that it wasn't working because I was seeing errors from background jobs and just figured there weren't any production errors occurring 😅. So thank you for bringing this to my attention)

@holman
Copy link
Author

holman commented Feb 7, 2024

Hah, yeah no worries! It was pretty surprising to me, too. Will be interesting what comes out of the Rails issue; I’m subscribed there too.

Unfortunately I’m heading out for a few hours, but will dig into it more on my side later today. Thanks for all the digging thus far!

@trevorturk
Copy link

Have you looked into how Sentry works? I thought I remembered them working on changes to support Rails' new error subscriber stuff, maybe here: https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/lib/sentry/rails/railtie.rb#L51 via getsentry/sentry-ruby#1705 -- I haven't spent much time looking into this, but I noticed they have app.executor.error_reporter.subscribe for example.

@fractaledmind
Copy link
Owner

fractaledmind commented Feb 7, 2024

I dug into Honeybadger's source, but not Sentry's yet. I expect it to be similar. Honeybadger adds a middleware which pulls out the exception from the header.

@holman
Copy link
Author

holman commented Feb 7, 2024

Looks like the problem (at least in my setup) is this line:

ActiveSupport.on_load(:action_dispatch) do

That never seems to get loaded looks like? So it doesn't end up calling the ActionDispatch::Executor block. The monkeypatch does get loaded otherwise, though. (The higher-up initializer "solid_errors.active_support.notification_subscriber" block does run.)

@fractaledmind
Copy link
Owner

Right, just double checked and that is not a load hook that Rails actually calls. Just updated the code in that branch. Also going to keep digging and experimenting to see if we can make this not necessary.

@holman
Copy link
Author

holman commented Feb 12, 2024

Fixed in edge Rails!

@holman holman closed this as completed Feb 12, 2024
@mbajur
Copy link

mbajur commented Aug 6, 2024

Is rails ~> 7.0.1 also impacted by that issue? I have a similar case in which only exceptions raised inside Rails.errors.record are being saved by solid_errors

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.

4 participants