lib/new_relic/control/frameworks/rails.rb in newrelic_rpm-9.5.0 vs lib/new_relic/control/frameworks/rails.rb in newrelic_rpm-9.6.0

- old
+ new

@@ -8,10 +8,13 @@ module Frameworks # Control subclass instantiated when Rails is detected. Contains # Rails specific configuration, instrumentation, environment values, # etc. class Rails < NewRelic::Control::Frameworks::Ruby + BROWSER_MONITORING_INSTALLED_SINGLETON = NewRelic::Agent.config + BROWSER_MONITORING_INSTALLED_VARIABLE = :@browser_monitoring_installed + def env @env ||= (ENV['NEW_RELIC_ENV'] || RAILS_ENV.dup) end # Rails can return an empty string from this method, causing @@ -95,22 +98,31 @@ end end def install_browser_monitoring(config) @install_lock.synchronize do - return if defined?(@browser_monitoring_installed) && @browser_monitoring_installed + return if browser_agent_already_installed? - @browser_monitoring_installed = true + mark_browser_agent_as_installed return if config.nil? || !config.respond_to?(:middleware) || !Agent.config[:'browser_monitoring.auto_instrument'] begin require 'new_relic/rack/browser_monitoring' config.middleware.use(NewRelic::Rack::BrowserMonitoring) ::NewRelic::Agent.logger.debug('Installed New Relic Browser Monitoring middleware') rescue => e ::NewRelic::Agent.logger.warn('Error installing New Relic Browser Monitoring middleware', e) end end + end + + def browser_agent_already_installed? + BROWSER_MONITORING_INSTALLED_SINGLETON.instance_variable_defined?(BROWSER_MONITORING_INSTALLED_VARIABLE) && + BROWSER_MONITORING_INSTALLED_SINGLETON.instance_variable_get(BROWSER_MONITORING_INSTALLED_VARIABLE) + end + + def mark_browser_agent_as_installed + BROWSER_MONITORING_INSTALLED_SINGLETON.instance_variable_set(BROWSER_MONITORING_INSTALLED_VARIABLE, true) end def rails_version @rails_version ||= Gem::Version.new(::Rails::VERSION::STRING) end