Kentaro Kuribayashi's blog

Software Engineering, Management, Books, and Daily Journal.

Shipped exception_notification-hato_notifier

Having been inspired by makimoto's hack, I also created another custom notifier for exception_notification that adds exception notification feature (as its name shows) to Rack applications.

My one sends notifications via Hato that is also written by me and allows us to manage where to relay coming messages. With the custom notifier, you can just send any exception notification to Hato server and let the server to relay the messages according to the methods you set in advance.

Here I'll show you an example to use this notifier in a Sinatra application (it's too facticious, though ;)):

require 'sinatra/base'
require 'exception_notification'
require 'exception_notifier/hato_notifier'

class ExampleApp < Sinatra::Base
  use ExceptionNotification::Rack,
    hato: {
      host:    'localhost',
      port:    9699,
      api_key: 'example',
      template: {
        tag:     ->(exception, options) { "exception.#{exception.class}" },
        message: ->(exception, options) { "Exception: #{exception.class}: #{exception.message}" },
      },
    }

  class Exception < ::Exception; end

  get '/' do
    raise Exception.new('Example exception')
  end
end

Once you configure the notifier, all exception notifications will be sent to Hato with tags by which your Hato server detects where and how to relay the messages. Hato has plugin architecture and there have been already some plugins listed below:

I think it's more efficient that you manage where or how to relay messages in one place using such tools as Hato. To add custom notifiers at each time when you need is laborious. To manage the methods in a place is better, I'm convinced.

Enjoy!