Using New Relic to monitor a Padrino Application

Getting New Relic hooked into your Padrino application isn’t too hard – there are a just a few gotchas.

(Before starting, make sure you have a valid config/new_relic.yml configuration file in place.)

If you’ve tried this already, you may have run into this error:

TypeError - can't convert String into Integer:
.../newrelic_rpm-3.1.0/lib/new_relic/agent/instrumentation/sinatra.rb:36:in `[]'

The padrino-rpm gem fixes the bug that causes this error. Which brings us to step 1 – install or bundle padrino-rpm from github.

gem 'padrino' # Padrino needs to be loaded first!
gem 'padrino-rpm', :git => 'https://github.com/Asquera/padrino-rpm.git'

Require the gems in order within your app or apps.rb:

require 'padrino'
require 'padrino-rpm'
require 'newrelic_rpm'

The padrino_rpm gem relies on before_load and after_load hooks to add its instrumentation. So, make sure your Padrino application initializes using

Padrino.load!

or else the instrumentation won’t take effect.

Once these changes are in place, restart your server and tail log/newrelic_agent.log. You should now see New Relic reporting and your pages working.

Here a link to New Relic support that may contain more information:

https://support.newrelic.com/help/discussions/support/7034-newrelic-sinatra-i...

Bonus Points

New Relic now supports end-user monitoring via the injection of JavaScript into your page’s layout. By default this doesn’t take effect within Sinatra/Padrino (or at least I dont think). You can still get it to work by placing these calls in the appropriate places of your layout.

With the head tag:

= NewRelic::Agent.browser_timing_header

And just before the end of your body tag:

= NewRelic::Agent.browser_timing_footer

Load up a page using the layout and make sure you see that both JavaScript tags are outputted into your HTML.

After a few minutes head over to New Relic and you should find some neat browser metrics about DOM Performance and Page Rendering.

Update

Find the Rubygem here. Many thanks to @Argorak.