lib/new_relic/control/frameworks/rails.rb in ghazel-newrelic_rpm-3.1.0.1 vs lib/new_relic/control/frameworks/rails.rb in ghazel-newrelic_rpm-3.4.0.2

- old
+ new

@@ -1,12 +1,12 @@ -# Control subclass instantiated when Rails is detected. Contains -# Rails specific configuration, instrumentation, environment values, -# etc. require 'new_relic/control/frameworks/ruby' module NewRelic class Control module Frameworks + # Control subclass instantiated when Rails is detected. Contains + # Rails specific configuration, instrumentation, environment values, + # etc. class Rails < NewRelic::Control::Frameworks::Ruby def env @env ||= RAILS_ENV.dup end @@ -15,15 +15,31 @@ RAILS_ROOT.to_s else super end end + def logger + ::RAILS_DEFAULT_LOGGER + end # In versions of Rails prior to 2.0, the rails config was only available to - # the init.rb, so it had to be passed on from there. + # the init.rb, so it had to be passed on from there. This is a best effort to + # find a config and use that. def init_config(options={}) - rails_config=options[:config] + rails_config = options[:config] + if !rails_config && defined?(::Rails) && ::Rails.respond_to?(:configuration) + rails_config = ::Rails.configuration + end + # Install the dependency detection, + if rails_config && ::Rails.configuration.respond_to?(:after_initialize) + rails_config.after_initialize do + # This will insure we load all the instrumentation as late as possible. If the agent + # is not enabled, it will load a limited amount of instrumentation. See + # delayed_job_injection.rb + DependencyDetection.detect! + end + end if !agent_enabled? # Might not be running if it does not think mongrel, thin, passenger, etc # is running, if it things it's a rake task, or if the agent_enabled is false. log! "New Relic Agent not running." else @@ -34,16 +50,16 @@ end def install_browser_monitoring(config) return if @browser_monitoring_installed @browser_monitoring_installed = true - return if config.nil? || !config.respond_to?(:middleware) || !browser_monitoring_auto_instrument? + return if config.nil? || !config.respond_to?(:middleware) || ! browser_monitoring_auto_instrument? begin require 'new_relic/rack/browser_monitoring' config.middleware.use NewRelic::Rack::BrowserMonitoring log!("Installed New Relic Browser Monitoring middleware", :info) - rescue Exception => e + rescue => e log!("Error installing New Relic Browser Monitoring middleware: #{e.inspect}", :error) end end def install_developer_mode(rails_config) @@ -59,28 +75,33 @@ if @local_env.dispatcher_instance_id port = @local_env.dispatcher_instance_id.to_s =~ /^\d+/ ? ":#{local_env.dispatcher_instance_id}" : ":port" log!("NewRelic Agent Developer Mode enabled.") log!("To view performance information, go to http://localhost#{port}/newrelic") end - rescue Exception => e + rescue => e log!("Error installing New Relic Developer Mode: #{e.inspect}", :error) end - else + elsif rails_config log!("Developer mode not available for Rails versions prior to 2.2", :warn) end end def log!(msg, level=:info) - super unless should_log? - ::RAILS_DEFAULT_LOGGER.send(level, msg) - rescue Exception => e + if should_log? + logger = ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER + logger.send(level, msg) + else + super + end + rescue => e super end def to_stdout(message) - ::RAILS_DEFAULT_LOGGER.info(message) - rescue Exception => e + logger = ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER + logger.info(message) + rescue => e super end def rails_version @rails_version ||= NewRelic::VersionNumber.new(::Rails::VERSION::STRING) @@ -135,17 +156,9 @@ ::ActionController::Base.class_eval { include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim } end - def _install_instrumentation - super - if defined?(Rails) && Rails.respond_to?(:configuration) && Rails.configuration.respond_to?(:after_initialize) - Rails.configuration.after_initialize do - DependencyDetection.detect! - end - end - end end end end end