I recently upgraded a site from Rails 2 to Rails 3 and moved it to Heroku. Once the upgrade was complete, I eagerly opened up the NewRelic performance monitoring tools to see how much speedier the application had become.
To my dismay, the charts were all completely blank. I carried out the usual debugging steps … turned up the NewRelic agent logging verbosity … but I couldn’t find anything wrong. Then I discovered that NewRelic has a development mode —which logs requests made locally. I turned this on and took a look at these charts. They were also completely blank! So I realized that the problem was not that my application wasn’t properly reporting information to the NewRelic servers, the problem was that the application wasn’t even logging it correctly.
I opened up RubyMine’s trusty ‘External Libraries’ menu and started placing breakpoints in the newrelic_rpm
gem,
hoping to find the source of the problem. Hours later I eventually discovered the problem:
NewRelic overrides the ActionController#process_action
method to initialize its performance monitoring code. This
trick is somewhat well known and other codebases may well fiddle with this method as well. In my case, the (Rails 2 era)
user session / state (pre-Devise) code uses alias_method_chain
on this method, renaming it to
process_action_with_current_user_assignment
and process_action_without_current_user_assignment
. Renaming the method
in this way was blocking NewRelic from working correctly.
Once I knew that this was the problem, I was able to come up with a MonkeyPatch to get NewRelic to allow other pieces
of code to use alias_method_chain
on the process_action
method as well.
Place the following code into your /config/initializers
directory:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
Credit to: https://gist.github.com/959784