Skip to content

Instrument the generation of Action Mailer messages - #12556

Merged
josevalim merged 1 commit into
rails:masterfrom
dasch:dasch/nstrument-am-processing
Oct 20, 2013
Merged

Instrument the generation of Action Mailer messages#12556
josevalim merged 1 commit into
rails:masterfrom
dasch:dasch/nstrument-am-processing

Conversation

@dasch

@dasch dasch commented Oct 16, 2013

Copy link
Copy Markdown
Contributor

Currently, only the time spent sending a mail is instrumented in Action Mailer. The time it takes to render the views and building the mail object itself is not instrumented at all.

This PR adds very basic instrumentation. More data, such as view rendering time, database time, and really anything, can be added later.

Comment thread actionmailer/lib/action_mailer/base.rb Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if it is worthy breaking ActionMailer::Base in two modules now. One with all the delivery stuff and another one on top that would add the instrumentation, following ActionController pattern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that - I actually had a branch based off the first one that did this, but obviously it didn't work since it hooked into deliver_mail, which only happens after the mail has been generated.

Would it be okay to get this in first and then work on a refactoring later? It would probably require moving the existing #process code into a module (Implementation) and then including that and a separate Instrumentation module. It could easily obfuscate the content of this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also want to use the same mechanism for including additional messages in the log line, e.g. Active Record includes a module that implements an add_info_to_payload method.

@dasch

dasch commented Oct 16, 2013

Copy link
Copy Markdown
Contributor Author

Just a few questions:

  • Is "generate" the right word to use here?
  • Do you want the log to be in a different format?

Comment thread actionmailer/lib/action_mailer/base.rb Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe process.action_mailer to mimic action controller as well?

@josevalim

Copy link
Copy Markdown
Contributor

The logged message is fine, we can always adjust it later. :)

@dasch

dasch commented Oct 16, 2013

Copy link
Copy Markdown
Contributor Author

@josevalim should I include the mailer method in the instrumentation? Right now only the name of the mailer itself is included.

@dasch

dasch commented Oct 16, 2013

Copy link
Copy Markdown
Contributor Author

Okay, I've included the action - seems to be prudent. Do you want me to rebase?

@josevalim

Copy link
Copy Markdown
Contributor

Yes, please rebase. I have also added a message about the event name. IMO it should be called process instead of generate. Any reason why not to?

@dasch

dasch commented Oct 16, 2013

Copy link
Copy Markdown
Contributor Author

Nah, I'll change it to "process".

@dasch

dasch commented Oct 16, 2013

Copy link
Copy Markdown
Contributor Author

Actually, "process" makes it sound like we handle an incoming mail, "an email was processed".

@dasch

dasch commented Oct 16, 2013

Copy link
Copy Markdown
Contributor Author

Naming is hard... what about "render"? Although actual rendering happens multiple times :-/

@dasch

dasch commented Oct 16, 2013

Copy link
Copy Markdown
Contributor Author

Okay, I've renamed it to "process" and squashed. I guess we'll find out if the name is confusing or not. If you merge this I'll start work on refactoring and adding support for view rendering time and db time.

Comment thread actionmailer/lib/action_mailer/base.rb Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May you use 1.9 hash style?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that the convention in Rails nowadays?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dasch

dasch commented Oct 17, 2013

Copy link
Copy Markdown
Contributor Author

The build is failing due to some other thing :-/

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.
@robin850

Copy link
Copy Markdown
Member

@dasch : Yes, this is not your fault ; this failure is present in lots of pull requests.

@josevalim : Could you please review and merge this one if everything is ok ? :-)

josevalim pushed a commit that referenced this pull request Oct 20, 2013
Instrument the generation of Action Mailer messages
@josevalim
josevalim merged commit fdfc967 into rails:master Oct 20, 2013
@dasch

dasch commented Oct 21, 2013

Copy link
Copy Markdown
Contributor Author

Thanks! I'll get started on more granular metrics as soon as I have the time.

@robin850

Copy link
Copy Markdown
Member

Thank you guys!

@dasch
dasch deleted the dasch/nstrument-am-processing branch April 28, 2014 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants