Class: NewRelic::Control::Frameworks::Rails
- Inherits:
-
NewRelic::Control
- Object
- NewRelic::Control
- 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 inherited from NewRelic::Control
Attributes included from LoggingMethods
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_developer_mode(rails_config) ⇒ Object
- #install_episodes(config) ⇒ Object
- #log!(msg, level = :info) ⇒ Object
- #rails_version ⇒ Object
- #root ⇒ Object
- #to_stdout(message) ⇒ Object
Methods inherited from NewRelic::Control
#agent_enabled?, #app, #init_plugin, #start_agent, #to_s
Methods included from ClassMethods
#instance, #new_instance, #newrelic_root
Methods included from Instrumentation
#_delayed_instrumentation, #add_instrumentation, #install_instrumentation, #load_instrumentation_files, #load_samplers
Methods included from ServerMethods
#api_server, #convert_to_ip_address, #http_connection, #proxy_server, #server, #server_from_host
Methods included from Configuration
#[], #[]=, #apdex_t, #app_names, #capture_params, #developer_mode?, #dispatcher, #dispatcher_instance_id, #episodes_enabled?, #fetch, #license_key, #merge_defaults, #merge_options, #monitor_mode?, #multi_threaded?, #post_size_limit, #send_data_on_exit, #settings, #sync_startup, #use_ssl?, #use_textmate?, #validate_seed, #validate_token, #verify_certificate?
Methods included from LoggingMethods
#log, #log_file_name, #log_path, #setup_log, #should_log?
Methods included from Profiling
#profiling=, #profiling?, #profiling_available?
Instance Method Details
#env ⇒ Object
6 7 8 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 6 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.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 15 def init_config(={}) rails_config=[:config] 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 log! "Starting the New Relic Agent." install_developer_mode rails_config if developer_mode? install_episodes rails_config end end |
#install_developer_mode(rails_config) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 39 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 # inform user that the dev edition is available if we are running inside # a webserver process 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 log!("Error installing New Relic Developer Mode: #{e.inspect}", :error) end else log!("Developer mode not available for Rails versions prior to 2.2", :warn) end end |
#install_episodes(config) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 28 def install_episodes(config) return if config.nil? || !config.respond_to?(:middleware) || !episodes_enabled? config.after_initialize do if defined?(NewRelic::Rack::Episodes) config.middleware.use NewRelic::Rack::Episodes log! "Installed episodes middleware" ::RAILS_DEFAULT_LOGGER.info "Installed episodes middleware" end end end |
#log!(msg, level = :info) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 62 def log!(msg, level=:info) return unless should_log? begin ::RAILS_DEFAULT_LOGGER.send(level, msg) rescue Exception => e super end end |
#rails_version ⇒ Object
77 78 79 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 77 def rails_version @rails_version ||= NewRelic::VersionNumber.new(::Rails::VERSION::STRING) end |
#root ⇒ Object
9 10 11 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 9 def root RAILS_ROOT end |
#to_stdout(message) ⇒ Object
71 72 73 74 75 |
# File 'lib/new_relic/control/frameworks/rails.rb', line 71 def to_stdout() ::RAILS_DEFAULT_LOGGER.info() rescue Exception => e super end |