newrelic_rpm 3.6.0.83 → 3.6.1.85.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGELOG +27 -0
  2. data/Gemfile +2 -7
  3. data/README.md +1 -1
  4. data/lib/new_relic/agent/agent.rb +3 -2
  5. data/lib/new_relic/agent/autostart.rb +56 -0
  6. data/lib/new_relic/agent/browser_monitoring.rb +19 -14
  7. data/lib/new_relic/agent/configuration/defaults.rb +12 -2
  8. data/lib/new_relic/agent/configuration/environment_source.rb +4 -1
  9. data/lib/new_relic/agent/cross_app_monitor.rb +2 -1
  10. data/lib/new_relic/agent/cross_app_tracing.rb +19 -10
  11. data/lib/new_relic/agent/error_collector.rb +5 -4
  12. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +204 -0
  13. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +88 -0
  14. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
  15. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -1
  16. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +84 -0
  17. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +3 -2
  18. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +104 -87
  19. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +91 -0
  20. data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
  21. data/lib/new_relic/agent/instrumentation/merb/errors.rb +4 -4
  22. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +20 -20
  24. data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -5
  25. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +3 -3
  26. data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +3 -25
  27. data/lib/new_relic/agent/instrumentation/rails4/action_view.rb +2 -115
  28. data/lib/new_relic/agent/instrumentation/rails4/active_record.rb +2 -82
  29. data/lib/new_relic/agent/instrumentation/rails4/errors.rb +3 -4
  30. data/lib/new_relic/agent/method_tracer.rb +93 -56
  31. data/lib/new_relic/agent/null_logger.rb +6 -0
  32. data/lib/new_relic/agent/samplers/cpu_sampler.rb +9 -4
  33. data/lib/new_relic/agent/sql_sampler.rb +10 -6
  34. data/lib/new_relic/agent/stats_engine/metric_stats.rb +19 -3
  35. data/lib/new_relic/agent/stats_engine/transactions.rb +53 -34
  36. data/lib/new_relic/agent/system_info.rb +54 -0
  37. data/lib/new_relic/agent/thread.rb +2 -2
  38. data/lib/new_relic/agent/transaction/pop.rb +52 -0
  39. data/lib/new_relic/agent/transaction.rb +388 -0
  40. data/lib/new_relic/agent/transaction_info.rb +5 -13
  41. data/lib/new_relic/agent/transaction_sample_builder.rb +13 -20
  42. data/lib/new_relic/agent/transaction_sampler.rb +13 -15
  43. data/lib/new_relic/agent/uri_util.rb +35 -0
  44. data/lib/new_relic/agent.rb +54 -11
  45. data/lib/new_relic/build.rb +2 -2
  46. data/lib/new_relic/control/frameworks/rails.rb +0 -1
  47. data/lib/new_relic/control/frameworks/rails3.rb +2 -0
  48. data/lib/new_relic/control/frameworks/rails4.rb +0 -4
  49. data/lib/new_relic/control/instance_methods.rb +5 -19
  50. data/lib/new_relic/control/server_methods.rb +2 -0
  51. data/lib/new_relic/environment_report.rb +4 -34
  52. data/lib/new_relic/latest_changes.rb +1 -1
  53. data/lib/new_relic/local_environment.rb +0 -6
  54. data/lib/new_relic/metric_spec.rb +2 -2
  55. data/lib/new_relic/rack/error_collector.rb +6 -4
  56. data/lib/new_relic/transaction_sample.rb +7 -1
  57. data/lib/new_relic/version.rb +1 -1
  58. data/lib/newrelic_rpm.rb +2 -2
  59. data/newrelic.yml +20 -20
  60. data/test/config/test_control.rb +2 -2
  61. data/test/multiverse/suites/agent_only/audit_log_test.rb +1 -1
  62. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +0 -2
  63. data/test/multiverse/suites/agent_only/logging_test.rb +1 -1
  64. data/test/multiverse/suites/agent_only/marshaling_test.rb +5 -3
  65. data/test/multiverse/suites/agent_only/rename_rule_test.rb +2 -0
  66. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +96 -0
  67. data/test/multiverse/suites/agent_only/testing_app.rb +1 -0
  68. data/test/multiverse/suites/rails/error_tracing_test.rb +17 -29
  69. data/test/multiverse/suites/rails/queue_time_test.rb +8 -2
  70. data/test/multiverse/suites/rails/view_instrumentation_test.rb +6 -3
  71. data/test/multiverse/suites/resque/instrumentation_test.rb +1 -1
  72. data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +8 -0
  73. data/test/new_relic/agent/agent/connect_test.rb +2 -1
  74. data/test/new_relic/agent/agent/start_test.rb +0 -10
  75. data/test/new_relic/agent/agent_logger_test.rb +15 -0
  76. data/test/new_relic/agent/agent_test_controller.rb +6 -2
  77. data/test/new_relic/agent/agent_test_controller_test.rb +20 -69
  78. data/test/new_relic/agent/autostart_test.rb +67 -0
  79. data/test/new_relic/agent/browser_monitoring_test.rb +60 -38
  80. data/test/new_relic/agent/configuration/environment_source_test.rb +19 -17
  81. data/test/new_relic/agent/cross_app_monitor_test.rb +8 -0
  82. data/test/new_relic/agent/error_collector/notice_error_test.rb +0 -5
  83. data/test/new_relic/agent/error_collector_test.rb +8 -9
  84. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +228 -0
  85. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +18 -34
  86. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +5 -5
  87. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +8 -9
  88. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +1 -1
  89. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +24 -38
  90. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +126 -178
  91. data/test/new_relic/agent/instrumentation/rack_test.rb +1 -1
  92. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +135 -151
  93. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +153 -81
  94. data/test/new_relic/agent/method_tracer_test.rb +42 -33
  95. data/test/new_relic/agent/mock_scope_listener.rb +4 -4
  96. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -2
  97. data/test/new_relic/agent/rpm_agent_test.rb +86 -89
  98. data/test/new_relic/agent/sql_sampler_test.rb +18 -19
  99. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +5 -8
  100. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +20 -8
  101. data/test/new_relic/agent/stats_engine/samplers_test.rb +31 -14
  102. data/test/new_relic/agent/stats_engine_test.rb +53 -60
  103. data/test/new_relic/agent/thread_test.rb +7 -7
  104. data/test/new_relic/agent/transaction/pop_test.rb +96 -0
  105. data/test/new_relic/agent/transaction_info_test.rb +6 -17
  106. data/test/new_relic/agent/transaction_sample_builder_test.rb +10 -18
  107. data/test/new_relic/agent/transaction_sampler_test.rb +80 -75
  108. data/test/new_relic/agent/{instrumentation/metric_frame_test.rb → transaction_test.rb} +76 -42
  109. data/test/new_relic/agent/uri_util_test.rb +75 -0
  110. data/test/new_relic/agent_test.rb +115 -9
  111. data/test/test_helper.rb +138 -9
  112. data.tar.gz.sig +0 -0
  113. metadata +37 -74
  114. metadata.gz.sig +0 -0
  115. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +0 -84
  116. data/lib/new_relic/agent/instrumentation/metric_frame.rb +0 -353
  117. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +0 -175
  118. data/test/test_contexts.rb +0 -34
@@ -39,8 +39,7 @@ module NewRelic
39
39
  module Agent
40
40
  extend self
41
41
  def module_method_to_be_traced (x, testcase)
42
- testcase.assert x == "x"
43
- testcase.assert testcase.stats_engine.peek_scope.name == "x"
42
+ testcase.assert_equal 'x', x
44
43
  end
45
44
  end
46
45
  end
@@ -91,32 +90,38 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
91
90
  assert_equal '12345', TestModuleWithLog.other_method
92
91
  end
93
92
 
94
- def test_basic
93
+ def test_trace_execution_scoped_records_metric_data
95
94
  metric = "hello"
96
95
  t1 = Time.now
97
- self.class.trace_execution_scoped metric do
96
+ self.class.trace_execution_scoped(metric) do
98
97
  sleep 0.05
99
- assert metric == @stats_engine.peek_scope.name
100
98
  end
101
99
  elapsed = Time.now - t1
102
100
 
103
101
  stats = @stats_engine.get_stats(metric)
104
102
  check_time stats.total_call_time, elapsed
105
- assert stats.call_count == 1
103
+ assert_equal 1, stats.call_count
104
+ end
105
+
106
+ def test_trace_execution_scoped_pushes_transaction_scope
107
+ self.class.trace_execution_scoped('yeap') do
108
+ 'ptoo'
109
+ end
110
+ assert_equal 'yeap', @scope_listener.scopes.last
106
111
  end
107
112
 
108
113
  def test_basic__original_api
109
114
  metric = "hello"
110
115
  t1 = Time.now
111
- self.class.trace_method_execution metric, true, true, true do
116
+ self.class.trace_method_execution(metric, true, true, true) do
112
117
  sleep 0.05
113
- assert metric == @stats_engine.peek_scope.name
114
118
  end
115
119
  elapsed = Time.now - t1
116
120
 
117
121
  stats = @stats_engine.get_stats(metric)
118
122
  check_time stats.total_call_time, elapsed
119
- assert stats.call_count == 1
123
+ assert_equal 1, stats.call_count
124
+ assert_equal metric, @scope_listener.scopes.last
120
125
  end
121
126
 
122
127
  METRIC = "metric"
@@ -137,7 +142,8 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
137
142
 
138
143
  stats = @stats_engine.get_stats(METRIC)
139
144
  check_time stats.total_call_time, elapsed
140
- assert stats.call_count == 1
145
+ assert_equal 1, stats.call_count
146
+ assert_equal METRIC, @scope_listener.scopes.last
141
147
  end
142
148
 
143
149
  def test_add_method_tracer__default
@@ -172,10 +178,9 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
172
178
  end
173
179
 
174
180
  def test_tt_only
181
+ assert @scope_listener.scopes.empty?
175
182
 
176
- assert_nil @scope_listener.scope["c2"]
177
183
  self.class.add_method_tracer :method_c1, "c1", :push_scope => true
178
-
179
184
  self.class.add_method_tracer :method_c2, "c2", :metric => false
180
185
  self.class.add_method_tracer :method_c3, "c3", :push_scope => false
181
186
 
@@ -185,7 +190,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
185
190
  assert_nil @stats_engine.lookup_stats("c2")
186
191
  assert_not_nil @stats_engine.lookup_stats("c3")
187
192
 
188
- assert_not_nil @scope_listener.scope["c2"]
193
+ assert_equal ['c2', 'c1'], @scope_listener.scopes
189
194
  end
190
195
 
191
196
  def test_nested_scope_tracer
@@ -220,7 +225,10 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
220
225
 
221
226
  stats = @stats_engine.get_stats(METRIC)
222
227
  check_time stats.total_call_time, elapsed
223
- assert stats.call_count == 1
228
+ assert_equal 1, stats.call_count
229
+ assert_equal METRIC, @scope_listener.scopes.last
230
+ assert(METRIC != @scope_listener.scopes[-2],
231
+ 'duplicate scope detected when redundant tracer is present')
224
232
  end
225
233
 
226
234
  def test_add_tracer_with_dynamic_metric
@@ -241,7 +249,8 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
241
249
 
242
250
  stats = @stats_engine.get_stats(expected_metric)
243
251
  check_time stats.total_call_time, elapsed
244
- assert stats.call_count == 1
252
+ assert_equal 1, stats.call_count
253
+ assert_equal expected_metric, @scope_listener.scopes.last
245
254
  end
246
255
 
247
256
  def test_trace_method_with_block
@@ -249,14 +258,15 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
249
258
 
250
259
  t1 = Time.now
251
260
  method_with_block(1,2,3,true,METRIC) do |scope|
252
- assert scope == METRIC
261
+ assert_equal METRIC, scope
253
262
  sleep 0.1 # pad the test a bit to increase the margin of error
254
263
  end
255
264
  elapsed = Time.now - t1
256
265
 
257
266
  stats = @stats_engine.get_stats(METRIC)
258
267
  check_time stats.total_call_time, elapsed
259
- assert stats.call_count == 1
268
+ assert_equal 1, stats.call_count
269
+ assert_equal METRIC, @scope_listener.scopes.last
260
270
  end
261
271
 
262
272
  def test_trace_module_method
@@ -278,15 +288,17 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
278
288
  end
279
289
 
280
290
  def self.static_method(x, testcase, is_traced)
281
- testcase.assert x == "x"
282
- testcase.assert((testcase.stats_engine.peek_scope.name == "x") == is_traced)
291
+ testcase.assert_equal 'x', x
283
292
  end
284
293
 
285
294
  def trace_trace_static_method
286
295
  self.add_method_tracer :static_method, '#{args[0]}'
287
296
  self.class.static_method "x", self, true
297
+ assert_equal 'x', @scope_listener.scopes.last
298
+ @scope_listener = NewRelic::Agent::MockScopeListener.new
288
299
  self.remove_method_tracer :static_method, '#{args[0]}'
289
300
  self.class.static_method "x", self, false
301
+ assert_nil @scope_listener.scopes.last
290
302
  end
291
303
 
292
304
  def test_multiple_metrics__scoped
@@ -299,7 +311,9 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
299
311
  assert_equal 1, m.call_count
300
312
  assert_equal elapsed, m.total_call_time
301
313
  end
314
+ assert_equal 'first', @scope_listener.scopes.last
302
315
  end
316
+
303
317
  def test_multiple_metrics__unscoped
304
318
  metrics = %w[first second third]
305
319
  self.class.trace_execution_unscoped metrics do
@@ -310,23 +324,24 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
310
324
  assert_equal 1, m.call_count
311
325
  assert_equal elapsed, m.total_call_time
312
326
  end
327
+ assert @scope_listener.scopes.empty?
313
328
  end
329
+
314
330
  def test_exception
315
331
  begin
316
332
  metric = "hey"
317
- self.class.trace_execution_scoped metric do
318
- assert @stats_engine.peek_scope.name == metric
333
+ self.class.trace_execution_scoped(metric) do
319
334
  throw StandardError.new
320
335
  end
321
336
 
322
337
  assert false # should never get here
323
338
  rescue StandardError
324
339
  # make sure the scope gets popped
325
- assert @stats_engine.peek_scope == nil
340
+ assert_equal metric, @scope_listener.scopes.last
326
341
  end
327
342
 
328
343
  stats = @stats_engine.get_stats metric
329
- assert stats.call_count == 1
344
+ assert_equal 1, stats.call_count
330
345
  end
331
346
 
332
347
  def test_add_multiple_tracers
@@ -338,6 +353,8 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
338
353
  method_to_be_traced 1,2,3,true,nil
339
354
  self.class.remove_method_tracer :method_to_be_traced, 'XX'
340
355
  method_to_be_traced 1,2,3,false,'XX'
356
+
357
+ assert_equal ['YY'], @scope_listener.scopes
341
358
  end
342
359
 
343
360
  def trace_no_push_scope
@@ -345,6 +362,8 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
345
362
  method_to_be_traced 1,2,3,true,nil
346
363
  self.class.remove_method_tracer :method_to_be_traced, 'X'
347
364
  method_to_be_traced 1,2,3,false,'X'
365
+
366
+ assert_nil @scope_listener.scopes
348
367
  end
349
368
 
350
369
  def check_time(t1, t2)
@@ -358,12 +377,6 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
358
377
  assert x == 1
359
378
  assert y == 2
360
379
  assert z == 3
361
- scope_name = @stats_engine.peek_scope ? @stats_engine.peek_scope.name : nil
362
- if is_traced
363
- assert_equal expected_metric, scope_name
364
- else
365
- assert_not_equal expected_metric, scope_name
366
- end
367
380
  end
368
381
 
369
382
  def method_with_block(x, y, z, is_traced, expected_metric, &block)
@@ -371,10 +384,6 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
371
384
  assert x == 1
372
385
  assert y == 2
373
386
  assert z == 3
374
- block.call(@stats_engine.peek_scope.name)
375
-
376
- scope_name = @stats_engine.peek_scope ? @stats_engine.peek_scope.name : nil
377
- assert((expected_metric == scope_name) == is_traced)
378
387
  end
379
388
 
380
389
  def method_c1
@@ -5,20 +5,20 @@
5
5
 
6
6
  class NewRelic::Agent::MockScopeListener
7
7
 
8
- attr_reader :scope
8
+ attr_reader :scopes
9
9
 
10
10
  def initialize
11
- @scope = {}
11
+ @scopes = []
12
12
  end
13
13
 
14
14
  def notice_first_scope_push(time)
15
15
  end
16
16
 
17
- def notice_push_scope(scope, time)
18
- @scope[scope] = true
17
+ def notice_push_scope(time)
19
18
  end
20
19
 
21
20
  def notice_pop_scope(scope, time)
21
+ @scopes << scope
22
22
  end
23
23
 
24
24
  def notice_scope_empty(time)
@@ -7,6 +7,8 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_hel
7
7
  require 'new_relic/agent/pipe_channel_manager'
8
8
 
9
9
  class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
10
+ include TransactionSampleTestHelper
11
+
10
12
  def setup
11
13
  @test_config = { :developer_mode => true }
12
14
  NewRelic::Agent.config.apply_config(@test_config)
@@ -54,7 +56,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
54
56
 
55
57
  def test_listener_merges_transaction_traces
56
58
  sampler = NewRelic::Agent.agent.transaction_sampler
57
- TransactionSampleTestHelper.run_sample_trace_on(sampler)
59
+ run_sample_trace_on(sampler)
58
60
  NewRelic::Agent.agent.merge_data_from([nil, [sampler.samples], nil])
59
61
 
60
62
  assert_equal(1, NewRelic::Agent.agent.unsent_traces_size)
@@ -64,7 +66,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
64
66
  pid = Process.fork do
65
67
  NewRelic::Agent.after_fork
66
68
  new_sampler = NewRelic::Agent::TransactionSampler.new
67
- sample = TransactionSampleTestHelper.run_sample_trace_on(new_sampler)
69
+ sample = run_sample_trace_on(new_sampler)
68
70
  new_sampler.store_force_persist(sample)
69
71
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
70
72
  listener.pipes[667].write(:transaction_traces => new_sampler.harvest([]))
@@ -4,116 +4,113 @@
4
4
 
5
5
  ENV['SKIP_RAILS'] = 'true'
6
6
  require File.expand_path('../../../test_helper', __FILE__)
7
- require File.expand_path('../../../test_contexts', __FILE__)
8
7
 
9
8
  class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase # ActiveSupport::TestCase
10
- extend TestContexts
11
-
12
- attr_reader :agent
9
+ def setup
10
+ NewRelic::Agent.manual_start
11
+ @agent = NewRelic::Agent.instance
12
+ end
13
13
 
14
- with_running_agent do
15
- # Fake out the agent to think mongrel is running
14
+ def teardown
15
+ NewRelic::Agent.instance.shutdown
16
+ end
16
17
 
17
- should "agent_setup" do
18
- assert NewRelic::Agent.instance.class == NewRelic::Agent::Agent
19
- assert_raise RuntimeError do
20
- NewRelic::Control.instance.init_plugin :agent_enabled => false
21
- end
18
+ def test_agent_setup
19
+ assert(NewRelic::Agent.instance.class == NewRelic::Agent::Agent)
20
+ assert_raise(RuntimeError) do
21
+ NewRelic::Control.instance.init_plugin(:agent_enabled => false)
22
22
  end
23
+ end
23
24
 
24
- should "public_apis" do
25
- assert_raise RuntimeError do
26
- NewRelic::Agent.set_sql_obfuscator(:unknown) do |sql|
27
- puts sql
28
- end
29
- end
30
-
31
- ignore_called = false
32
- NewRelic::Agent.ignore_error_filter do |e|
33
- ignore_called = true
34
- nil
35
- end
36
- NewRelic::Agent.notice_error(StandardError.new("message"), :request_params => {:x => "y"})
37
- assert ignore_called
38
- NewRelic::Agent.instance.error_collector.instance_variable_set '@ignore_filter', nil
25
+ def test_public_apis
26
+ assert_raise(RuntimeError) do
27
+ NewRelic::Agent.set_sql_obfuscator(:unknown) { |sql| puts sql }
39
28
  end
40
29
 
41
- should "startup_shutdown" do
42
- with_config(:agent_enabled => true) do
43
- @agent = NewRelic::Agent::ShimAgent.instance
44
- @agent.shutdown
45
- assert (not @agent.started?)
46
- @agent.start
47
- assert !@agent.started?
48
- # this installs the real agent:
49
- NewRelic::Agent.manual_start
50
- @agent = NewRelic::Agent.instance
51
- assert @agent != NewRelic::Agent::ShimAgent.instance
52
- assert @agent.started?
53
- @agent.shutdown
54
- assert !@agent.started?
55
- @agent.start
56
- assert @agent.started?
57
- NewRelic::Agent.shutdown
58
- end
30
+ ignore_called = false
31
+ NewRelic::Agent.ignore_error_filter do |e|
32
+ ignore_called = true
33
+ nil
59
34
  end
35
+ NewRelic::Agent.notice_error(StandardError.new("message"), :request_params => {:x => "y"})
36
+ assert(ignore_called)
37
+ end
60
38
 
61
- should "manual_start" do
62
- NewRelic::Agent.instance.expects(:connect).once
63
- NewRelic::Agent.instance.expects(:start_worker_thread).once
64
- NewRelic::Agent.instance.instance_variable_set '@started', nil
65
- NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
39
+ def test_startup_shutdown
40
+ with_config(:agent_enabled => true) do
41
+ @agent = NewRelic::Agent::ShimAgent.instance
42
+ @agent.shutdown
43
+ assert (not @agent.started?)
44
+ @agent.start
45
+ assert !@agent.started?
46
+ # this installs the real agent:
47
+ NewRelic::Agent.manual_start
48
+ @agent = NewRelic::Agent.instance
49
+ assert @agent != NewRelic::Agent::ShimAgent.instance
50
+ assert @agent.started?
51
+ @agent.shutdown
52
+ assert !@agent.started?
53
+ @agent.start
54
+ assert @agent.started?
66
55
  NewRelic::Agent.shutdown
67
56
  end
57
+ end
68
58
 
69
- should "post_fork_handler" do
70
- NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
71
- NewRelic::Agent.after_fork
72
- NewRelic::Agent.after_fork
73
- NewRelic::Agent.shutdown
74
- end
75
- should "manual_overrides" do
76
- NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
77
- assert_equal "testjobs", NewRelic::Agent.config.app_names[0]
78
- assert_equal "mailer", NewRelic::Control.instance.local_env.dispatcher_instance_id
79
- NewRelic::Agent.shutdown
80
- end
59
+ def test_manual_start
60
+ NewRelic::Agent.instance.expects(:connect).once
61
+ NewRelic::Agent.instance.expects(:start_worker_thread).once
62
+ NewRelic::Agent.instance.instance_variable_set '@started', nil
63
+ NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
64
+ NewRelic::Agent.shutdown
65
+ end
81
66
 
82
- should "restart" do
83
- NewRelic::Agent.manual_start :app_name => "noapp", :dispatcher_instance_id => ""
84
- NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
85
- assert_equal "testjobs", NewRelic::Agent.config.app_names[0]
86
- assert_equal "mailer", NewRelic::Control.instance.local_env.dispatcher_instance_id
87
- NewRelic::Agent.shutdown
88
- end
67
+ def test_post_fork_handler
68
+ NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
69
+ NewRelic::Agent.after_fork
70
+ NewRelic::Agent.after_fork
71
+ NewRelic::Agent.shutdown
72
+ end
73
+
74
+ def test_manual_overrides
75
+ NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
76
+ assert_equal "testjobs", NewRelic::Agent.config.app_names[0]
77
+ assert_equal "mailer", NewRelic::Control.instance.local_env.dispatcher_instance_id
78
+ NewRelic::Agent.shutdown
79
+ end
80
+
81
+ def test_agent_restart
82
+ NewRelic::Agent.manual_start :app_name => "noapp", :dispatcher_instance_id => ""
83
+ NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
84
+ assert_equal "testjobs", NewRelic::Agent.config.app_names[0]
85
+ assert_equal "mailer", NewRelic::Control.instance.local_env.dispatcher_instance_id
86
+ NewRelic::Agent.shutdown
87
+ end
89
88
 
90
- should "set_record_sql" do
91
- @agent.set_record_sql(false)
92
- assert !NewRelic::Agent.is_sql_recorded?
89
+ def test_set_record_sql
90
+ @agent.set_record_sql(false)
91
+ assert !NewRelic::Agent.is_sql_recorded?
92
+ NewRelic::Agent.disable_sql_recording do
93
+ assert_equal false, NewRelic::Agent.is_sql_recorded?
93
94
  NewRelic::Agent.disable_sql_recording do
94
95
  assert_equal false, NewRelic::Agent.is_sql_recorded?
95
- NewRelic::Agent.disable_sql_recording do
96
- assert_equal false, NewRelic::Agent.is_sql_recorded?
97
- end
98
- assert_equal false, NewRelic::Agent.is_sql_recorded?
99
96
  end
100
- assert !NewRelic::Agent.is_sql_recorded?
101
- @agent.set_record_sql(nil)
97
+ assert_equal false, NewRelic::Agent.is_sql_recorded?
102
98
  end
99
+ assert !NewRelic::Agent.is_sql_recorded?
100
+ @agent.set_record_sql(nil)
101
+ end
103
102
 
104
- should "version" do
105
- assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
106
- end
103
+ def test_agent_version_string
104
+ assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
105
+ end
107
106
 
108
- context "with transaction api" do
109
- should "reject empty arguments" do
110
- assert_raises RuntimeError do
111
- NewRelic::Agent.record_transaction 0.5
112
- end
113
- end
114
- should "record a transaction" do
115
- NewRelic::Agent.record_transaction 0.5, 'uri' => "/users/create?foo=bar"
116
- end
107
+ def test_record_transaction_should_reject_empty_arguments
108
+ assert_raises RuntimeError do
109
+ NewRelic::Agent.record_transaction 0.5
117
110
  end
118
111
  end
112
+
113
+ def test_record_transaction
114
+ NewRelic::Agent.record_transaction 0.5, 'uri' => "/users/create?foo=bar"
115
+ end
119
116
  end
@@ -18,7 +18,7 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
18
18
  assert_nil @sampler.transaction_data
19
19
  @sampler.notice_first_scope_push nil
20
20
  assert_not_nil @sampler.transaction_data
21
- @sampler.notice_scope_empty
21
+ @sampler.notice_scope_empty('txn')
22
22
  assert_nil @sampler.transaction_data
23
23
  end
24
24
 
@@ -46,8 +46,8 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
46
46
 
47
47
  def test_harvest_slow_sql
48
48
  data = NewRelic::Agent::TransactionSqlData.new
49
- data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
50
- 'guid')
49
+ data.set_transaction_info("/c/a", {}, 'guid')
50
+ data.set_transaction_name("WebTransaction/Controller/c/a")
51
51
  data.sql_data.concat [
52
52
  NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
53
53
  NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
@@ -75,8 +75,8 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
75
75
 
76
76
  def test_harvest
77
77
  data = NewRelic::Agent::TransactionSqlData.new
78
- data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
79
- 'guid')
78
+ data.set_transaction_info("/c/a", {}, 'guid')
79
+ data.set_transaction_name("WebTransaction/Controller/c/a")
80
80
  data.sql_data.concat [NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
81
81
  NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
82
82
  NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select", {}, 1.1)]
@@ -88,7 +88,8 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
88
88
 
89
89
  def test_harvest_should_not_take_more_than_10
90
90
  data = NewRelic::Agent::TransactionSqlData.new
91
- data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {}, 'guid')
91
+ data.set_transaction_info("/c/a", {}, 'guid')
92
+ data.set_transaction_name("WebTransaction/Controller/c/a")
92
93
  15.times do |i|
93
94
  data.sql_data << NewRelic::Agent::SlowSql.new("select * from test#{(i+97).chr}",
94
95
  "Database/test#{(i+97).chr}/select", {}, i)
@@ -103,8 +104,8 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
103
104
 
104
105
  def test_harvest_should_aggregate_similar_queries
105
106
  data = NewRelic::Agent::TransactionSqlData.new
106
- data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
107
- 'guid')
107
+ data.set_transaction_info("/c/a", {}, 'guid')
108
+ data.set_transaction_name("WebTransaction/Controller/c/a")
108
109
  queries = [
109
110
  NewRelic::Agent::SlowSql.new("select * from test where foo in (1, 2) ", "Database/test/select", {}, 1.5),
110
111
  NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2, 3 ,4, 5,6, 'snausage')", "Database/test/select", {}, 1.2),
@@ -124,8 +125,8 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
124
125
  .returns([{"header0" => 'bar0', "header1" => 'bar1', "header2" => 'bar2'}])
125
126
 
126
127
  data = NewRelic::Agent::TransactionSqlData.new
127
- data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
128
- 'guid')
128
+ data.set_transaction_info("/c/a", {}, 'guid')
129
+ data.set_transaction_name("WebTransaction/Controller/c/a")
129
130
  queries = [
130
131
  NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
131
132
  NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
@@ -148,9 +149,8 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
148
149
  txn_sampler = NewRelic::Agent::TransactionSampler.new
149
150
  NewRelic::Agent.instance.stats_engine.transaction_sampler = txn_sampler
150
151
  txn_sampler.start_builder(Time.now)
151
- txn_sampler.notice_transaction('a path', 'a uri', {:some => :params})
152
152
  @sampler.create_transaction_data
153
- @sampler.notice_transaction('a path', 'a uri', {:some => :params})
153
+ @sampler.notice_transaction('a uri', {:some => :params})
154
154
 
155
155
  assert_equal(NewRelic::Agent.instance.transaction_sampler.builder.sample.guid,
156
156
  NewRelic::Agent.instance.sql_sampler.transaction_data.guid)
@@ -159,9 +159,8 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
159
159
  def test_should_not_collect_explain_plans_when_disabled
160
160
  with_config(:'transaction_tracer.explain_enabled' => false) do
161
161
  data = NewRelic::Agent::TransactionSqlData.new
162
- data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
163
- 'guid')
164
-
162
+ data.set_transaction_info("/c/a", {}, 'guid')
163
+ data.set_transaction_name("WebTransaction/Controller/c/a")
165
164
  queries = [
166
165
  NewRelic::Agent::SlowSql.new("select * from test",
167
166
  "Database/test/select", {}, 1.5)
@@ -186,8 +185,8 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
186
185
  def test_sends_obfuscated_queries_when_configured
187
186
  with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
188
187
  data = NewRelic::Agent::TransactionSqlData.new
189
- data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
190
- 'guid')
188
+ data.set_transaction_info("/c/a", {}, 'guid')
189
+ data.set_transaction_name("WebTransaction/Controller/c/a")
191
190
  data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test where foo = 'bar'",
192
191
  "Database/test/select", {}, 1.5),
193
192
  NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2,3,4,5)",
@@ -203,8 +202,8 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
203
202
  def test_to_collector_array
204
203
  with_config(:'transaction_tracer.explain_enabled' => false) do
205
204
  data = NewRelic::Agent::TransactionSqlData.new
206
- data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
207
- 'guid')
205
+ data.set_transaction_info("/c/a", {}, 'guid')
206
+ data.set_transaction_name("WebTransaction/Controller/c/a")
208
207
  data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test",
209
208
  "Database/test/select",
210
209
  {}, 1.5)])
@@ -69,15 +69,12 @@ class NewRelic::Agent::StatsEngine::GCProfilerTest < Test::Unit::TestCase
69
69
  return true # no need to test if we're not collecting GC metrics
70
70
  end
71
71
 
72
+ with_config(:'transaction_tracer.enabled' => true) do
73
+ in_transaction { }
74
+ end
75
+
72
76
  engine = NewRelic::Agent.instance.stats_engine
73
- tracer = NewRelic::Agent::TransactionSampler.new
74
- tracer.instance_variable_set(:@last_sample,
75
- NewRelic::TransactionSample.new)
76
- engine.transaction_sampler = tracer
77
- engine.start_transaction
78
- scope = engine.push_scope "scope"
79
- engine.pop_scope scope, 0.01
80
- engine.end_transaction
77
+ tracer = NewRelic::Agent.instance.transaction_sampler
81
78
 
82
79
  gc_stats = engine.get_stats('GC/cumulative')
83
80
  assert_equal 2, gc_stats.call_count
@@ -117,8 +117,9 @@ class NewRelic::Agent::MetricStatsTest < Test::Unit::TestCase
117
117
  end
118
118
 
119
119
  def test_record_metrics_unscoped_metrics_only_by_default
120
- @engine.stubs(:scope_name).returns('scopey')
121
- @engine.record_metrics('foo', 42)
120
+ in_transaction('scopey') do
121
+ @engine.record_metrics('foo', 42)
122
+ end
122
123
  unscoped_stats = @engine.get_stats('foo', false)
123
124
  scoped_stats = @engine.get_stats('foo', true, true, 'scopey')
124
125
  assert_equal(1, unscoped_stats.call_count)
@@ -126,12 +127,13 @@ class NewRelic::Agent::MetricStatsTest < Test::Unit::TestCase
126
127
  end
127
128
 
128
129
  def test_record_metrics_records_to_scoped_metric_if_requested
129
- @engine.stubs(:scope_name).returns('scopey')
130
- @engine.record_metrics('foo', 42, :scoped => true)
130
+ in_transaction('scopey') do
131
+ @engine.record_metrics('foo', 42, :scoped => true)
132
+ end
131
133
  unscoped_stats = @engine.get_stats('foo', false)
132
134
  scoped_stats = @engine.get_stats('foo', true, true, 'scopey')
133
- assert_equal(1, unscoped_stats.call_count)
134
- assert_equal(1, scoped_stats.call_count)
135
+ assert_equal(1, unscoped_stats.call_count, 'missing unscoped metric')
136
+ assert_equal(1, scoped_stats.call_count, 'missing scoped metric')
135
137
  end
136
138
 
137
139
  def test_record_metrics_elides_scoped_metric_if_not_in_transaction
@@ -144,8 +146,9 @@ class NewRelic::Agent::MetricStatsTest < Test::Unit::TestCase
144
146
  end
145
147
 
146
148
  def test_record_metrics_accepts_explicit_scope
147
- @engine.stubs(:scope_name).returns('scopey')
148
- @engine.record_metrics('foo', 42, :scoped => true, :scope => 'not scopey')
149
+ in_transaction('scopey') do
150
+ @engine.record_metrics('foo', 42, :scoped => true, :scope => 'not scopey')
151
+ end
149
152
  unscoped_stats = @engine.get_stats('foo', false)
150
153
  scoped_stats_scopey = @engine.get_stats('foo', true, true, 'scopey')
151
154
  scoped_stats_not_scopey = @engine.get_stats('foo', true, true, 'not scopey')
@@ -181,4 +184,13 @@ class NewRelic::Agent::MetricStatsTest < Test::Unit::TestCase
181
184
  assert_equal(nthreads * iterations, stats_m1.call_count)
182
185
  assert_equal(nthreads * iterations, stats_m2.call_count)
183
186
  end
187
+
188
+ def test_transaction_stats_are_tracked_separately
189
+ in_transaction do
190
+ @engine.record_metrics('foo', 1)
191
+ assert_nil @engine.lookup_stats('foo')
192
+ end
193
+
194
+ assert_equal 1, @engine.lookup_stats('foo').call_count
195
+ end
184
196
  end