Class: NewRelic::Control::Frameworks::Rails
- Inherits:
-
Ruby
- Object
- NewRelic::Control
- Ruby
- NewRelic::Control::Frameworks::Rails
- Defined in:
- lib/new_relic/control/frameworks/rails.rb
Overview
Control subclass instantiated when Rails is detected. Contains Rails specific configuration, instrumentation, environment values, etc.
Direct Known Subclasses
Instance Attribute Summary
Attributes included from InstanceMethods
Instance Method Summary collapse
- #env ⇒ Object
-
#init_config(options = {}) ⇒ Object
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.
- #install_agent_hooks(config) ⇒ Object
- #install_browser_monitoring(config) ⇒ Object
- #install_developer_mode(rails_config) ⇒ Object
- #rails_config ⇒ Object
- #rails_root ⇒ Object
- #rails_version ⇒ Object
-
#root ⇒ Object
Rails can return an empty string from this method, causing the agent not to start even when it is properly in a rails 3 application, so we test the value to make sure it actually has contents, and bail to the parent class if it is empty.
Methods included from ClassMethods
#instance, #load_framework_class, #load_test_framework, #local_env, #new_instance, #newrelic_root, #reset
Methods included from InstanceMethods
#[], #app, #dispatcher, #framework, #init_plugin, #newrelic_root, #settings, #start_agent
Methods included from Instrumentation
#add_instrumentation, #install_instrumentation, #load_instrumentation_files, #load_samplers
Methods included from ServerMethods
#api_server, #convert_to_ip_address, #proxy_server, #resolve_ip_address, #server, #server_from_host
Methods included from Profiling
#profiling=, #profiling?, #profiling_available?
Instance Method Details
#env ⇒ Object
14 15 16 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 14 def env @env ||= RAILS_ENV.dup end |
#init_config(options = {}) ⇒ Object
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. This is a best effort to find a config and use that.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 46 def init_config(={}) @config = [:config] # 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. DependencyDetection.detect! end end if !Agent.config[:agent_enabled] # Might not be running if it does not think mongrel, thin, passenger, etc # is running, if it thinks it's a rake task, or if the agent_enabled is false. ::NewRelic::Agent.logger.info("New Relic Agent not running.") else install_developer_mode(rails_config) if Agent.config[:developer_mode] install_browser_monitoring(rails_config) install_agent_hooks(rails_config) end end |
#install_agent_hooks(config) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 67 def install_agent_hooks(config) return if @agent_hooks_installed @agent_hooks_installed = true return if config.nil? || !config.respond_to?(:middleware) begin require 'new_relic/rack/agent_hooks' config.middleware.use NewRelic::Rack::AgentHooks ::NewRelic::Agent.logger.debug("Installed New Relic Agent Hooks middleware") rescue => e ::NewRelic::Agent.logger.warn("Error installing New Relic Agent Hooks middleware", e) end end |
#install_browser_monitoring(config) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 80 def install_browser_monitoring(config) return if @browser_monitoring_installed @browser_monitoring_installed = true 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 |
#install_developer_mode(rails_config) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 93 def install_developer_mode(rails_config) return if @installed @installed = true if rails_config && rails_config.respond_to?(:middleware) begin require 'new_relic/rack/developer_mode' rails_config.middleware.use NewRelic::Rack::DeveloperMode ::NewRelic::Agent.logger.info("New Relic Agent Developer Mode enabled.") rescue => e ::NewRelic::Agent.logger.warn("Error installing New Relic Developer Mode", e) end elsif rails_config ::NewRelic::Agent.logger.warn("Developer mode not available for Rails versions prior to 2.2") end end |
#rails_config ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 35 def rails_config if defined?(::Rails) && ::Rails.respond_to?(:configuration) ::Rails.configuration else @config end end |
#rails_root ⇒ Object
31 32 33 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 31 def rails_root RAILS_ROOT if defined?(RAILS_ROOT) end |
#rails_version ⇒ Object
109 110 111 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 109 def rails_version @rails_version ||= NewRelic::VersionNumber.new(::Rails::VERSION::STRING) end |
#root ⇒ Object
Rails can return an empty string from this method, causing the agent not to start even when it is properly in a rails 3 application, so we test the value to make sure it actually has contents, and bail to the parent class if it is empty.
22 23 24 25 26 27 28 29 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 22 def root root = rails_root.to_s if !root.empty? root else super end end |