Ruby on Kubernetes: Airbrake Exception Reporting

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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s