0

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" <almost@got.me>},
    exception_recipients: %w{butnotquite@gmail.com}
  }

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?

mystic cola
  • 1,465
  • 1
  • 21
  • 39
  • 1
    I would dig in the logs to see what happened, either the Rails logs or if its not there then the logs of the server / host machine running your app. – Joel Blum Mar 29 '21 at 07:56
  • It's exactly what I did... No error at all. The last thing in the production.log is the successful render of index.html.erb. The last thing in the Puma error log is: [4120] - Worker 0 (pid: 4122) booted, phase: 0 4120] Early termination of worker. But that could've just been a reboot. Apparently the app had been down from March 18th until just before I made this message. Where else could I look? – mystic cola Mar 29 '21 at 09:58
  • Where are you running your app on ? (e.g aws, heroku etc) usually they have somewhere where they keep the machine logs – Joel Blum Mar 29 '21 at 10:30
  • I'm running AWS. Just not sure where to look. Apache logs? PHP logs? Who knows... – mystic cola Mar 30 '21 at 21:18
  • Anyway... I'm much more concerned with getting some sort of notification when the site is down. maybe I can train Google Analytics to do that or something. Was just hoping there was a way Exception Notification could do it. – mystic cola Mar 30 '21 at 21:19
  • u can take a look at different SAAS like newrelic. Not sure about the pricing, they usually have a free version that can get u pretty far. – Joel Blum Mar 31 '21 at 07:44
  • Ok. It turns out that Puma isn't starting on server restart. THAT's why the site goes down. Care to take a crack at that? :) – mystic cola Mar 31 '21 at 08:59
  • not sure what's happening exactly. why is it restarting in the first place and why can't it start then? if there's some error message what does it say? – Joel Blum Mar 31 '21 at 13:37
  • You don't understand... There is no error. Somehow my Puma simply isn't setup to start at boot. Normally it gets started on deploy. The server (as in the WHOLE server) restarts because I restart it because it says: "Reboot required" or something like that. Usually after updates. I'm only just now noticing that Puma doesn't start with everything else. Only after a deploy. – mystic cola Apr 01 '21 at 14:19

1 Answers1

1

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

daniel lee
  • 111
  • 3