newrelic_rpm 3.8.0.218 → 3.8.1.221

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +32 -0
  3. data/README.md +4 -7
  4. data/Rakefile +3 -0
  5. data/lib/new_relic/agent.rb +3 -7
  6. data/lib/new_relic/agent/agent.rb +4 -14
  7. data/lib/new_relic/agent/agent_logger.rb +19 -11
  8. data/lib/new_relic/agent/autostart.rb +1 -1
  9. data/lib/new_relic/agent/configuration/default_source.rb +25 -12
  10. data/lib/new_relic/agent/configuration/manager.rb +14 -7
  11. data/lib/new_relic/agent/configuration/yaml_source.rb +39 -8
  12. data/lib/new_relic/agent/cross_app_monitor.rb +9 -7
  13. data/lib/new_relic/agent/cross_app_tracing.rb +6 -6
  14. data/lib/new_relic/agent/datastores/mongo.rb +6 -7
  15. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +32 -13
  16. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +4 -3
  17. data/lib/new_relic/agent/error_collector.rb +2 -2
  18. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +10 -69
  19. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +5 -7
  20. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +2 -2
  21. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +77 -93
  22. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/mongo.rb +26 -42
  24. data/lib/new_relic/agent/instrumentation/rubyprof.rb +1 -1
  25. data/lib/new_relic/agent/instrumentation/sinatra.rb +4 -1
  26. data/lib/new_relic/agent/javascript_instrumentor.rb +15 -6
  27. data/lib/new_relic/agent/method_tracer.rb +41 -92
  28. data/lib/new_relic/agent/request_sampler.rb +0 -1
  29. data/lib/new_relic/agent/rules_engine.rb +36 -12
  30. data/lib/new_relic/agent/shim_agent.rb +0 -1
  31. data/lib/new_relic/agent/sql_sampler.rb +8 -15
  32. data/lib/new_relic/agent/stats_engine.rb +2 -6
  33. data/lib/new_relic/agent/stats_engine/metric_stats.rb +8 -2
  34. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  35. data/lib/new_relic/agent/supported_versions.rb +1 -1
  36. data/lib/new_relic/agent/traced_method_stack.rb +87 -0
  37. data/lib/new_relic/agent/transaction.rb +277 -107
  38. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -2
  39. data/lib/new_relic/agent/transaction_sampler.rb +18 -27
  40. data/lib/new_relic/agent/transaction_state.rb +15 -40
  41. data/lib/new_relic/control/instance_methods.rb +8 -4
  42. data/lib/new_relic/recipes.rb +3 -3
  43. data/lib/new_relic/transaction_sample.rb +3 -7
  44. data/lib/new_relic/version.rb +1 -1
  45. data/lib/sequel/extensions/newrelic_instrumentation.rb +3 -3
  46. data/newrelic_rpm.gemspec +15 -9
  47. data/test/agent_helper.rb +71 -36
  48. data/test/environments/norails/Gemfile +2 -0
  49. data/test/environments/rails21/Gemfile +2 -0
  50. data/test/environments/rails22/Gemfile +2 -0
  51. data/test/environments/rails23/Gemfile +2 -0
  52. data/test/environments/rails30/Gemfile +2 -0
  53. data/test/environments/rails31/Gemfile +2 -0
  54. data/test/environments/rails32/Gemfile +2 -0
  55. data/test/environments/rails40/Gemfile +2 -0
  56. data/test/environments/rails41/Gemfile +1 -0
  57. data/test/helpers/mongo_metric_builder.rb +1 -1
  58. data/test/multiverse/suites/agent_only/audit_log_test.rb +2 -2
  59. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +9 -1
  60. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +1 -1
  61. data/test/multiverse/suites/agent_only/logging_test.rb +2 -2
  62. data/test/multiverse/suites/agent_only/marshaling_test.rb +8 -9
  63. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +14 -1
  64. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +30 -13
  65. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +9 -8
  66. data/test/multiverse/suites/agent_only/transaction_ignoring_test.rb +43 -0
  67. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +77 -5
  68. data/test/multiverse/suites/excon/excon_test.rb +1 -1
  69. data/test/multiverse/suites/mongo/Envfile +4 -7
  70. data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +55 -16
  71. data/test/multiverse/suites/mongo/helpers/mongo_server.rb +6 -4
  72. data/test/multiverse/suites/rails/bad_instrumentation_test.rb +2 -2
  73. data/test/multiverse/suites/rails/error_tracing_test.rb +3 -1
  74. data/test/multiverse/suites/rails/request_statistics_test.rb +14 -14
  75. data/test/multiverse/suites/rails/transaction_ignoring_test.rb +45 -0
  76. data/test/multiverse/suites/sequel/sequel_instrumentation_test.rb +1 -1
  77. data/test/new_relic/agent/agent/connect_test.rb +4 -4
  78. data/test/new_relic/agent/agent_logger_test.rb +32 -0
  79. data/test/new_relic/agent/configuration/manager_test.rb +12 -4
  80. data/test/new_relic/agent/configuration/yaml_source_test.rb +2 -2
  81. data/test/new_relic/agent/cross_app_monitor_test.rb +6 -2
  82. data/test/new_relic/agent/cross_app_tracing_test.rb +5 -5
  83. data/test/new_relic/agent/datastores/mongo/statement_formatter_test.rb +7 -6
  84. data/test/new_relic/agent/error_collector_test.rb +1 -2
  85. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +24 -11
  86. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +2 -2
  87. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +12 -17
  88. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +43 -32
  89. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +3 -4
  90. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +36 -20
  91. data/test/new_relic/agent/javascript_instrumentor_test.rb +1 -2
  92. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +15 -26
  93. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +66 -103
  94. data/test/new_relic/agent/method_tracer_test.rb +2 -2
  95. data/test/new_relic/agent/mock_scope_listener.rb +3 -6
  96. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -4
  97. data/test/new_relic/agent/rules_engine_test.rb +13 -0
  98. data/test/new_relic/agent/sql_sampler_test.rb +8 -10
  99. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +18 -0
  100. data/test/new_relic/agent/stats_engine_test.rb +0 -173
  101. data/test/new_relic/agent/threading/agent_thread_test.rb +27 -26
  102. data/test/new_relic/agent/traced_method_stack_test.rb +139 -0
  103. data/test/new_relic/agent/transaction_sample_builder_test.rb +2 -12
  104. data/test/new_relic/agent/transaction_sampler_test.rb +98 -107
  105. data/test/new_relic/agent/transaction_state_test.rb +52 -61
  106. data/test/new_relic/agent/transaction_test.rb +209 -140
  107. data/test/new_relic/agent_test.rb +3 -2
  108. data/test/new_relic/control_test.rb +10 -9
  109. data/test/new_relic/fake_collector.rb +34 -2
  110. data/test/new_relic/http_client_test_cases.rb +0 -5
  111. data/test/new_relic/license_test.rb +4 -2
  112. data/test/new_relic/local_environment_test.rb +14 -28
  113. data/test/new_relic/multiverse_helpers.rb +2 -2
  114. data/test/new_relic/rack/developer_mode_test.rb +4 -5
  115. data/test/new_relic/transaction_ignoring_test_cases.rb +104 -0
  116. data/test/new_relic/transaction_sample_test.rb +14 -7
  117. data/test/performance/lib/performance/instrumentation/gc_stats.rb +6 -3
  118. data/test/performance/suites/transaction_tracing.rb +4 -1
  119. data/test/test_helper.rb +31 -60
  120. data/ui/views/newrelic/show_sample.rhtml +1 -1
  121. metadata +46 -101
  122. metadata.gz.sig +0 -0
  123. data/lib/new_relic/agent/stats_engine/transactions.rb +0 -114
  124. data/lib/new_relic/agent/transaction/pop.rb +0 -52
  125. data/test/new_relic/agent/transaction/pop_test.rb +0 -79
@@ -26,7 +26,7 @@ module NewRelic
26
26
  end
27
27
 
28
28
  def test_start_trace_has_time_even_on_agent_failure
29
- NewRelic::Agent.instance.stats_engine.stubs(:push_scope).raises("Boom!")
29
+ NewRelic::Agent::TracedMethodStack.stubs(:push_frame).raises("Boom!")
30
30
  t0, segment = CrossAppTracing.start_trace(request)
31
31
  refute_nil t0
32
32
  assert_nil segment
@@ -42,19 +42,19 @@ module NewRelic
42
42
 
43
43
  def test_finish_trace_allows_nil_request
44
44
  expects_no_logging(:error)
45
- expects_pop_scope
45
+ expects_pop_frame
46
46
  CrossAppTracing.finish_trace(Time.now, segment, nil, response)
47
47
  end
48
48
 
49
49
  def test_finish_trace_allows_nil_response
50
50
  expects_no_logging(:error)
51
- expects_pop_scope
51
+ expects_pop_frame
52
52
  CrossAppTracing.finish_trace(Time.now, segment, request, nil)
53
53
  end
54
54
 
55
55
 
56
- def expects_pop_scope
57
- NewRelic::Agent.instance.stats_engine.stubs(:pop_scope).once
56
+ def expects_pop_frame
57
+ NewRelic::Agent::TracedMethodStack.stubs(:pop_frame).once
58
58
  end
59
59
  end
60
60
  end
@@ -30,18 +30,18 @@ module NewRelic
30
30
  :_id => "BSON::ObjectId('?')" } }.freeze
31
31
 
32
32
  def test_doesnt_modify_incoming_statement
33
- formatted = StatementFormatter.format(DOC_STATEMENT)
33
+ formatted = StatementFormatter.format(DOC_STATEMENT, :find)
34
34
  refute_same DOC_STATEMENT, formatted
35
35
  end
36
36
 
37
37
  def test_statement_formatter_removes_unwhitelisted_keys
38
- formatted = StatementFormatter.format(DOC_STATEMENT)
38
+ formatted = StatementFormatter.format(DOC_STATEMENT, :find)
39
39
  assert_equal_unordered(formatted.keys, StatementFormatter::PLAINTEXT_KEYS)
40
40
  end
41
41
 
42
42
  def test_can_disable_statement_capturing_queries
43
43
  with_config(:'mongo.capture_queries' => false) do
44
- formatted = StatementFormatter.format(DOC_STATEMENT)
44
+ formatted = StatementFormatter.format(DOC_STATEMENT, :find)
45
45
  assert_nil formatted
46
46
  end
47
47
  end
@@ -49,18 +49,19 @@ module NewRelic
49
49
  def test_statement_formatter_obfuscates_by_default
50
50
  expected = { :database => 'multiverse',
51
51
  :collection => 'tribbles',
52
+ :operation => :find,
52
53
  :selector => { 'name' => '?',
53
54
  :operation => :find,
54
55
  :_id => '?' } }
55
56
 
56
- result = StatementFormatter.format(SELECTOR_STATEMENT)
57
+ result = StatementFormatter.format(SELECTOR_STATEMENT, :find)
57
58
  assert_equal expected, result
58
59
  end
59
60
 
60
61
  def test_statement_formatter_raw_selectors
61
62
  with_config(:'mongo.obfuscate_queries' => false) do
62
- result = StatementFormatter.format(SELECTOR_STATEMENT)
63
- assert_equal SELECTOR_STATEMENT, result
63
+ result = StatementFormatter.format(SELECTOR_STATEMENT, :find)
64
+ assert_equal SELECTOR_STATEMENT.merge(:operation => :find), result
64
65
  end
65
66
  end
66
67
 
@@ -322,12 +322,11 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
322
322
  end
323
323
 
324
324
  def test_blamed_metric_from_transaction
325
- NewRelic::Agent::TransactionState.get.transaction = stub(:name => "Controller/foo/bar")
325
+ NewRelic::Agent::TransactionState.get.most_recent_transaction = stub(:name => "Controller/foo/bar")
326
326
  assert_equal "Errors/Controller/foo/bar", @error_collector.blamed_metric_name({})
327
327
  end
328
328
 
329
329
  def test_blamed_metric_with_no_transaction
330
- NewRelic::Agent::TransactionState.get.transaction = nil
331
330
  assert_nil @error_collector.blamed_metric_name({})
332
331
  end
333
332
 
@@ -25,6 +25,7 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
25
25
  end
26
26
 
27
27
  def setup
28
+ freeze_time
28
29
  @subscriber = NewRelic::Agent::Instrumentation::ActionControllerSubscriber.new
29
30
  NewRelic::Agent.instance.stats_engine.clear_stats
30
31
  @entry_payload = {
@@ -49,7 +50,6 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
49
50
  end
50
51
 
51
52
  def test_record_controller_metrics
52
- freeze_time
53
53
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
54
54
  advance_time(2)
55
55
  @subscriber.finish('process_action.action_controller', :id, @exit_payload)
@@ -62,7 +62,6 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
62
62
  end
63
63
 
64
64
  def test_record_apdex_metrics
65
- freeze_time
66
65
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
67
66
  advance_time(1.5)
68
67
  @subscriber.finish('process_action.action_controller', :id, @exit_payload)
@@ -74,6 +73,19 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
74
73
  )
75
74
  end
76
75
 
76
+ def test_record_apdex_metrics_with_error
77
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
78
+ advance_time(1.5)
79
+ @exit_payload[:exception] = StandardError.new("boo")
80
+ @subscriber.finish('process_action.action_controller', :id, @exit_payload)
81
+
82
+ expected_values = { :apdex_f => 1, :apdex_t => 0, :apdex_s => 0 }
83
+ assert_metrics_recorded(
84
+ 'Apdex/test/index' => expected_values,
85
+ 'Apdex' => expected_values
86
+ )
87
+ end
88
+
77
89
  def test_records_scoped_metrics_for_evented_child_txn
78
90
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
79
91
  @subscriber.start('process_action.action_controller', :id, @entry_payload \
@@ -83,7 +95,7 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
83
95
  @subscriber.finish('process_action.action_controller', :id, @exit_payload)
84
96
 
85
97
  assert_metrics_recorded(
86
- ['Controller/test/child', 'Controller/test/index'] => { :call_count => 1 }
98
+ ['Nested/Controller/test/child', 'Controller/test/child'] => { :call_count => 1 }
87
99
  )
88
100
  end
89
101
 
@@ -99,13 +111,13 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
99
111
  end
100
112
 
101
113
  assert_metrics_recorded(
102
- ['Controller/test/child', 'Controller/test/index'] => { :call_count => 1 }
114
+ ['Nested/Controller/test/child', 'Controller/test/child'] => { :call_count => 1 }
103
115
  )
104
116
  end
105
117
 
106
118
  def test_sets_default_transaction_name_on_start
107
119
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
108
- assert_equal 'Controller/test/index', NewRelic::Agent::Transaction.current.name
120
+ assert_equal 'Controller/test/index', NewRelic::Agent::Transaction.current.best_name
109
121
  ensure
110
122
  @subscriber.finish('process_action.action_controller', :id, @entry_payload)
111
123
  end
@@ -114,13 +126,13 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
114
126
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
115
127
  txn = NewRelic::Agent::Transaction.current
116
128
  @subscriber.finish('process_action.action_controller', :id, @entry_payload)
117
- assert_equal 'Controller/test/index', txn.name
129
+ assert_equal 'Controller/test/index', txn.best_name
118
130
  end
119
131
 
120
132
  def test_sets_transaction_name
121
133
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
122
134
  NewRelic::Agent.set_transaction_name('something/else')
123
- assert_equal 'Controller/something/else', NewRelic::Agent::Transaction.current.name
135
+ assert_equal 'Controller/something/else', NewRelic::Agent::Transaction.current.best_name
124
136
  ensure
125
137
  @subscriber.finish('process_action.action_controller', :id, @entry_payload)
126
138
  end
@@ -130,7 +142,7 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
130
142
  txn = NewRelic::Agent::Transaction.current
131
143
  NewRelic::Agent.set_transaction_name('something/else')
132
144
  @subscriber.finish('process_action.action_controller', :id, @entry_payload)
133
- assert_equal 'Controller/something/else', txn.name
145
+ assert_equal 'Controller/something/else', txn.best_name
134
146
  end
135
147
 
136
148
  def test_record_nothing_for_ignored_action
@@ -168,10 +180,11 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
168
180
 
169
181
  def test_record_busy_time
170
182
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
183
+ advance_time(1)
171
184
  @subscriber.finish('process_action.action_controller', :id, @exit_payload)
172
185
  NewRelic::Agent::BusyCalculator.harvest_busy
173
186
 
174
- assert_metrics_recorded('Instance/Busy' => { :call_count => 1 })
187
+ assert_metrics_recorded('Instance/Busy' => { :call_count => 1, :total_call_time => 1.0 })
175
188
  end
176
189
 
177
190
  def test_creates_transaction
@@ -204,7 +217,7 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
204
217
  end
205
218
 
206
219
  def test_record_queue_time_metrics
207
- t0 = freeze_time
220
+ t0 = Time.now
208
221
  env = { 'HTTP_X_REQUEST_START' => (t0 - 5).to_f.to_s }
209
222
  NewRelic::Agent.instance.events.notify(:before_call, env)
210
223
 
@@ -228,7 +241,7 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
228
241
  end
229
242
 
230
243
  def test_dont_record_queue_time_in_nested_transaction
231
- t0 = freeze_time
244
+ t0 = Time.now
232
245
 
233
246
  env = { 'HTTP_X_REQUEST_START' => (t0 - 5).to_f.to_s }
234
247
  NewRelic::Agent.instance.events.notify(:before_call, env)
@@ -200,7 +200,7 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
200
200
  end
201
201
 
202
202
  sampler = NewRelic::Agent.instance.transaction_sampler
203
- template_segment = sampler.last_sample.root_segment.called_segments[0]
203
+ template_segment = sampler.last_sample.root_segment.called_segments[0].called_segments[0]
204
204
  partial_segment = template_segment.called_segments[0]
205
205
 
206
206
  assert_equal('View/model/index.html.erb/Rendering',
@@ -232,7 +232,7 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
232
232
  end
233
233
 
234
234
  sampler = NewRelic::Agent.instance.transaction_sampler
235
- partial_segments = sampler.last_sample.root_segment.called_segments
235
+ partial_segments = sampler.last_sample.root_segment.called_segments[0].called_segments
236
236
 
237
237
  assert_equal 3, partial_segments.size
238
238
  assert_equal('View/model/_list.html.erb/Partial',
@@ -89,19 +89,13 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Minitest::T
89
89
  def test_creates_txn_segment
90
90
  freeze_time
91
91
 
92
- NewRelic::Agent.manual_start
93
- @stats_engine.start_transaction
94
- sampler = NewRelic::Agent.instance.transaction_sampler
95
- sampler.notice_first_scope_push(Time.now.to_f)
96
- sampler.notice_transaction('/path', {})
97
- sampler.notice_push_scope('Controller/sandwiches/index')
98
- simulate_query(2)
99
- sampler.notice_pop_scope('Controller/sandwiches/index')
100
- sampler.notice_scope_empty(stub('txn', :name => '/path', :custom_parameters => {}, :guid => 'a guid'))
92
+ in_transaction do
93
+ simulate_query(2)
94
+ end
101
95
 
102
96
  last_segment = nil
97
+ sampler = NewRelic::Agent.instance.transaction_sampler
103
98
  sampler.last_sample.root_segment.each_segment{|s| last_segment = s }
104
- NewRelic::Agent.shutdown
105
99
 
106
100
  assert_equal('ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find',
107
101
  last_segment.metric_name)
@@ -110,16 +104,17 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Minitest::T
110
104
  end
111
105
 
112
106
  def test_creates_slow_sql_node
113
- NewRelic::Agent.manual_start
114
- sampler = NewRelic::Agent.instance.sql_sampler
115
- sampler.notice_first_scope_push nil
116
107
  freeze_time
117
108
 
118
- simulate_query(2)
109
+ sampler = NewRelic::Agent.instance.sql_sampler
110
+ sql = nil
111
+
112
+ in_transaction do
113
+ simulate_query(2)
114
+ sql = sampler.transaction_data.sql_data[0].sql
115
+ end
119
116
 
120
- assert_equal 'SELECT * FROM sandwiches', sampler.transaction_data.sql_data[0].sql
121
- ensure
122
- NewRelic::Agent.shutdown
117
+ assert_equal 'SELECT * FROM sandwiches', sql
123
118
  end
124
119
 
125
120
  def test_should_not_raise_due_to_an_exception_during_instrumentation_callback
@@ -22,48 +22,26 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Minitest
22
22
  end
23
23
 
24
24
  def setup
25
+ NewRelic::Agent.drop_buffered_data
25
26
  @object = TestObject.new
26
27
  @dummy_headers = { :request => 'headers' }
27
28
  @txn_namer = NewRelic::Agent::Instrumentation:: \
28
29
  ControllerInstrumentation::TransactionNamer.new(@object)
29
30
  end
30
31
 
31
- def test_detect_upstream_wait_returns_transaction_start_time_if_nothing_from_headers
32
- @object.stubs(:newrelic_request_headers).returns(@dummy_headers)
33
- in_transaction do |txn|
34
- NewRelic::Agent::Instrumentation::QueueTime.expects(:parse_frontend_timestamp) \
35
- .with(@dummy_headers, txn.start_time).returns(txn.start_time)
36
- assert_equal(txn.start_time, @object.send(:_detect_upstream_wait, txn))
37
- end
32
+ def teardown
33
+ NewRelic::Agent.instance.stats_engine.clear_stats
38
34
  end
39
35
 
40
- def test_detect_upstream_wait_returns_parsed_timestamp_from_headers
41
- @object.stubs(:newrelic_request_headers).returns(@dummy_headers)
42
- in_transaction do |txn|
43
- earlier_time = txn.start_time - 1
44
- NewRelic::Agent::Instrumentation::QueueTime.expects(:parse_frontend_timestamp) \
45
- .with(@dummy_headers, txn.start_time).returns(earlier_time)
46
- assert_equal(earlier_time, @object.send(:_detect_upstream_wait, txn))
47
- end
48
- end
49
-
50
- def test_detect_upstream_wait_swallows_errors
51
- @object.stubs(:newrelic_request_headers).returns(@dummy_headers)
52
- in_transaction do |txn|
53
- NewRelic::Agent::Instrumentation::QueueTime.expects(:parse_frontend_timestamp) \
54
- .with(@dummy_headers, txn.start_time).raises("an error")
55
- assert_equal(txn.start_time, @object.send(:_detect_upstream_wait, txn))
56
- end
36
+ def test_apdex_recorded
37
+ @object.public_transaction
38
+ assert_metrics_recorded("Apdex")
57
39
  end
58
40
 
59
- def test_detect_upsteam_wait_does_not_parse_timestamp_in_nested_transaction
60
- @object.stubs(:newrelic_request_headers).returns(@dummy_headers)
61
- in_transaction do |outer|
62
- in_transaction do |inner|
63
- NewRelic::Agent::Instrumentation::QueueTime.expects(:parse_frontend_timestamp).never
64
- assert_equal(inner.start_time, @object.send(:_detect_upstream_wait, inner))
65
- end
66
- end
41
+ def test_apdex_ignored
42
+ @object.stubs(:ignore_apdex?).returns(true)
43
+ @object.public_transaction
44
+ assert_metrics_not_recorded("Apdex")
67
45
  end
68
46
 
69
47
  def test_transaction_name_calls_newrelic_metric_path
@@ -127,4 +105,37 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Minitest
127
105
  end
128
106
  obj = TestObject.new
129
107
  end
108
+
109
+ def test_add_transaction_tracer_defines_with_method
110
+ assert TestObject.method_defined? :public_transaction_with_newrelic_transaction_trace
111
+ end
112
+
113
+ def test_add_transaction_tracer_defines_without_method
114
+ assert TestObject.method_defined? :public_transaction_without_newrelic_transaction_trace
115
+ end
116
+
117
+ def test_parse_punctuation
118
+ ['?', '!', '='].each do |punctuation_mark|
119
+ result = TestObject.parse_punctuation("foo#{punctuation_mark}")
120
+ assert_equal ['foo', punctuation_mark], result
121
+ end
122
+ end
123
+
124
+ def test_argument_list
125
+ options = {:foo => :bar, :params => '{ :account_name => args[0].name }', :far => 7}
126
+ result = TestObject.generate_argument_list(options)
127
+ expected = [":far => \"7\"", ":foo => :bar", ":params => { :account_name => args[0].name }"]
128
+ assert_equal expected.sort, result.sort
129
+ end
130
+
131
+ def test_build_method_names
132
+ result = TestObject.build_method_names('foo', '?')
133
+ expected = ["foo_with_newrelic_transaction_trace?", "foo_without_newrelic_transaction_trace?"]
134
+ assert_equal expected, result
135
+ end
136
+
137
+ def test_already_added_transaction_tracer_returns_true_if_with_method_defined
138
+ with_method_name = 'public_transaction_with_newrelic_transaction_trace'
139
+ assert TestObject.already_added_transaction_tracer?(TestObject, with_method_name)
140
+ end
130
141
  end
@@ -18,16 +18,15 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Minitest::Test
18
18
 
19
19
  @socket = fixture_tcp_socket( @response )
20
20
 
21
- @engine = NewRelic::Agent.instance.stats_engine
22
- @engine.clear_stats
21
+ NewRelic::Agent.instance.stats_engine.clear_stats
23
22
  end
24
23
 
25
24
  def test_scope_stack_integrity_maintained_on_request_failure
26
25
  @socket.stubs(:write).raises('fake network error')
27
26
  with_config(:"cross_application_tracer.enabled" => true) do
28
- expected = @engine.push_scope('dummy')
27
+ expected = NewRelic::Agent::TracedMethodStack.push_frame('dummy')
29
28
  Net::HTTP.get(URI.parse('http://www.google.com/index.html')) rescue nil
30
- @engine.pop_scope(expected, 42)
29
+ NewRelic::Agent::TracedMethodStack.pop_frame(expected, 42)
31
30
  end
32
31
  end
33
32
 
@@ -58,14 +58,21 @@ class NewRelic::Agent::Instrumentation::TaskInstrumentationTest < Minitest::Test
58
58
  run_task_inner(1)
59
59
  assert_metrics_recorded_exclusive(
60
60
  [
61
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
62
+
63
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
61
64
  [
62
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
63
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1'
65
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
66
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0'
67
+ ],
68
+
69
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1',
70
+ [
71
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1',
72
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0'
64
73
  ],
65
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
66
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1'
67
74
  ],
68
- :filter => /^Controller/
75
+ :filter => /^(Sub)?Controller/
69
76
  )
70
77
  end
71
78
 
@@ -73,32 +80,41 @@ class NewRelic::Agent::Instrumentation::TaskInstrumentationTest < Minitest::Test
73
80
  run_task_inner(3)
74
81
  assert_metrics_recorded_exclusive(
75
82
  [
83
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
84
+
85
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
76
86
  [
77
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
78
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1'
87
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
88
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0'
79
89
  ],
90
+
91
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1',
80
92
  [
81
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1',
82
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_2'
93
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1',
94
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0'
83
95
  ],
96
+
97
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_2',
84
98
  [
85
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_2',
86
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_3'
99
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_2',
100
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0'
101
+ ],
102
+
103
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_3',
104
+ [
105
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_3',
106
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0'
87
107
  ],
88
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
89
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1',
90
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_2',
91
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_3'
92
108
  ],
93
- :filter => /^Controller/
109
+ :filter => /^(Nested\/)?Controller/
94
110
  )
95
111
  end
96
112
 
97
113
  def test_should_handle_nested_task_invocations
98
114
  run_task_outer(3)
99
115
  assert_metrics_recorded({
100
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/outer_task' => { :call_count => 1 },
101
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0' => { :call_count => 2 }
116
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/outer_task' => { :call_count => 1 },
117
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0' => { :call_count => 1 }
102
118
  })
103
119
  end
104
120
 
@@ -106,8 +122,8 @@ class NewRelic::Agent::Instrumentation::TaskInstrumentationTest < Minitest::Test
106
122
  run_task_outer(10)
107
123
 
108
124
  assert_metrics_recorded({
109
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/outer_task' => { :call_count => 1 },
110
- 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0' => { :call_count => 2 }
125
+ 'Nested/Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/outer_task' => { :call_count => 1 },
126
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0' => { :call_count => 1 }
111
127
  })
112
128
  assert_metrics_not_recorded(['Controller'])
113
129