Rails Exception Notification 500 Errors

277 Views Asked by At

I'm running the Exception Notification gem on Rails 5. I have it setup the default way in config/environments/production.rb:

  Rails.application.config.middleware.use ExceptionNotification::Rack,
  email: {
    # deliver_with: :deliver, # Rails >= 4.2.1 do not need this option since it defaults to :deliver_now
    email_prefix: '[MFTA Error Notification] ',
    sender_address: %{"notifier" <[email protected]>},
    exception_recipients: %w{[email protected]}
  }

This works fine for standard errors when the site is up...

But shouldn't it send me a report on 500 server errors a well? Very randomly... about once a month or so... the rails app will crash on me and I'll need to redeploy it to get it to work again. But I won't even know that the site's down without a notification.

So is there some separate config... or even another Gem... to let me know when this happens?

1

There are 1 best solutions below

0
On

Since your app is hosted in aws, you can setup a healthcheck endpoint in your app and use a lambda function to ping it periodically. If there’s no 200 response, its very likely your app is down as serving a healthcheck is a dead simple thing which shouldnt fail.

Normally people would set a threshold say X consecutive health check failure within Y duration to verify that the app is down. But this would require your lambda function to be stateful. If you dont mind getting false alarm due to say deployment or server restart, you can forget about this.

Also, if you want the health check to be more performant, you can just implement your rack middleware to intercept this healthcheck request and return a 200 response. In that sense teh request doesnt has to go through all the stacks until it reach Rails