Metal controller instrumentation

By default, the New Relic Ruby agent does not instrument ActionController::Metal controllers. This document describes how to have these controller actions appear on the APM Transactions page and overviews alongside those inheriting from ApplicationController for Rails 3 apps or higher.

Rails 4.0 or higher

Starting with Rails 4.0, New Relic's controller instrumentation uses ActiveSupport::Notifications. Including the ActionController::Instrumentation module ensures that controller events are fired from your Metal controller. This enables New Relic to instrument those actions.

class PlatinumController < ActionController::Metal
  include ActionController::Rendering

  def show
    render :text => "Here is some text"
  end

  # Ensure ActiveSupport::Notifications events are fired
  include ActionController::Instrumentation
end

Rails 3.0 through 3.2

Include NewRelic::Agent::Instrumentation::ControllerInstrumentation and call add_transaction_tracer for each action you want to instrument.

class SteelController < ActionController::Metal
  include ActionController::Rendering

  def show
    render :text => "Here is some text"
  end

  include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
  add_transaction_tracer :show
end

Rails 2.3

If you use the Rails::Rack::Metal class from Rails 2, you can instrument calls to your Metals as follows:

require 'newrelic_rpm'

class MyMetal < Rails::Rack::Metal
  def self.call(env)
    # ... your metal code ...
  end

  class << self
    include NewRelic::Agent::Instrumentation::ControllerInstrumentation
    add_transaction_tracer :call
  end
end

For more help

Join the discussion about Ruby in the New Relic Online Technical Community! The Technical Community is a public platform to discuss and troubleshoot your New Relic toolset.

If you need additional help, get support at support.newrelic.com.