newrelic_rpm 3.4.2.1 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (49) hide show
  1. data/CHANGELOG +47 -2
  2. data/lib/new_relic/agent.rb +5 -5
  3. data/lib/new_relic/agent/agent.rb +88 -177
  4. data/lib/new_relic/agent/beacon_configuration.rb +33 -47
  5. data/lib/new_relic/agent/browser_monitoring.rb +26 -33
  6. data/lib/new_relic/agent/configuration/defaults.rb +21 -13
  7. data/lib/new_relic/agent/configuration/manager.rb +28 -14
  8. data/lib/new_relic/agent/configuration/server_source.rb +8 -5
  9. data/lib/new_relic/agent/database.rb +37 -22
  10. data/lib/new_relic/agent/error_collector.rb +32 -31
  11. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +4 -3
  12. data/lib/new_relic/agent/new_relic_service.rb +21 -19
  13. data/lib/new_relic/agent/pipe_channel_manager.rb +13 -13
  14. data/lib/new_relic/agent/sql_sampler.rb +9 -28
  15. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +21 -24
  16. data/lib/new_relic/agent/stats_engine/transactions.rb +20 -12
  17. data/lib/new_relic/agent/transaction_sample_builder.rb +5 -3
  18. data/lib/new_relic/agent/transaction_sampler.rb +43 -47
  19. data/lib/new_relic/control/frameworks/rails.rb +9 -4
  20. data/lib/new_relic/control/frameworks/rails3.rb +10 -0
  21. data/lib/new_relic/noticed_error.rb +18 -8
  22. data/lib/new_relic/rack.rb +4 -0
  23. data/lib/new_relic/rack/browser_monitoring.rb +2 -0
  24. data/lib/new_relic/rack/error_collector.rb +56 -0
  25. data/lib/new_relic/version.rb +3 -3
  26. data/newrelic.yml +0 -12
  27. data/newrelic_rpm.gemspec +6 -3
  28. data/test/new_relic/agent/agent/connect_test.rb +78 -113
  29. data/test/new_relic/agent/agent/start_test.rb +2 -2
  30. data/test/new_relic/agent/agent/start_worker_thread_test.rb +6 -33
  31. data/test/new_relic/agent/agent_test.rb +20 -6
  32. data/test/new_relic/agent/agent_test_controller_test.rb +7 -5
  33. data/test/new_relic/agent/beacon_configuration_test.rb +54 -60
  34. data/test/new_relic/agent/browser_monitoring_test.rb +88 -74
  35. data/test/new_relic/agent/configuration/manager_test.rb +21 -21
  36. data/test/new_relic/agent/configuration/server_source_test.rb +21 -4
  37. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
  38. data/test/new_relic/agent/mock_scope_listener.rb +3 -0
  39. data/test/new_relic/agent/new_relic_service_test.rb +56 -17
  40. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -1
  41. data/test/new_relic/agent/rpm_agent_test.rb +1 -0
  42. data/test/new_relic/agent/stats_engine_test.rb +12 -7
  43. data/test/new_relic/agent/transaction_sampler_test.rb +106 -102
  44. data/test/new_relic/agent_test.rb +10 -9
  45. data/test/new_relic/control_test.rb +1 -17
  46. data/test/new_relic/rack/browser_monitoring_test.rb +11 -5
  47. data/test/new_relic/rack/error_collector_test.rb +74 -0
  48. data/test/test_helper.rb +1 -1
  49. metadata +9 -7
@@ -1,4 +1,5 @@
1
1
  require 'new_relic/control/frameworks/rails'
2
+ require 'new_relic/rack/error_collector'
2
3
  module NewRelic
3
4
  class Control
4
5
  module Frameworks
@@ -30,6 +31,15 @@ module NewRelic
30
31
  ::Rails.logger
31
32
  end
32
33
 
34
+ def init_config(options={})
35
+ super
36
+ if Agent.config[:agent_enabled] && Agent.config[:'error_collector.enabled']
37
+ if !rails_config.middleware.respond_to?(:include?) ||
38
+ !rails_config.middleware.include?(NewRelic::Rack::ErrorCollector)
39
+ rails_config.middleware.use NewRelic::Rack::ErrorCollector
40
+ end
41
+ end
42
+ end
33
43
 
34
44
  def log!(msg, level=:info)
35
45
  if should_log?
@@ -2,28 +2,38 @@
2
2
  class NewRelic::NoticedError
3
3
  extend NewRelic::CollectionHelper
4
4
  attr_accessor :path, :timestamp, :params, :exception_class, :message
5
+ attr_reader :exception_id
5
6
 
6
7
  def initialize(path, data, exception, timestamp = Time.now)
7
- self.path = path
8
- self.params = NewRelic::NoticedError.normalize_params(data)
8
+ @exception_id = exception.object_id
9
+ @path = path
10
+ @params = NewRelic::NoticedError.normalize_params(data)
9
11
 
10
- self.exception_class = exception.is_a?(Exception) ? exception.class.name : 'Error'
12
+ @exception_class = exception.is_a?(Exception) ? exception.class.name : 'Error'
11
13
 
12
14
  if exception.respond_to?('original_exception')
13
- self.message = exception.original_exception.message.to_s
15
+ @message = exception.original_exception.message.to_s
14
16
  else
15
- self.message = (exception || '<no message>').to_s
17
+ @message = (exception || '<no message>').to_s
16
18
  end
17
19
 
18
20
  # clamp long messages to 4k so that we don't send a lot of
19
21
  # overhead across the wire
20
- self.message = self.message[0..4095] if self.message.length > 4096
22
+ @message = @message[0..4095] if @message.length > 4096
21
23
 
22
24
  # obfuscate error message if necessary
23
25
  if NewRelic::Agent.config[:high_security]
24
- self.message = NewRelic::Agent::Database.obfuscate_sql(self.message)
26
+ @message = NewRelic::Agent::Database.obfuscate_sql(@message)
25
27
  end
26
28
 
27
- self.timestamp = timestamp
29
+ @timestamp = timestamp
30
+ end
31
+
32
+ def ==(other)
33
+ if other.respond_to?(:exception_id)
34
+ @exception_id == other.exception_id
35
+ else
36
+ false
37
+ end
28
38
  end
29
39
  end
@@ -0,0 +1,4 @@
1
+ module NewRelic
2
+ module Rack
3
+ end
4
+ end
@@ -59,6 +59,8 @@ module NewRelic::Rack
59
59
  # otherwise put the header right above body start
60
60
  body_start
61
61
  end
62
+ # otherwise put the header right above body start
63
+ head_pos ||= body_start
62
64
 
63
65
  # check that head_pos is less than body close. If it's not something
64
66
  # is really weird and we should punt.
@@ -0,0 +1,56 @@
1
+ module NewRelic::Rack
2
+ class ErrorCollector
3
+ def initialize(app, options={})
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ @app.call(env)
9
+ rescue Exception => exception
10
+ request = Rack::Request.new(env)
11
+ if !should_ignore_error?(exception, request)
12
+ NewRelic::Agent.instance.error_collector.notice_error(exception,
13
+ :uri => request.path,
14
+ :referer => request.referer,
15
+ :request_params => request.params)
16
+ end
17
+ raise exception
18
+ end
19
+
20
+ def should_ignore_error?(error, request)
21
+ NewRelic::Agent.instance.error_collector.error_is_ignored?(error) ||
22
+ ignored_in_controller?(error, request)
23
+ end
24
+
25
+ def ignored_in_controller?(exception, request)
26
+ if request.env['action_dispatch.request.parameters']
27
+ ignore_actions = newrelic_ignore_for_controller(request.env['action_dispatch.request.parameters']['controller'])
28
+ action_name = request.env['action_dispatch.request.parameters']['action']
29
+
30
+ case ignore_actions
31
+ when nil; false
32
+ when Hash
33
+ only_actions = Array(ignore_actions[:only])
34
+ except_actions = Array(ignore_actions[:except])
35
+ only_actions.include?(action_name.to_sym) ||
36
+ (except_actions.any? &&
37
+ !except_actions.include?(action_name.to_sym))
38
+ else
39
+ true
40
+ end
41
+ end
42
+ end
43
+
44
+ def newrelic_ignore_for_controller(controller_name)
45
+ if controller_name
46
+ controller_constant_name = (controller_name + "_controller").camelize
47
+ if Object.const_defined?(controller_constant_name)
48
+ controller = controller_constant_name.constantize
49
+ controller.instance_variable_get(:@do_not_trace)
50
+ end
51
+ end
52
+ rescue NameError
53
+ nil
54
+ end
55
+ end
56
+ end
@@ -2,9 +2,9 @@
2
2
  module NewRelic
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 3
5
- MINOR = 4
6
- TINY = 2
7
- BUILD = 1 # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
5
+ MINOR = 5
6
+ TINY = 0
7
+ BUILD = nil # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
10
10
 
data/newrelic.yml CHANGED
@@ -87,19 +87,7 @@ common: &default_settings
87
87
  # use a non-blocking lookup, so in a worst case, if you have DNS
88
88
  # problems, your app may block indefinitely.
89
89
  # verify_certificate: true
90
-
91
- # Set your application's Apdex threshold value with the 'apdex_t'
92
- # setting, in seconds. The apdex_t value determines the buckets used
93
- # to compute your overall Apdex score.
94
- # Requests that take less than apdex_t seconds to process will be
95
- # classified as Satisfying transactions; more than apdex_t seconds
96
- # as Tolerating transactions; and more than four times the apdex_t
97
- # value as Frustrating transactions.
98
- # For more about the Apdex standard, see
99
- # http://newrelic.com/docs/general/apdex
100
90
 
101
- apdex_t: 0.5
102
-
103
91
  #============================== Browser Monitoring ===============================
104
92
  # New Relic Real User Monitoring gives you insight into the performance real users are
105
93
  # experiencing with your website. This is accomplished by measuring the time it takes for
data/newrelic_rpm.gemspec CHANGED
@@ -5,10 +5,10 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "newrelic_rpm"
8
- s.version = "3.4.2.1"
8
+ s.version = "3.5.0"
9
9
 
10
10
  s.authors = ["Bill Kayser", "Jon Guymon", "Justin George", "Darin Swanson", "Rob Saul"]
11
- s.date = "2012-09-12"
11
+ s.date = "2012-10-04"
12
12
  s.description = "New Relic is a performance management system, developed by New Relic,\nInc (http://www.newrelic.com). New Relic provides you with deep\ninformation about the performance of your web application as it runs\nin production. The New Relic Ruby Agent is dual-purposed as a either a\nGem or plugin, hosted on\nhttp://github.com/newrelic/rpm/\n"
13
13
  s.email = "support@newrelic.com"
14
14
  s.executables = ["newrelic_cmd", "newrelic", "mongrel_rpm"]
@@ -118,8 +118,10 @@ Gem::Specification.new do |s|
118
118
  "lib/new_relic/metric_spec.rb",
119
119
  "lib/new_relic/metrics.rb",
120
120
  "lib/new_relic/noticed_error.rb",
121
+ "lib/new_relic/rack.rb",
121
122
  "lib/new_relic/rack/browser_monitoring.rb",
122
123
  "lib/new_relic/rack/developer_mode.rb",
124
+ "lib/new_relic/rack/error_collector.rb",
123
125
  "lib/new_relic/recipes.rb",
124
126
  "lib/new_relic/stats.rb",
125
127
  "lib/new_relic/timer_lib.rb",
@@ -208,6 +210,7 @@ Gem::Specification.new do |s|
208
210
  "test/new_relic/rack/browser_monitoring_test.rb",
209
211
  "test/new_relic/rack/developer_mode_helper_test.rb",
210
212
  "test/new_relic/rack/developer_mode_test.rb",
213
+ "test/new_relic/rack/error_collector_test.rb",
211
214
  "test/new_relic/stats_test.rb",
212
215
  "test/new_relic/transaction_analysis/segment_summary_test.rb",
213
216
  "test/new_relic/transaction_analysis_test.rb",
@@ -304,7 +307,7 @@ Gem::Specification.new do |s|
304
307
  "vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb"
305
308
  ]
306
309
  s.homepage = "http://www.github.com/newrelic/rpm"
307
- s.post_install_message = "\nPLEASE NOTE:\n\nDeveloper Mode is now a Rack middleware.\n\nDeveloper Mode is no longer available in Rails 2.1 and earlier.\nHowever, starting in version 2.12 you can use Developer Mode in any\nRack based framework, in addition to Rails. To install developer mode\nin a non-Rails application, just add NewRelic::Rack::DeveloperMode to\nyour middleware stack.\n\nIf you are using JRuby, we recommend using at least version 1.4 or \nlater because of issues with the implementation of the timeout library.\n\nRefer to the README.md file for more information.\n\nPlease see http://github.com/newrelic/rpm/blob/master/CHANGELOG\nfor a complete description of the features and enhancements available\nin version 3.4 of the Ruby Agent.\n \n"
310
+ s.post_install_message = "\nPLEASE NOTE:\n\nDeveloper Mode is now a Rack middleware.\n\nDeveloper Mode is no longer available in Rails 2.1 and earlier.\nHowever, starting in version 2.12 you can use Developer Mode in any\nRack based framework, in addition to Rails. To install developer mode\nin a non-Rails application, just add NewRelic::Rack::DeveloperMode to\nyour middleware stack.\n\nIf you are using JRuby, we recommend using at least version 1.4 or \nlater because of issues with the implementation of the timeout library.\n\nRefer to the README.md file for more information.\n\nPlease see http://github.com/newrelic/rpm/blob/master/CHANGELOG\nfor a complete description of the features and enhancements available\nin version 3.5 of the Ruby Agent.\n \n"
308
311
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "New Relic Ruby Agent"]
309
312
  s.require_paths = ["lib"]
310
313
  s.summary = "New Relic Ruby Agent"
@@ -14,7 +14,7 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
14
14
  @sql_sampler = NewRelic::Agent::SqlSampler.new
15
15
  server = NewRelic::Control::Server.new('localhost', 30303)
16
16
  @service = NewRelic::Agent::NewRelicService.new('abcdef', server)
17
- log.stubs(:warn)
17
+ log.stubs(:warn => true, :info => true, :debug => true)
18
18
  end
19
19
 
20
20
  def control
@@ -169,97 +169,70 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
169
169
  end
170
170
 
171
171
  def test_configure_error_collector_base
172
- fake_collector = mocked_error_collector
173
- fake_collector.expects(:config_enabled).returns(false)
174
- fake_collector.expects(:enabled=).with(false)
175
- log.expects(:debug).with("Errors will not be sent to the New Relic service.")
176
- configure_error_collector!(false)
172
+ error_collector = NewRelic::Agent::ErrorCollector.new
173
+ NewRelic::Control.instance.log.stubs(:debug)
174
+ NewRelic::Control.instance.log.expects(:debug) \
175
+ .with("Errors will not be sent to the New Relic service.").at_least_once
176
+ with_config(:'error_collector.enabled' => false) do
177
+ # noop
178
+ end
177
179
  end
178
180
 
179
181
  def test_configure_error_collector_enabled
180
- fake_collector = mocked_error_collector
181
- fake_collector.expects(:config_enabled).returns(true)
182
- fake_collector.expects(:enabled=).with(true)
183
- log.expects(:debug).with("Errors will be sent to the New Relic service.")
184
- configure_error_collector!(true)
182
+ with_config(:'error_collector.enabled' => false) do
183
+ error_collector = NewRelic::Agent::ErrorCollector.new
184
+ NewRelic::Control.instance.log.stubs(:debug)
185
+ NewRelic::Control.instance.log.expects(:debug) \
186
+ .with("Errors will be sent to the New Relic service.").at_least_once
187
+ with_config(:'error_collector.enabled' => true) do
188
+ # noop
189
+ end
190
+ end
185
191
  end
186
192
 
187
193
  def test_configure_error_collector_server_disabled
188
- fake_collector = mocked_error_collector
189
- fake_collector.expects(:config_enabled).returns(true)
190
- fake_collector.expects(:enabled=).with(false)
191
- log.expects(:debug).with("Errors will not be sent to the New Relic service.")
192
- configure_error_collector!(false)
193
- end
194
-
195
- def test_enable_random_samples
196
- sampling_rate = 10
197
- ts = @transaction_sampler = mock('ts')
198
- ts.expects(:random_sampling=).with(true)
199
- ts.expects(:sampling_rate=).with(sampling_rate)
200
- ts.expects(:sampling_rate).returns(sampling_rate)
201
- log.expects(:info).with("Transaction sampling enabled, rate = 10")
202
- enable_random_samples!(sampling_rate)
203
- end
204
-
205
- def test_enable_random_samples_with_no_sampling_rate
206
- # testing that we set a sane default for sampling rate
207
- sampling_rate = 0
208
- ts = @transaction_sampler = mock('ts')
209
- ts.expects(:random_sampling=).with(true)
210
- ts.expects(:sampling_rate=).with(10)
211
- ts.expects(:sampling_rate).returns(10)
212
- log.expects(:info).with("Transaction sampling enabled, rate = 10")
213
- enable_random_samples!(sampling_rate)
214
- end
215
-
216
- def test_config_transaction_tracer
217
- test_config = {
218
- 'transaction_tracer.enabled' => true,
219
- 'transaction_tracer.random_sampler' => false,
220
- 'transaction_tracer.explain_threshold' => 0.75,
221
- 'transaction_tracer.explain_enabled' => true
222
- }
223
- with_config(test_config) do
224
- config_transaction_tracer
225
- assert @transaction_sampler.enabled?
226
- assert_equal 0.75, @transaction_sampler.explain_threshold
227
- assert @transaction_sampler.explain_enabled
194
+ error_collector = NewRelic::Agent::ErrorCollector.new
195
+ NewRelic::Control.instance.log.stubs(:debug)
196
+ NewRelic::Control.instance.log.expects(:debug) \
197
+ .with("Errors will not be sent to the New Relic service.").at_least_once
198
+ config = NewRelic::Agent::Configuration::ServerSource.new('collect_errors' => false)
199
+ with_config(config) do
200
+ # noop
228
201
  end
229
202
  end
230
203
 
231
204
  def test_configure_transaction_tracer_with_random_sampling
232
- @config_should_send_samples = true
233
- @should_send_random_samples = true
234
- @slowest_transaction_threshold = 5
235
- log.stubs(:debug)
236
- self.expects(:enable_random_samples!).with(10)
237
- configure_transaction_tracer!(true, 10)
238
- assert @should_send_samples
239
- assert_equal 5, @transaction_sampler.slow_capture_threshold
205
+ with_config(:'transaction_tracer.transaction_threshold' => 5,
206
+ :'transaction_tracer.random_sample' => true) do
207
+ log.stubs(:debug)
208
+ sample = TransactionSampleTestHelper.make_sql_transaction
209
+ @transaction_sampler.store_sample(sample)
210
+
211
+ assert_equal sample, @transaction_sampler.instance_variable_get(:@random_sample)
212
+ end
240
213
  end
241
214
 
242
215
  def test_configure_transaction_tracer_positive
243
- @config_should_send_samples = true
244
- @slowest_transaction_threshold = 5
245
- log.stubs(:debug)
246
- configure_transaction_tracer!(true, 10)
247
- assert @should_send_samples
248
- assert_equal 5, @transaction_sampler.slow_capture_threshold
216
+ with_config(:'transaction_tracer.enabled' => true) do
217
+ assert @transaction_sampler.enabled?
218
+ end
249
219
  end
250
220
 
251
221
  def test_configure_transaction_tracer_negative
252
- @config_should_send_samples = false
253
- log.expects(:debug).with('Transaction traces will not be sent to the New Relic service.')
254
- configure_transaction_tracer!(true, 10)
255
- assert !@should_send_samples
222
+ with_config(:'transaction_tracer.enabled' => false) do
223
+ assert @transaction_sampler.enabled?
224
+ end
256
225
  end
257
226
 
258
227
  def test_configure_transaction_tracer_server_disabled
259
- @config_should_send_samples = true
228
+ @transaction_sampler.stubs(:log).returns(log)
229
+ log.stubs(:debug)
260
230
  log.expects(:debug).with('Transaction traces will not be sent to the New Relic service.')
261
- configure_transaction_tracer!(false, 10)
262
- assert !@should_send_samples
231
+ config = NewRelic::Agent::Configuration::ServerSource.new('collect_traces' => false,
232
+ 'developer_mode' => false)
233
+ with_config(config) do
234
+ assert !@transaction_sampler.enabled?
235
+ end
263
236
  end
264
237
 
265
238
  def test_apdex_f
@@ -270,58 +243,39 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
270
243
 
271
244
  def test_set_sql_recording_default
272
245
  with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
273
- self.expects(:log_sql_transmission_warning?)
274
- set_sql_recording!
275
- assert_equal :obfuscated, @record_sql, " should default to :obfuscated, was #{@record_sql}"
246
+ assert_equal(:obfuscated, NewRelic::Agent::Database.record_sql_method,
247
+ "should default to :obfuscated, was #{NewRelic::Agent::Database.record_sql_method}")
276
248
  end
277
249
  end
278
250
 
279
251
  def test_set_sql_recording_off
280
252
  with_config(:'transaction_tracer.record_sql' => 'off') do
281
- self.expects(:log_sql_transmission_warning?)
282
- set_sql_recording!
283
- assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
253
+ assert_equal(:off, NewRelic::Agent::Database.record_sql_method,
254
+ "should be set to :off, was #{NewRelic::Agent::Database.record_sql_method}")
284
255
  end
285
256
  end
286
257
 
287
258
  def test_set_sql_recording_none
288
259
  with_config(:'transaction_tracer.record_sql' => 'none') do
289
- self.expects(:log_sql_transmission_warning?)
290
- set_sql_recording!
291
- assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
260
+ assert_equal(:off, NewRelic::Agent::Database.record_sql_method,
261
+ "should be set to :off, was #{NewRelic::Agent::Database.record_sql_method}")
292
262
  end
293
263
  end
294
264
 
295
265
  def test_set_sql_recording_raw
296
266
  with_config(:'transaction_tracer.record_sql' => 'raw') do
297
- self.expects(:log_sql_transmission_warning?)
298
- set_sql_recording!
299
- assert_equal :raw, @record_sql, "should be set to :raw, was #{@record_sql}"
267
+ assert_equal(:raw, NewRelic::Agent::Database.record_sql_method,
268
+ "should be set to :raw, was #{NewRelic::Agent::Database.record_sql_method}")
300
269
  end
301
270
  end
302
271
 
303
272
  def test_set_sql_recording_falsy
304
273
  with_config(:'transaction_tracer.record_sql' => false) do
305
- self.expects(:log_sql_transmission_warning?)
306
- set_sql_recording!
307
- assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
274
+ assert_equal(:off, NewRelic::Agent::Database.record_sql_method,
275
+ "should be set to :off, was #{NewRelic::Agent::Database.record_sql_method}")
308
276
  end
309
277
  end
310
278
 
311
- def test_log_sql_transmission_warning_negative
312
- log = mocked_log
313
- @record_sql = :obfuscated
314
- log.expects(:warn).never
315
- log_sql_transmission_warning?
316
- end
317
-
318
- def test_log_sql_transmission_warning_positive
319
- log = mocked_log
320
- @record_sql = :raw
321
- log.expects(:warn).with('Agent is configured to send raw SQL to the service')
322
- log_sql_transmission_warning?
323
- end
324
-
325
279
  def test_query_server_for_configuration
326
280
  self.expects(:connect_to_server).returns("so happy")
327
281
  self.expects(:finish_setup).with("so happy")
@@ -329,9 +283,9 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
329
283
  end
330
284
 
331
285
  def test_connect_to_server_gets_config_from_collector
286
+ NewRelic::Agent.manual_start
332
287
  service = NewRelic::FakeService.new
333
288
  NewRelic::Agent::Agent.instance.service = service
334
- NewRelic::Agent.manual_start
335
289
  service.mock['connect'] = {'agent_run_id' => 23, 'config' => 'a lot'}
336
290
 
337
291
  response = NewRelic::Agent.agent.connect_to_server
@@ -345,26 +299,40 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
345
299
  def test_finish_setup
346
300
  config = {
347
301
  'agent_run_id' => 'fishsticks',
348
- 'data_report_period' => 'pasta sauce',
349
- 'url_rules' => 'tamales',
350
302
  'collect_traces' => true,
351
303
  'collect_errors' => true,
352
- 'sample_rate' => 10
304
+ 'sample_rate' => 10,
305
+ 'agent_config' => { 'transaction_tracer.record_sql' => 'raw' }
353
306
  }
354
307
  self.expects(:log_connection!).with(config)
355
- self.expects(:configure_transaction_tracer!).with(true, 10)
356
- self.expects(:configure_error_collector!).with(true)
357
308
  @transaction_sampler = stub('transaction sampler', :configure! => true,
358
309
  :config => {})
359
310
  @sql_sampler = stub('sql sampler', :configure! => true)
360
311
  with_config(:'transaction_tracer.enabled' => true) do
361
312
  finish_setup(config)
362
313
  assert_equal 'fishsticks', @service.agent_id
363
- assert_equal 'pasta sauce', @report_period
364
- assert_equal 'tamales', @url_rules
314
+ assert_equal 'raw', NewRelic::Agent.config[:'transaction_tracer.record_sql']
365
315
  end
366
316
  end
367
317
 
318
+ def test_logging_collector_messages
319
+ NewRelic::Agent.manual_start
320
+ service = NewRelic::FakeService.new
321
+ NewRelic::Agent::Agent.instance.service = service
322
+ service.mock['connect'] = {
323
+ 'agent_run_id' => 23, 'config' => 'a lot',
324
+ 'messages' => [{ 'message' => 'beep boop', 'level' => 'INFO' },
325
+ { 'message' => 'ha cha cha', 'level' => 'WARN' }]
326
+ }
327
+
328
+ NewRelic::Control.instance.log.stubs(:info)
329
+ NewRelic::Control.instance.log.expects(:info).with('beep boop')
330
+ NewRelic::Control.instance.log.expects(:warn).with('ha cha cha')
331
+
332
+ NewRelic::Agent.agent.query_server_for_configuration
333
+ NewRelic::Agent.shutdown
334
+ end
335
+
368
336
  def test_finish_setup_without_config
369
337
  @service.agent_id = 'blah'
370
338
  finish_setup(nil)
@@ -377,10 +345,7 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
377
345
  def test_set_apdex_t_from_server
378
346
  service = NewRelic::FakeService.new
379
347
  NewRelic::Agent::Agent.instance.service = service
380
- service.mock['connect'] = {
381
- 'apdex_t' => 0.5,
382
- 'listen_to_server_config' => true
383
- }
348
+ service.mock['connect'] = { 'apdex_t' => 0.5 }
384
349
  with_config(:sync_startup => true, :monitor_mode => true,
385
350
  :license_key => 'a' * 40) do
386
351
  NewRelic::Agent.manual_start