• EnglishEspañol日本語한국어Português
  • EntrarComeçar agora

Esta tradução de máquina é fornecida para sua comodidade.

In the event of any inconsistency between the English version and the translated version, the English versionwill take priority. Please visit this page for more information.

Criar um problema

Instrumentação de controlador metálico

Por padrão, o agente New Relic Ruby não instrumenta ActionController::Metal controladores. Isso está de acordo com a filosofia de que o controlador Metal fornece apenas a interface mínima necessária para fornecer um aplicativo Rack válido. Geralmente depende de você embelezar os controladores de metal conforme necessário. Este documento descreve como fazer com que essas ações do controlador apareçam na página Transactions do APM e fornece visões gerais junto com aquelas herdadas de ApplicationController para aplicativos Rails 3 ou superior.

Rails 4.0 ou superior

A partir do Rails 4.0, a instrumentação do controlador da New Relic usa ActiveSupport::Notifications. Incluir o módulo ActionController::Instrumentation garante que os eventos do controlador sejam disparados a partir do seu controlador Metal. Isso permite que a New Relic instrumentalize essas ações.

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 a 3.2

Método 1

O método a seguir instrumenta automaticamente todas as ações do controlador Metal, assim como acontece com o Controlador Base.

Inclua NewRelic::Agent::Instrumentation::ControllerInstrumentation e NewRelic::Agent::Instrumentation::Rails3::ActionController na parte inferior de suas 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::ActionController
end

Método 2

O exemplo a seguir permite que você opte por rastrear apenas métodos de ação específicos do controlador Metal.

Inclua NewRelic::Agent::Instrumentation::ControllerInstrumentation e chame add_transaction_tracer para cada instrumentação de método:

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

Método 3

O exemplo final é uma maneira mais geral de adicionar rastreamento do método que funcionará em qualquer classe, não apenas na classe Metal Controller.

Inclua NewRelic::Agent::MethodTracer e chame add_method_tracer para cada instrumentação de método:

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

Se você usar a classe Rails::Rack::Metal do Rails 2, poderá instrumentar chamadas para seus Metais da seguinte maneira:

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.