From 8f0c5e00ff61cc2f61acedfb35de756bd0e95437 Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Wed, 16 Oct 2013 10:32:06 +0200 Subject: Instrument the generation of Action Mailer messages The processing of outbound mail is instrumented with the key `process.action_mailer`. The payload includes the mailer name as well as the mailer method. --- actionmailer/lib/action_mailer/base.rb | 15 +++++++++++---- actionmailer/lib/action_mailer/log_subscriber.rb | 7 +++++++ 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'actionmailer/lib/action_mailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index ada86fbc4f..6357805198 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -511,11 +511,18 @@ module ActionMailer process(method_name, *args) if method_name end - def process(*args) #:nodoc: - lookup_context.skip_default_locale! + def process(method_name, *args) #:nodoc: + payload = { + :mailer => self.class.name, + :action => method_name + } - super - @_message = NullMail.new unless @_mail_was_called + ActiveSupport::Notifications.instrument("process.action_mailer", payload) do + lookup_context.skip_default_locale! + + super + @_message = NullMail.new unless @_mail_was_called + end end class NullMail #:nodoc: diff --git a/actionmailer/lib/action_mailer/log_subscriber.rb b/actionmailer/lib/action_mailer/log_subscriber.rb index 8467d45986..eb6fb11d81 100644 --- a/actionmailer/lib/action_mailer/log_subscriber.rb +++ b/actionmailer/lib/action_mailer/log_subscriber.rb @@ -19,6 +19,13 @@ module ActionMailer debug(event.payload[:mail]) end + # An email was generated. + def process(event) + mailer = event.payload[:mailer] + action = event.payload[:action] + debug("\n#{mailer}##{action}: processed outbound mail in #{event.duration.round(1)}ms") + end + # Use the logger configured for ActionMailer::Base def logger ActionMailer::Base.logger -- cgit v1.2.3