Par défaut, l'agent Ruby New Relic n'instrumente pas ActionController::Metal
contrôleurs. Cela est conforme à la philosophie selon laquelle le contrôleur Metal ne fournit que l'interface minimale nécessaire pour fournir une application Rack valide. C'est généralement à vous d'embellir les contrôleurs en métal selon vos besoins. Ce document décrit comment faire apparaître ces actions de contrôleur sur la page APM Transactions et les aperçus à côté de celles héritées de ApplicationController
pour les applications Rails 3 ou supérieures.
Rails 4.0 ou supérieur
À partir de Rails 4.0, l'instrumentation du contrôleur de New Relic utilise ActiveSupport::Notifications
. L'inclusion du module ActionController::Instrumentation
garantit que les événements du contrôleur sont déclenchés depuis votre contrôleur Metal. Cela permet à New Relic d’ instrumenter ces 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::ControllerInstrumentationend
Rails 3.0 à 3.2
Méthode 1
La méthode suivante auto-instrumente toutes les actions du contrôleur Metal, tout comme avec le contrôleur de base.
Incluez NewRelic::Agent::Instrumentation::ControllerInstrumentation
et NewRelic::Agent::Instrumentation::Rails3::ActionController
au bas de vos classes Metal Controller :
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::ActionControllerend
Méthode 2
L'exemple suivant vous permet d'opter pour le traçage uniquement de méthodes d'action spécifiques du contrôleur Metal.
Inclure NewRelic::Agent::Instrumentation::ControllerInstrumentation
et appeler add_transaction_tracer
pour chaque instrumentation de méthode :
class SteelController < ActionController::Metal include ActionController::Rendering include NewRelic::Agent::Instrumentation::ControllerInstrumentation
def show render :text => "Here is some text" end add_transaction_tracer :showend
Méthode 3
L'exemple final est une manière plus générale d'ajouter le traçage de la méthode qui fonctionnera dans n'importe quelle classe, pas seulement dans la classe Metal Controller.
Inclure NewRelic::Agent::MethodTracer
et appeler add_method_tracer
pour chaque instrumentation de méthode :
class SteelController < ActionController::Metal include ActionController::Rendering include NewRelic::Agent::MethodTracer
def show render :text => "Here is some text" end add_method_tracer :showend
Rails 2.3
Si vous utilisez la classe Rails::Rack::Metal
de Rails 2, vous pouvez instrumenter les appels à vos métaux comme suit :
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 endend