< Return to Blog

Digging Deep with ActiveSupport::Notifications

Digging Deep with ActiveSupport::Notifications by Matt Sanders should not be missed.

ActiveSupport::Notifications is a powerful, under-utilized library which makes it easy to instrument and monitor your code. Rails exposes a tons of performance information which is easy to access and you can create your own events with a single line of code. This talk explores the basics of ActiveSupport::Notifications and gets into powerful techniques you can use to super-charge your monitoring and instrumentation.

This presentation covers the incredibly powerful instrumentation API within ActiveSupport.

ActiveSupport::Notifications.subscribe 'foo' do |*args|
  event = ActiveSupport::Notifications::Event.new(*args)
  event.name
  event.time
  event.end
  event.duration
  event.transaction_id
  event.payload
  # log or process payload...
end

I really liked how the API provides an Event class that makes handling all the parameters extremely easy. Don't miss out on ActiveSupport::LogSubscriber which will come in handy as well since ActionView, ActionController, and ActiveRecord all have one that inherits from ActiveSupport::LogSubscriber.

I've also contributed to Rails RDocs on this topic.