Class: NewRelic::Control::Frameworks::Rails3

Inherits:
Rails show all
Defined in:
lib/new_relic/control/frameworks/rails3.rb

Overview

Control subclass instantiated when Rails is detected. Contains Rails 3.0+ specific configuration, instrumentation, environment values, etc. Many methods are inherited from the NewRelic::Control::Frameworks::Rails class, where the two do not differ

Instance Attribute Summary

Attributes included from InstanceMethods

#local_env

Attributes included from LoggingMethods

#log_file

Instance Method Summary collapse

Methods inherited from Rails

#install_browser_monitoring, #install_developer_mode, #rails_config, #rails_version

Methods inherited from Ruby

#config_file

Methods included from ClassMethods

#instance, #load_framework_class, #load_test_framework, #local_env, #new_instance, #newrelic_root

Methods included from InstanceMethods

#[], #app, #dispatcher, #init_plugin, #settings, #start_agent, #to_s

Methods included from LanguageSupport::Control

included

Methods included from LoggingMethods

#find_or_create_file_path, #log, #log_path, #log_to_stdout?, #set_log_format!, #set_log_level!, #setup_log, #should_log?

Methods included from Instrumentation

#add_instrumentation, #install_instrumentation, #load_instrumentation_files, #load_samplers

Methods included from ServerMethods

#api_server, #cert_file_path, #convert_to_ip_address, #http_connection, #proxy_server, #resolve_ip_address, #server, #server_from_host

Methods included from Profiling

#profiling=, #profiling?, #profiling_available?

Instance Method Details

#envObject



13
14
15
# File 'lib/new_relic/control/frameworks/rails3.rb', line 13

def env
  @env ||= ::Rails.env.to_s
end

#init_config(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/new_relic/control/frameworks/rails3.rb', line 34

def init_config(options={})
  super
  if Agent.config[:agent_enabled] && Agent.config[:'error_collector.enabled']
    if !rails_config.middleware.respond_to?(:include?) ||
        !rails_config.middleware.include?(NewRelic::Rack::ErrorCollector)
      rails_config.middleware.use NewRelic::Rack::ErrorCollector
    end
  end
end

#log!(msg, level = :info) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/new_relic/control/frameworks/rails3.rb', line 44

def log!(msg, level=:info)
  if should_log?
    logger.send(level, msg)
  else
    super
  end
rescue => e
  super
end

#loggerObject



30
31
32
# File 'lib/new_relic/control/frameworks/rails3.rb', line 30

def logger
  ::Rails.logger
end

#rootObject

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.



21
22
23
24
25
26
27
28
# File 'lib/new_relic/control/frameworks/rails3.rb', line 21

def root
  value = ::Rails.root.to_s
  if value.empty?
    super
  else
    value
  end
end

#to_stdout(msg) ⇒ Object



54
55
56
57
58
# File 'lib/new_relic/control/frameworks/rails3.rb', line 54

def to_stdout(msg)
  logger.info(msg)
rescue
  super
end

#vendor_rootObject



60
61
62
# File 'lib/new_relic/control/frameworks/rails3.rb', line 60

def vendor_root
  @vendor_root ||= File.join(root,'vendor','rails')
end

#versionObject



64
65
66
# File 'lib/new_relic/control/frameworks/rails3.rb', line 64

def version
  @rails_version ||= NewRelic::VersionNumber.new(::Rails::VERSION::STRING)
end