Frage

I've got problem with monitoring my app with New Relic.

I have latest Spree engine mounted in my routes and own controller to serve as root.

For some reason, New Relic gathers only data from this root route, any call to Spree JSON API is ignored and don't show up in Dashboard, so I can see only one transaction and it's pretty useless.

Is there any way to enable monitoring on whole mounted app? Am I missing something?

War es hilfreich?

Lösung

As long as you're running on Rails 4.0 or later, adding the following to app/controllers/spree/api/base_controller_decorator.rb or some equivalent location should get instrumentation wired up:

class Spree::Api::BaseController
  include ActionController::Instrumentation
end

This works because on Rails 4.0 and later New Relic's controller instrumentation is based off ActiveSupport::Notifications, and include ActionController::Instrumentation gets those events flowing.

Andere Tipps

My guess is that this is happening because Spree's API is inheriting from ActionController::Metal, where NewRelic doesn't hook into.

Check here: https://github.com/spree/spree/blob/6ac62c32f91e6626b338564aab7a7ad570cbd4c3/api/app/controllers/spree/api/base_controller.rb#L5

This is probably a good argument for switching away from this within Spree, so please submit an issue for that.

I've found a way to bypass the problem in this article.

Create app/controllers/spree/api/base_controller_decorator.rb with following code:

require 'new_relic/agent/instrumentation/action_controller_subscriber'
require 'new_relic/agent/instrumentation/rails4/action_controller'

Spree::Api::BaseController.class_eval do
  before_filter :check_for_user

  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
  include NewRelic::Agent::Instrumentation::Rails4::ActionController

  NewRelic::Agent::Instrumentation::ActionControllerSubscriber \
    .subscribe(/^process_action.action_controller$/)

end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top