ghazel-newrelic_rpm 3.1.0.1 → 3.4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/CHANGELOG +120 -35
  2. data/LICENSE +29 -2
  3. data/README.rdoc +2 -2
  4. data/bin/mongrel_rpm +0 -0
  5. data/bin/newrelic +0 -0
  6. data/bin/newrelic_cmd +0 -0
  7. data/lib/new_relic/agent.rb +50 -38
  8. data/lib/new_relic/agent/agent.rb +459 -337
  9. data/lib/new_relic/agent/beacon_configuration.rb +71 -11
  10. data/lib/new_relic/agent/browser_monitoring.rb +73 -14
  11. data/lib/new_relic/agent/busy_calculator.rb +11 -3
  12. data/lib/new_relic/agent/chained_call.rb +2 -2
  13. data/lib/new_relic/agent/database.rb +223 -0
  14. data/lib/new_relic/agent/error_collector.rb +231 -183
  15. data/lib/new_relic/agent/instrumentation.rb +2 -2
  16. data/lib/new_relic/agent/instrumentation/active_merchant.rb +10 -2
  17. data/lib/new_relic/agent/instrumentation/active_record.rb +138 -0
  18. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +7 -1
  19. data/lib/new_relic/agent/instrumentation/authlogic.rb +6 -0
  20. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +46 -14
  21. data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -2
  22. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +11 -3
  23. data/lib/new_relic/agent/instrumentation/memcache.rb +49 -25
  24. data/lib/new_relic/agent/instrumentation/merb/controller.rb +7 -2
  25. data/lib/new_relic/agent/instrumentation/merb/errors.rb +7 -1
  26. data/lib/new_relic/agent/instrumentation/metric_frame.rb +31 -4
  27. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -5
  28. data/lib/new_relic/agent/instrumentation/net.rb +8 -2
  29. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +5 -2
  30. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +66 -35
  32. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +7 -1
  33. data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -1
  34. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +121 -1
  35. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +7 -1
  36. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +21 -0
  37. data/lib/new_relic/agent/instrumentation/resque.rb +80 -0
  38. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -20
  39. data/lib/new_relic/agent/instrumentation/sunspot.rb +6 -0
  40. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +7 -2
  41. data/lib/new_relic/agent/method_tracer.rb +205 -99
  42. data/lib/new_relic/agent/new_relic_service.rb +221 -0
  43. data/lib/new_relic/agent/pipe_channel_manager.rb +161 -0
  44. data/lib/new_relic/agent/pipe_service.rb +54 -0
  45. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +89 -0
  46. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -7
  47. data/lib/new_relic/agent/shim_agent.rb +5 -5
  48. data/lib/new_relic/agent/sql_sampler.rb +282 -0
  49. data/lib/new_relic/agent/stats_engine.rb +2 -0
  50. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  51. data/lib/new_relic/agent/stats_engine/metric_stats.rb +35 -30
  52. data/lib/new_relic/agent/stats_engine/samplers.rb +10 -4
  53. data/lib/new_relic/agent/stats_engine/transactions.rb +28 -87
  54. data/lib/new_relic/agent/transaction_info.rb +74 -0
  55. data/lib/new_relic/agent/transaction_sample_builder.rb +18 -3
  56. data/lib/new_relic/agent/transaction_sampler.rb +108 -20
  57. data/lib/new_relic/agent/worker_loop.rb +14 -6
  58. data/lib/new_relic/collection_helper.rb +19 -11
  59. data/lib/new_relic/command.rb +1 -1
  60. data/lib/new_relic/commands/deployments.rb +2 -2
  61. data/lib/new_relic/commands/install.rb +2 -13
  62. data/lib/new_relic/control.rb +2 -3
  63. data/lib/new_relic/control/class_methods.rb +12 -6
  64. data/lib/new_relic/control/configuration.rb +57 -8
  65. data/lib/new_relic/control/frameworks.rb +10 -0
  66. data/lib/new_relic/control/frameworks/external.rb +4 -4
  67. data/lib/new_relic/control/frameworks/merb.rb +2 -1
  68. data/lib/new_relic/control/frameworks/rails.rb +35 -22
  69. data/lib/new_relic/control/frameworks/rails3.rb +12 -7
  70. data/lib/new_relic/control/frameworks/ruby.rb +5 -5
  71. data/lib/new_relic/control/frameworks/sinatra.rb +1 -4
  72. data/lib/new_relic/control/instance_methods.rb +38 -12
  73. data/lib/new_relic/control/instrumentation.rb +23 -4
  74. data/lib/new_relic/control/logging_methods.rb +70 -15
  75. data/lib/new_relic/control/server_methods.rb +22 -9
  76. data/lib/new_relic/delayed_job_injection.rb +16 -3
  77. data/lib/new_relic/helper.rb +21 -0
  78. data/lib/new_relic/language_support.rb +95 -0
  79. data/lib/new_relic/local_environment.rb +92 -48
  80. data/lib/new_relic/metric_data.rb +7 -2
  81. data/lib/new_relic/metric_spec.rb +12 -9
  82. data/lib/new_relic/noticed_error.rb +6 -1
  83. data/lib/new_relic/rack/browser_monitoring.rb +18 -19
  84. data/lib/new_relic/rack/developer_mode.rb +3 -2
  85. data/lib/new_relic/recipes.rb +8 -4
  86. data/lib/new_relic/stats.rb +17 -60
  87. data/lib/new_relic/transaction_analysis.rb +2 -1
  88. data/lib/new_relic/transaction_analysis/segment_summary.rb +4 -2
  89. data/lib/new_relic/transaction_sample.rb +60 -75
  90. data/lib/new_relic/transaction_sample/segment.rb +31 -79
  91. data/lib/new_relic/version.rb +2 -2
  92. data/lib/newrelic_rpm.rb +1 -1
  93. data/newrelic.yml +2 -2
  94. data/newrelic_rpm.gemspec +46 -54
  95. data/test/active_record_fixtures.rb +3 -3
  96. data/test/config/newrelic.yml +1 -1
  97. data/test/fixtures/proc_cpuinfo.txt +575 -0
  98. data/test/new_relic/agent/agent/connect_test.rb +128 -25
  99. data/test/new_relic/agent/agent/start_test.rb +9 -94
  100. data/test/new_relic/agent/agent/start_worker_thread_test.rb +2 -4
  101. data/test/new_relic/agent/agent_test.rb +51 -78
  102. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  103. data/test/new_relic/agent/agent_test_controller_test.rb +49 -33
  104. data/test/new_relic/agent/beacon_configuration_test.rb +12 -5
  105. data/test/new_relic/agent/browser_monitoring_test.rb +99 -50
  106. data/test/new_relic/agent/database_test.rb +161 -0
  107. data/test/new_relic/agent/error_collector_test.rb +47 -23
  108. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +96 -42
  109. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
  110. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
  111. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +3 -11
  112. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +9 -9
  113. data/test/new_relic/agent/instrumentation/queue_time_test.rb +6 -11
  114. data/test/new_relic/agent/memcache_instrumentation_test.rb +54 -18
  115. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
  116. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
  117. data/test/new_relic/agent/method_tracer_test.rb +3 -2
  118. data/test/new_relic/agent/new_relic_service_test.rb +151 -0
  119. data/test/new_relic/agent/pipe_channel_manager_test.rb +114 -0
  120. data/test/new_relic/agent/pipe_service_test.rb +113 -0
  121. data/test/new_relic/agent/rpm_agent_test.rb +4 -31
  122. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  123. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +19 -18
  124. data/test/new_relic/agent/stats_engine_test.rb +41 -6
  125. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  126. data/test/new_relic/agent/transaction_sample_builder_test.rb +27 -4
  127. data/test/new_relic/agent/transaction_sampler_test.rb +68 -46
  128. data/test/new_relic/agent/worker_loop_test.rb +3 -3
  129. data/test/new_relic/agent_test.rb +242 -0
  130. data/test/new_relic/collection_helper_test.rb +50 -28
  131. data/test/new_relic/control/configuration_test.rb +77 -0
  132. data/test/new_relic/control/logging_methods_test.rb +49 -21
  133. data/test/new_relic/control_test.rb +115 -54
  134. data/test/new_relic/delayed_job_injection_test.rb +21 -0
  135. data/test/new_relic/fake_collector.rb +210 -0
  136. data/test/new_relic/fake_service.rb +44 -0
  137. data/test/new_relic/local_environment_test.rb +14 -1
  138. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  139. data/test/new_relic/rack/browser_monitoring_test.rb +84 -23
  140. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  141. data/test/new_relic/rack/developer_mode_test.rb +31 -0
  142. data/test/new_relic/stats_test.rb +3 -18
  143. data/test/new_relic/transaction_analysis/segment_summary_test.rb +14 -0
  144. data/test/new_relic/transaction_analysis_test.rb +3 -3
  145. data/test/new_relic/transaction_sample/segment_test.rb +15 -80
  146. data/test/new_relic/transaction_sample_test.rb +25 -18
  147. data/test/script/build_test_gem.sh +51 -0
  148. data/test/script/ci.sh +140 -0
  149. data/test/script/ci_agent-tests_runner.sh +82 -0
  150. data/test/script/ci_bench.sh +52 -0
  151. data/test/script/ci_multiverse_runner.sh +63 -0
  152. data/test/test_contexts.rb +1 -0
  153. data/test/test_helper.rb +18 -5
  154. data/ui/helpers/developer_mode_helper.rb +14 -8
  155. data/ui/helpers/google_pie_chart.rb +0 -1
  156. data/ui/views/newrelic/index.rhtml +2 -2
  157. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +4 -18
  158. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +10 -0
  159. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +11 -11
  160. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +17 -4
  161. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +4 -0
  162. metadata +50 -36
  163. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +0 -108
  164. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +0 -112
  165. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
  166. data/lib/new_relic/data_serialization.rb +0 -84
  167. data/lib/new_relic/histogram.rb +0 -91
  168. data/lib/new_relic/rack/metric_app.rb +0 -65
  169. data/lib/new_relic/rack/mongrel_rpm.ru +0 -28
  170. data/lib/new_relic/rack/newrelic.yml +0 -27
  171. data/lib/new_relic/rack_app.rb +0 -6
  172. data/test/new_relic/data_serialization_test.rb +0 -70
  173. data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
  174. data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
  175. data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
@@ -1,5 +1,7 @@
1
1
  module NewRelic
2
2
  class Control
3
+ # used to contain methods to look up settings from the
4
+ # configuration located in newrelic.yml
3
5
  module Configuration
4
6
  def settings
5
7
  unless @settings
@@ -34,7 +36,7 @@ module NewRelic
34
36
  # Merge the given options into the config options.
35
37
  # They might be a nested hash
36
38
  def merge_options(options, hash=self)
37
- options.each do |key, val |
39
+ options.each do |key, val|
38
40
  case
39
41
  when key == :config then next
40
42
  when val.is_a?(Hash)
@@ -47,6 +49,28 @@ module NewRelic
47
49
  end
48
50
  end
49
51
 
52
+ def merge_server_side_config(data)
53
+ remove_server_controlled_configs
54
+ config = Hash.new
55
+ data.each_pair do |key, value|
56
+ if key.include?('.')
57
+ key = key.split('.')
58
+ config[key.first] ||= Hash.new
59
+ config[key.first][key[1]] = value
60
+ else
61
+ config[key] = value
62
+ end
63
+ end
64
+ merge_options(config)
65
+ end
66
+
67
+ def remove_server_controlled_configs
68
+ settings.delete('transaction_tracer')
69
+ settings.delete('slow_sql')
70
+ settings.delete('error_collector')
71
+ settings.delete('capture_params')
72
+ end
73
+
50
74
  def [](key)
51
75
  fetch(key)
52
76
  end
@@ -61,15 +85,18 @@ module NewRelic
61
85
 
62
86
  def apdex_t
63
87
  # Always initialized with a default
64
- fetch('apdex_t').to_f
88
+ @apdex_t_float ||= fetch('apdex_t').to_f
65
89
  end
66
90
 
67
91
  def license_key
68
- fetch('license_key')
92
+ env_setting = ENV['NEW_RELIC_LICENSE_KEY'] || ENV['NEWRELIC_LICENSE_KEY']
93
+ fetch('license_key', env_setting)
69
94
  end
95
+
70
96
  def capture_params
71
97
  fetch('capture_params')
72
98
  end
99
+
73
100
  # True if we are sending data to the server, monitoring production
74
101
  def monitor_mode?
75
102
  fetch('monitor_mode', fetch('enabled'))
@@ -79,24 +106,31 @@ module NewRelic
79
106
  def developer_mode?
80
107
  fetch('developer_mode', fetch('developer'))
81
108
  end
82
-
109
+
110
+ # whether we should install the
111
+ # NewRelic::Rack::BrowserMonitoring middleware automatically on
112
+ # Rails applications
83
113
  def browser_monitoring_auto_instrument?
84
114
  fetch('browser_monitoring', {}).fetch('auto_instrument', true)
85
115
  end
86
116
 
87
- # True if the app runs in multi-threaded mode
88
117
  def multi_threaded?
89
118
  fetch('multi_threaded')
90
119
  end
91
120
 
92
121
  def disable_serialization?
93
- fetch('disable_serialization', false)
122
+ fetch('disable_serialization', true)
123
+ end
124
+ def disable_serialization=(b)
125
+ self['disable_serialization'] = b
94
126
  end
95
127
 
96
128
  # True if we should view files in textmate
97
129
  def use_textmate?
98
130
  fetch('textmate')
99
131
  end
132
+
133
+ # defaults to 2MiB
100
134
  def post_size_limit
101
135
  fetch('post_size_limit', 2 * 1024 * 1024)
102
136
  end
@@ -135,12 +169,19 @@ module NewRelic
135
169
  def validate_token
136
170
  self['validate_token'] || ENV['NR_VALIDATE_TOKEN']
137
171
  end
138
-
172
+
139
173
  def use_ssl?
140
174
  @use_ssl = fetch('ssl', false) unless @use_ssl
141
175
  @use_ssl
142
176
  end
143
-
177
+
178
+ def log_file_path
179
+ fetch('log_file_path', 'log/')
180
+ end
181
+
182
+ # only verify certificates if you're very sure you want this
183
+ # level of security, it includes possibly app-crashing dns
184
+ # lookups every connection to the server
144
185
  def verify_certificate?
145
186
  unless @verify_certificate
146
187
  unless use_ssl?
@@ -151,6 +192,14 @@ module NewRelic
151
192
  end
152
193
  @verify_certificate
153
194
  end
195
+
196
+ def disable_backtrace_cleanup?
197
+ fetch('disable_backtrace_cleanup')
198
+ end
199
+
200
+ def has_slow_sql_config?
201
+ self['slow_sql'] && self['slow_sql'].has_key?('enabled')
202
+ end
154
203
  end
155
204
  include Configuration
156
205
  end
@@ -0,0 +1,10 @@
1
+ module NewRelic
2
+ class Control
3
+ # Contains subclasses of NewRelic::Control that are used when
4
+ # starting the agent within an application. Framework-specific
5
+ # logic should be included here, as documented within the Control
6
+ # abstract parent class
7
+ module Frameworks
8
+ end
9
+ end
10
+ end
@@ -1,11 +1,11 @@
1
- # This is the control used when starting up in the context of
2
- # The New Relic Infrastructure Agent. We want to call this
3
- # out specifically because in this context we are not monitoring
4
- # the running process, but actually external things.
5
1
  require 'new_relic/control/frameworks/ruby'
6
2
  module NewRelic
7
3
  class Control
8
4
  module Frameworks
5
+ # This is the control used when starting up in the context of
6
+ # The New Relic Infrastructure Agent. We want to call this
7
+ # out specifically because in this context we are not monitoring
8
+ # the running process, but actually external things.
9
9
  class External < NewRelic::Control::Frameworks::Ruby
10
10
  def init_config(options={})
11
11
  super
@@ -1,6 +1,7 @@
1
1
  module NewRelic
2
2
  class Control
3
3
  module Frameworks
4
+ # Includes limited support for Merb
4
5
  class Merb < NewRelic::Control
5
6
 
6
7
  def env
@@ -12,7 +13,7 @@ module NewRelic
12
13
 
13
14
  def to_stdout(msg)
14
15
  Merb.logger.info("NewRelic ~ " + msg)
15
- rescue Exception => e
16
+ rescue => e
16
17
  STDOUT.puts "NewRelic ~ " + msg
17
18
  end
18
19
 
@@ -1,10 +1,10 @@
1
- # Control subclass instantiated when Rails is detected. Contains
2
- # Rails specific configuration, instrumentation, environment values,
3
- # etc.
4
1
  require 'new_relic/control/frameworks/ruby'
5
2
  module NewRelic
6
3
  class Control
7
4
  module Frameworks
5
+ # Control subclass instantiated when Rails is detected. Contains
6
+ # Rails specific configuration, instrumentation, environment values,
7
+ # etc.
8
8
  class Rails < NewRelic::Control::Frameworks::Ruby
9
9
 
10
10
  def env
@@ -17,11 +17,27 @@ module NewRelic
17
17
  super
18
18
  end
19
19
  end
20
+ def logger
21
+ ::RAILS_DEFAULT_LOGGER
22
+ end
20
23
 
21
24
  # In versions of Rails prior to 2.0, the rails config was only available to
22
- # the init.rb, so it had to be passed on from there.
25
+ # the init.rb, so it had to be passed on from there. This is a best effort to
26
+ # find a config and use that.
23
27
  def init_config(options={})
24
- rails_config=options[:config]
28
+ rails_config = options[:config]
29
+ if !rails_config && defined?(::Rails) && ::Rails.respond_to?(:configuration)
30
+ rails_config = ::Rails.configuration
31
+ end
32
+ # Install the dependency detection,
33
+ if rails_config && ::Rails.configuration.respond_to?(:after_initialize)
34
+ rails_config.after_initialize do
35
+ # This will insure we load all the instrumentation as late as possible. If the agent
36
+ # is not enabled, it will load a limited amount of instrumentation. See
37
+ # delayed_job_injection.rb
38
+ DependencyDetection.detect!
39
+ end
40
+ end
25
41
  if !agent_enabled?
26
42
  # Might not be running if it does not think mongrel, thin, passenger, etc
27
43
  # is running, if it things it's a rake task, or if the agent_enabled is false.
@@ -36,12 +52,12 @@ module NewRelic
36
52
  def install_browser_monitoring(config)
37
53
  return if @browser_monitoring_installed
38
54
  @browser_monitoring_installed = true
39
- return if config.nil? || !config.respond_to?(:middleware) || !browser_monitoring_auto_instrument?
55
+ return if config.nil? || !config.respond_to?(:middleware) || ! browser_monitoring_auto_instrument?
40
56
  begin
41
57
  require 'new_relic/rack/browser_monitoring'
42
58
  config.middleware.use NewRelic::Rack::BrowserMonitoring
43
59
  log!("Installed New Relic Browser Monitoring middleware", :info)
44
- rescue Exception => e
60
+ rescue => e
45
61
  log!("Error installing New Relic Browser Monitoring middleware: #{e.inspect}", :error)
46
62
  end
47
63
  end
@@ -61,24 +77,29 @@ module NewRelic
61
77
  log!("NewRelic Agent Developer Mode enabled.")
62
78
  log!("To view performance information, go to http://localhost#{port}/newrelic")
63
79
  end
64
- rescue Exception => e
80
+ rescue => e
65
81
  log!("Error installing New Relic Developer Mode: #{e.inspect}", :error)
66
82
  end
67
- else
83
+ elsif rails_config
68
84
  log!("Developer mode not available for Rails versions prior to 2.2", :warn)
69
85
  end
70
86
  end
71
87
 
72
88
  def log!(msg, level=:info)
73
- super unless should_log?
74
- ::RAILS_DEFAULT_LOGGER.send(level, msg)
75
- rescue Exception => e
89
+ if should_log?
90
+ logger = ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER
91
+ logger.send(level, msg)
92
+ else
93
+ super
94
+ end
95
+ rescue => e
76
96
  super
77
97
  end
78
98
 
79
99
  def to_stdout(message)
80
- ::RAILS_DEFAULT_LOGGER.info(message)
81
- rescue Exception => e
100
+ logger = ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER
101
+ logger.info(message)
102
+ rescue => e
82
103
  super
83
104
  end
84
105
 
@@ -137,14 +158,6 @@ module NewRelic
137
158
  }
138
159
  end
139
160
 
140
- def _install_instrumentation
141
- super
142
- if defined?(Rails) && Rails.respond_to?(:configuration) && Rails.configuration.respond_to?(:after_initialize)
143
- Rails.configuration.after_initialize do
144
- DependencyDetection.detect!
145
- end
146
- end
147
- end
148
161
  end
149
162
  end
150
163
  end
@@ -1,14 +1,16 @@
1
- # Control subclass instantiated when Rails is detected. Contains
2
- # Rails specific configuration, instrumentation, environment values,
3
- # etc.
4
1
  require 'new_relic/control/frameworks/rails'
5
2
  module NewRelic
6
3
  class Control
7
4
  module Frameworks
5
+ # Control subclass instantiated when Rails is detected. Contains
6
+ # Rails 3.0+ specific configuration, instrumentation, environment values,
7
+ # etc. Many methods are inherited from the
8
+ # NewRelic::Control::Frameworks::Rails class, where the two do
9
+ # not differ
8
10
  class Rails3 < NewRelic::Control::Frameworks::Rails
9
11
 
10
12
  def env
11
- ::Rails.env.to_s
13
+ @env ||= ::Rails.env.to_s
12
14
  end
13
15
 
14
16
  # Rails can return an empty string from this method, causing
@@ -30,9 +32,12 @@ module NewRelic
30
32
 
31
33
 
32
34
  def log!(msg, level=:info)
33
- super unless should_log?
34
- logger.send(level, msg)
35
- rescue Exception => e
35
+ if should_log?
36
+ logger.send(level, msg)
37
+ else
38
+ super
39
+ end
40
+ rescue => e
36
41
  super
37
42
  end
38
43
 
@@ -1,11 +1,11 @@
1
- # A control used when no framework is detected.
2
- # Looks for a newrelic.yml file in several locations
3
- # including ./, ./config, $HOME/.newrelic and $HOME/.
4
- # It loads the settings from the newrelic.yml section
5
- # based on the value of RUBY_ENV or RAILS_ENV.
6
1
  module NewRelic
7
2
  class Control
8
3
  module Frameworks
4
+ # A control used when no framework is detected - the default.
5
+ # Looks for a newrelic.yml file in several locations including
6
+ # ./, ./config, $HOME/.newrelic and $HOME/. It loads the
7
+ # settings from the newrelic.yml section based on the value of
8
+ # RUBY_ENV or RAILS_ENV.
9
9
  class Ruby < NewRelic::Control
10
10
 
11
11
  def env
@@ -3,16 +3,13 @@ require 'new_relic/control/frameworks/ruby'
3
3
  module NewRelic
4
4
  class Control
5
5
  module Frameworks
6
+ # Contains basic control logic for Sinatra
6
7
  class Sinatra < NewRelic::Control::Frameworks::Ruby
7
8
 
8
9
  def env
9
10
  @env ||= ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
10
11
  end
11
12
 
12
- # This is the control used when starting up in the context of
13
- # The New Relic Infrastructure Agent. We want to call this
14
- # out specifically because in this context we are not monitoring
15
- # the running process, but actually external things.
16
13
  def init_config(options={})
17
14
  super
18
15
  end
@@ -1,11 +1,22 @@
1
+ require 'new_relic/language_support'
2
+
1
3
  module NewRelic
2
4
  class Control
5
+ include NewRelic::LanguageSupport::Control
6
+
7
+ # Contains methods that relate to the runtime usage of the control
8
+ # object. Note that these are subject to override in the
9
+ # NewRelic::Control::Framework classes that are actually instantiated
3
10
  module InstanceMethods
4
11
  # The env is the setting used to identify which section of the newrelic.yml
5
12
  # to load. This defaults to a framework specific value, such as ENV['RAILS_ENV']
6
13
  # but can be overridden as long as you set it before calling #init_plugin
7
14
  attr_writer :env
8
15
 
16
+ # The local environment contains all the information we report
17
+ # to the server about what kind of application this is, what
18
+ # gems and plugins it uses, and many other kinds of
19
+ # machine-dependent information useful in debugging
9
20
  attr_reader :local_env
10
21
 
11
22
 
@@ -34,13 +45,15 @@ module NewRelic
34
45
  #
35
46
  def init_plugin(options={})
36
47
  options['app_name'] = ENV['NEWRELIC_APP_NAME'] if ENV['NEWRELIC_APP_NAME']
48
+ options['app_name'] ||= ENV['NEW_RELIC_APP_NAME'] if ENV['NEW_RELIC_APP_NAME']
37
49
 
38
50
  # Merge the stringified options into the config as overrides:
39
51
  logger_override = options.delete(:log)
40
52
  environment_name = options.delete(:env) and self.env = environment_name
41
53
  dispatcher = options.delete(:dispatcher) and @local_env.dispatcher = dispatcher
42
54
  dispatcher_instance_id = options.delete(:dispatcher_instance_id) and @local_env.dispatcher_instance_id = dispatcher_instance_id
43
-
55
+
56
+ NewRelic::Agent::PipeChannelManager.listener.start if options.delete(:start_channel_listener)
44
57
 
45
58
  # Clear out the settings, if they've already been loaded. It may be that
46
59
  # between calling init_plugin the first time and the second time, the env
@@ -90,13 +103,14 @@ module NewRelic
90
103
  # dispatcher running
91
104
  return true if @local_env.dispatcher != nil
92
105
  end
93
-
106
+
107
+ # Asks the LocalEnvironment instance which framework should be loaded
94
108
  def app
95
109
  @local_env.framework
96
110
  end
97
111
  alias framework app
98
-
99
- def to_s
112
+
113
+ def to_s #:nodoc:
100
114
  "Control[#{self.app}]"
101
115
  end
102
116
 
@@ -105,7 +119,9 @@ module NewRelic
105
119
  # Append framework specific environment information for uploading to
106
120
  # the server for change detection. Override in subclasses
107
121
  def append_environment_info; end
108
-
122
+
123
+ # Asks bundler to tell us which gemspecs are loaded in the
124
+ # current process
109
125
  def bundler_gem_list
110
126
  if defined?(Bundler) && Bundler.instance_eval do @load end
111
127
  Bundler.load.specs.map do | spec |
@@ -116,11 +132,15 @@ module NewRelic
116
132
  []
117
133
  end
118
134
  end
119
-
135
+
136
+ # path to the config file, defaults to the "#{root}/config/newrelic.yml"
120
137
  def config_file
121
138
  File.expand_path(File.join(root,"config","newrelic.yml"))
122
139
  end
123
-
140
+
141
+ # initializes the control instance with a local environment and
142
+ # an optional config file override. Checks for the config file
143
+ # and loads it.
124
144
  def initialize local_env, config_file_override=nil
125
145
  @local_env = local_env
126
146
  @instrumentation_files = []
@@ -133,18 +153,24 @@ module NewRelic
133
153
  puts "Cannot find or read #{newrelic_file}"
134
154
  @yaml = {}
135
155
  else
136
- @yaml = YAML.load(ERB.new(File.read(newrelic_file)).result(binding))
156
+ @yaml = load_newrelic_yml(newrelic_file, binding)
137
157
  end
138
158
  rescue ScriptError, StandardError => e
139
- puts e
140
- puts e.backtrace.join("\n")
141
- raise "Error reading newrelic.yml file: #{e}"
159
+ new_err = e.class.new("Error reading newrelic.yml file: #{e}")
160
+ new_err.set_backtrace(e.backtrace)
161
+ raise new_err
142
162
  end
143
-
163
+
164
+ def load_newrelic_yml(path, binding)
165
+ YAML.load(ERB.new(File.read(path)).result(binding))
166
+ end
167
+
144
168
  def root
145
169
  '.'
146
170
  end
147
171
 
172
+ # Delegates to the class method newrelic_root, implemented by
173
+ # each subclass
148
174
  def newrelic_root
149
175
  self.class.newrelic_root
150
176
  end