• English日本語한국어
  • Log inStart now

Metal controller instrumentation

By default, the New Relic Ruby agent does not instrument ActionController::Metal controllers. This is in keeping with the philosophy that the Metal controller provides only the bare minimum interface needed to deliver a valid Rack app. It's generally up to you to embellish the Metal Controllers as needed. 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
# Uncomment the following line to include New Relic helper methods, such as newrelic_ignore or add_method_tracer
# include NewRelic::Agent::Instrumentation::ControllerInstrumentation
end

Rails 3.0 through 3.2

Method 1

The following method auto-instruments all Metal controller actions just as with the Base Controller.

Include NewRelic::Agent::Instrumentation::ControllerInstrumentation and NewRelic::Agent::Instrumentation::Rails3::ActionController at the bottom of your Metal Controller classes:

class SteelController < ActionController::Metal
include ActionController::Rendering
def show
render :text => "Here is some text"
end
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
include NewRelic::Agent::Instrumentation::Rails3::ActionController
end

Method 2

The following example enables you to opt in to tracing only specific action methods of the Metal controller.

Include NewRelic::Agent::Instrumentation::ControllerInstrumentation and call add_transaction_tracer for each method instrumentation:

class SteelController < ActionController::Metal
include ActionController::Rendering
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
def show
render :text => "Here is some text"
end
add_transaction_tracer :show
end

Method 3

The final example is a more general way of adding tracing of the method that will work in any class, not just Metal Controller class.

Include NewRelic::Agent::MethodTracer and call add_method_tracer for each method instrumentation:

class SteelController < ActionController::Metal
include ActionController::Rendering
include NewRelic::Agent::MethodTracer
def show
render :text => "Here is some text"
end
add_method_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
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.