Class: NewRelic::Control::Frameworks::Rails
- Inherits:
-
Ruby
show all
- 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
Rails3
Constant Summary
collapse
- BROWSER_MONITORING_INSTALLED_SINGLETON =
NewRelic::Agent.config
- BROWSER_MONITORING_INSTALLED_VARIABLE =
:@browser_monitoring_installed
Instance Attribute Summary
#local_env
Instance Method Summary
collapse
#rails_32_deprecation
#instance, #load_framework_class, #load_test_framework, #local_env, #new_instance, #newrelic_root, #reset
#[], #app, #configure_agent, #determine_env, #dispatcher, #framework, #handle_invalid_security_settings, #init_plugin, #newrelic_root, #security_settings_valid?, #settings, #start_agent
#add_instrumentation, #install_instrumentation, #load_instrumentation_files
#api_server, #server, #server_from_host
Instance Method Details
#browser_agent_already_installed? ⇒ Boolean
#env ⇒ Object
16
17
18
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 16
def env
@env ||= (ENV['NEW_RELIC_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.
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 48
def init_config(options = {})
@config = options[:config]
install_dependency_detection
install_browser_monitoring_and_agent_hooks
rescue => e
::NewRelic::Agent.logger.error('Failure during init_config for Rails. Is Rails required in a non-Rails ' \
'app? Set NEW_RELIC_FRAMEWORK=ruby to avoid this message. The Ruby agent ' \
'will continue running, but Rails-specific features may be missing. ' \
"#{e.class} - #{e.message}")
end
|
#install_agent_hooks(config) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 84
def install_agent_hooks(config)
return if defined?(@agent_hooks_installed) && @agent_hooks_installed
@agent_hooks_installed = true
return if config.nil? || !config.respond_to?(:middleware)
begin
require 'new_relic/rack/agent_hooks'
return unless NewRelic::Rack::AgentHooks.needed?
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 101
def install_browser_monitoring(config)
@install_lock.synchronize do
return if browser_agent_already_installed?
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
|
#install_browser_monitoring_and_agent_hooks ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 70
def install_browser_monitoring_and_agent_hooks
return unless rails_config
if !Agent.config[:agent_enabled]
::NewRelic::Agent.logger.info('New Relic agent not running. Skipping browser monitoring and agent hooks.')
else
install_browser_monitoring(rails_config)
install_agent_hooks(rails_config)
end
end
|
#install_dependency_detection ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 59
def install_dependency_detection
return unless rails_config && ::Rails.configuration.respond_to?(:after_initialize)
rails_config.after_initialize do
DependencyDetection.detect!
end
end
|
#mark_browser_agent_as_installed ⇒ Object
#rails_config ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 37
def rails_config
if defined?(::Rails) && ::Rails.respond_to?(:configuration)
::Rails.configuration
else
@config
end
end
|
#rails_root ⇒ Object
33
34
35
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 33
def rails_root
RAILS_ROOT if defined?(RAILS_ROOT)
end
|
#rails_version ⇒ Object
127
128
129
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 127
def rails_version
@rails_version ||= Gem::Version.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.
24
25
26
27
28
29
30
31
|
# File 'lib/new_relic/control/frameworks/rails.rb', line 24
def root
root = rails_root.to_s
if !root.empty?
root
else
super
end
end
|