• EnglishEspañol日本語한국어Português
  • ログイン今すぐ開始

この機械翻訳は、参考として提供されています。

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.

問題を作成する

メタルコントローラの計測器

デフォルトでは、NewRelicRubyエージェントはActionController::Metalコントローラーをインストルメントしません。これは、Metalコントローラーが有効なRackアプリを提供するために必要な最小限のインターフェースのみを提供するという哲学と一致しています。通常、必要に応じてメタルコントローラーを装飾するのはあなた次第です。このドキュメントでは、これらのコントローラーアクションをAPMトランザクションページに表示する方法と、Rails3以降のアプリのApplicationControllerから継承するアクションの概要について説明します。

Rails 4.0以上

Rails 4.0以降、NewRelicのコントローラーインストルメンテーションはActiveSupport::Notificationsを使用します。 ActionController::Instrumentationモジュールを含めると、コントローラーイベントがMetalコントローラーから確実に発生します。これにより、NewRelicはこれらのアクションをインストルメント化できます。

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

方法1

以下のメソッドは、ベースコントローラと同様に、すべてのMetalコントローラのアクションを自動的にインストルメントします。

MetalControllerクラスの下部にNewRelic::Agent::Instrumentation::ControllerInstrumentationNewRelic::Agent::Instrumentation::Rails3::ActionControllerを含めます。

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

方法2

次の例では、Metalコントローラの特定のアクション・メソッドのみのトレースをオプトインすることができます。

メソッドインストルメンテーションごとにNewRelic::Agent::Instrumentation::ControllerInstrumentationを含め、{ add_transaction_tracer }を呼び出します。

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

方法3

最後の例は、メソッドのトレースを追加するより一般的な方法で、Metal Controllerクラスだけでなく、どのクラスでも動作します。

メソッドインストルメンテーションごとにNewRelic::Agent::MethodTracerを含め、{ add_method_tracer }を呼び出します。

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

Rails 2のRails::Rack::Metalクラスを使用する場合は、次のようにMetalsへの呼び出しを計測できます。

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株式会社。

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