Moove It is now Qubika. For more information, visit our new website
Visit Qubika

The problem

In a project we are working on right now we needed to have a way to be notified when a crash on our application occurred, something that we though was going to we easily archived by a simple:

  gem install 'notify_me'

After some research we came to the conclusion that it was not going to so easy.

Existent solutions

If we where on rails we would just have done:

  gem install 'exception_notification'

And even tough i tried to run that gem outside of a rails application with some hacking i was unsuccessful and even i could have done it i felt like there where way too much dependencies for a simple notification email.

[toggle title_open=”Close Me” title_closed=”Exception Notification Dependencies” hide=”yes” border=”yes” style=”default” excerpt_length=”0″ read_more_text=”Show dependencies” read_less_text=”Read Less” include_excerpt_html=”no”]
i18n
multi_json
activesupport
builder
activemodel
erubis
journey
rack
rack-cache
rack-test
hike
tilt
sprockets
actionpack
mime-types
polyglot
treetop
mail
actionmailer
eventmachine
multipart-post
faraday
faraday_middleware
hashie
json
http_parser.rb
simple_oauth
twitter-stream
tinder
[/toggle]

So we started to take a look to other options like sinatra-enotify, it didn’t seem to cover our needs (you can’t even configure the email settings) and did not seem like a production ready gem. We also investigated bugsnag and airbrake again they seemed overkill for a simple email and even required an account (in some cases paid) on an external site to get them to work.

Path Taken

Having not found any existent solution and in the spirit to do some research and learning i embarked in the process of writing a simple exception notification gem for ruby.
Thus [RU]by [S]imple [E]xception [N]otification (rusen) was born.
The idea behind it was that it should we really easy to pickup and use but also provide more advanced options and control if it was needed.
The simplest way to use it is the following:

  gem install 'rusen'

then use it inside of your ruby script:
  require 'rusen'

  Rusen.settings.email_prefix = '[ERROR] '
  Rusen.settings.sender_address = 'some_email@example.com'
  Rusen.settings.exception_recipients = %w(dev_team@example.com test_team@example.com)
  Rusen.settings.smtp_settings = {
    :address => 'smtp.gmail.com',
    :port => 587,
    :domain => 'example.org',
    :authentication => :plain,
    :user_name => 'dev_team@moove-it.com',
    :password => 'xxxxxxx',
    :enable_starttls_auto => true
  }

  begin
    method.call
  rescue Exception => exception
    Rusen.notify(exception)
  end
It also comes with a rack middleware, how to setup that and the more complex ways to use it can be found in the documentation.

Conclusion

In the end it was an enjoyable experience in witch i learned a lot of things and the end result is something simple yet flexible that we can actually use in our production environment.

Get our stories delivered from us to your inbox weekly.