For simple apps reporting exceptions is simple, but not obvious … have a snippet 🙂
– report context so it’s easy to find out where a bug happened
– do not report when user opened a session manually (tty)
– do not report regular system exit
# report any errors to airbrake, kubernetes takes care of restarting
require 'airbrake-ruby'
Airbrake.configure do |config|
config.project_id = 1234567
config.project_key = ENV.fetch('AIRBRAKE_API_KEY')
config.environment = ENV.fetch('RAILS_ENV')
config.ignore_environments = [:test, :development]
config.logger = Logger.new(STDOUT)
end
at_exit do
context = ['POD_NAME', 'POD_NAMESPACE', 'TAG'].
map { |k| [k.downcase, ENV[k]] }.to_h
Airbrake.notify_sync($!, context) if $! && !$stdout.tty?
end