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
@@ -6,10 +6,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
6
6
 
7
7
  class NewRelic::Agent::TransactionTest < Minitest::Test
8
8
 
9
- attr_reader :txn
10
-
11
9
  def setup
12
- @txn = NewRelic::Agent::Transaction.new
13
10
  @stats_engine = NewRelic::Agent.instance.stats_engine
14
11
  @stats_engine.reset!
15
12
  NewRelic::Agent.instance.error_collector.reset!
@@ -21,59 +18,74 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
21
18
  end
22
19
 
23
20
  def cleanup_transaction
24
- NewRelic::Agent::Transaction.stack.clear
25
21
  NewRelic::Agent::TransactionState.clear
26
22
  end
27
23
 
28
24
  def test_request_parsing__none
29
- assert_nil txn.uri
30
- assert_nil txn.referer
25
+ in_transaction do |txn|
26
+ assert_nil txn.uri
27
+ assert_nil txn.referer
28
+ end
31
29
  end
32
30
 
33
31
  def test_request_parsing__path
34
- request = stub(:path => '/path?hello=bob#none')
35
- txn.request = request
36
- assert_equal "/path", txn.uri
32
+ in_transaction do |txn|
33
+ request = stub(:path => '/path?hello=bob#none')
34
+ txn.request = request
35
+ assert_equal "/path", txn.uri
36
+ end
37
37
  end
38
38
 
39
39
  def test_request_parsing__fullpath
40
- request = stub(:fullpath => '/path?hello=bob#none')
41
- txn.request = request
42
- assert_equal "/path", txn.uri
40
+ in_transaction do |txn|
41
+ request = stub(:fullpath => '/path?hello=bob#none')
42
+ txn.request = request
43
+ assert_equal "/path", txn.uri
44
+ end
43
45
  end
44
46
 
45
47
  def test_request_parsing__referer
46
- request = stub(:referer => 'https://www.yahoo.com:8080/path/hello?bob=none&foo=bar')
47
- txn.request = request
48
- assert_nil txn.uri
49
- assert_equal "https://www.yahoo.com:8080/path/hello", txn.referer
48
+ in_transaction do |txn|
49
+ request = stub(:referer => 'https://www.yahoo.com:8080/path/hello?bob=none&foo=bar')
50
+ txn.request = request
51
+ assert_nil txn.uri
52
+ assert_equal "https://www.yahoo.com:8080/path/hello", txn.referer
53
+ end
50
54
  end
51
55
 
52
56
  def test_request_parsing__uri
53
- request = stub(:uri => 'http://creature.com/path?hello=bob#none', :referer => '/path/hello?bob=none&foo=bar')
54
- txn.request = request
55
- assert_equal "/path", txn.uri
56
- assert_equal "/path/hello", txn.referer
57
+ in_transaction do |txn|
58
+ request = stub(:uri => 'http://creature.com/path?hello=bob#none', :referer => '/path/hello?bob=none&foo=bar')
59
+ txn.request = request
60
+ assert_equal "/path", txn.uri
61
+ assert_equal "/path/hello", txn.referer
62
+ end
57
63
  end
58
64
 
59
65
  def test_request_parsing__hostname_only
60
- request = stub(:uri => 'http://creature.com')
61
- txn.request = request
62
- assert_equal "/", txn.uri
63
- assert_nil txn.referer
66
+ in_transaction do |txn|
67
+ request = stub(:uri => 'http://creature.com')
68
+ txn.request = request
69
+ assert_equal "/", txn.uri
70
+ assert_nil txn.referer
71
+ end
64
72
  end
65
73
 
66
74
  def test_request_parsing__slash
67
- request = stub(:uri => 'http://creature.com/')
68
- txn.request = request
69
- assert_equal "/", txn.uri
70
- assert_nil txn.referer
75
+ in_transaction do |txn|
76
+ request = stub(:uri => 'http://creature.com/')
77
+ txn.request = request
78
+ assert_equal "/", txn.uri
79
+ assert_nil txn.referer
80
+ end
71
81
  end
72
82
 
73
83
  def test_queue_time
74
- txn.apdex_start = 1000
75
- txn.start_time = 1500
76
- assert_equal 500, txn.queue_time
84
+ in_transaction do |txn|
85
+ txn.apdex_start = 1000
86
+ txn.start_time = 1500
87
+ assert_equal 500, txn.queue_time
88
+ end
77
89
  end
78
90
 
79
91
  def test_apdex_bucket_counts_errors_as_frustrating
@@ -105,61 +117,55 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
105
117
  }
106
118
 
107
119
  with_config(config, :do_not_cast => true) do
108
- txn.name = 'Controller/foo/bar'
109
- assert_equal 1.5, txn.apdex_t
120
+ in_transaction('Controller/foo/bar') do |txn|
121
+ assert_equal 1.5, txn.apdex_t
122
+ end
110
123
 
111
- txn.name = 'Controller/some/other'
112
- assert_equal 2.0, txn.apdex_t
124
+ in_transaction('Controller/some/other') do |txn|
125
+ assert_equal 2.0, txn.apdex_t
126
+ end
113
127
  end
114
128
  end
115
129
 
116
- def test_update_apdex_records_correct_apdex_for_key_transaction
117
- config = {
130
+ KEY_TRANSACTION_CONFIG = {
118
131
  :web_transactions_apdex => {
119
132
  'Controller/slow/txn' => 4,
120
- 'Controller/fast/txn' => 0.1,
121
133
  },
122
134
  :apdex => 1
123
- }
135
+ }
124
136
 
125
- freeze_time
126
- t0 = Time.now
137
+ def test_update_apdex_records_correct_apdex_for_key_transaction
138
+ t0 = freeze_time
127
139
 
128
- # Setting the transaction name from within the in_transaction block seems
129
- # like cheating, but it mimics the way things are actually done, where we
130
- # finalize the transaction name before recording the Apdex metrics.
131
- with_config(config, :do_not_cast => true) do
140
+ with_config(KEY_TRANSACTION_CONFIG, :do_not_cast => true) do
132
141
  in_web_transaction('Controller/slow/txn') do
133
- NewRelic::Agent::Transaction.current.name = 'Controller/slow/txn'
134
142
  NewRelic::Agent::Transaction.record_apdex(t0 + 3.5, false)
135
143
  NewRelic::Agent::Transaction.record_apdex(t0 + 5.5, false)
136
144
  NewRelic::Agent::Transaction.record_apdex(t0 + 16.5, false)
137
145
  end
138
- assert_metrics_recorded(
139
- 'Apdex' => { :apdex_s => 1, :apdex_t => 1, :apdex_f => 1 },
140
- 'Apdex/slow/txn' => { :apdex_s => 1, :apdex_t => 1, :apdex_f => 1 }
141
- )
142
146
 
143
- in_web_transaction('Controller/fast/txn') do
144
- NewRelic::Agent::Transaction.current.name = 'Controller/fast/txn'
145
- NewRelic::Agent::Transaction.record_apdex(t0 + 0.05, false)
146
- NewRelic::Agent::Transaction.record_apdex(t0 + 0.2, false)
147
- NewRelic::Agent::Transaction.record_apdex(t0 + 0.5, false)
148
- end
147
+ # apdex_s is 2 because the transaction itself records apdex
149
148
  assert_metrics_recorded(
150
- 'Apdex' => { :apdex_s => 2, :apdex_t => 2, :apdex_f => 2 },
151
- 'Apdex/fast/txn' => { :apdex_s => 1, :apdex_t => 1, :apdex_f => 1 }
149
+ 'Apdex' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
150
+ 'Apdex/slow/txn' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 }
152
151
  )
152
+ end
153
+ end
154
+
155
+ def test_update_apdex_records_correct_apdex_for_non_key_transaction
156
+ t0 = freeze_time
153
157
 
158
+ with_config(KEY_TRANSACTION_CONFIG, :do_not_cast => true) do
154
159
  in_web_transaction('Controller/other/txn') do
155
- NewRelic::Agent::Transaction.current.name = 'Controller/other/txn'
156
160
  NewRelic::Agent::Transaction.record_apdex(t0 + 0.5, false)
157
161
  NewRelic::Agent::Transaction.record_apdex(t0 + 2, false)
158
162
  NewRelic::Agent::Transaction.record_apdex(t0 + 5, false)
159
163
  end
164
+
165
+ # apdex_s is 2 because the transaction itself records apdex
160
166
  assert_metrics_recorded(
161
- 'Apdex' => { :apdex_s => 3, :apdex_t => 3, :apdex_f => 3 },
162
- 'Apdex/other/txn' => { :apdex_s => 1, :apdex_t => 1, :apdex_f => 1 }
167
+ 'Apdex' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
168
+ 'Apdex/other/txn' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 }
163
169
  )
164
170
  end
165
171
  end
@@ -167,7 +173,6 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
167
173
  def test_record_apdex_stores_apdex_t_in_min_and_max
168
174
  with_config(:apdex_t => 2.5) do
169
175
  in_web_transaction('Controller/some/txn') do
170
- NewRelic::Agent::Transaction.current.name = 'Controller/some/txn'
171
176
  NewRelic::Agent::Transaction.record_apdex(Time.now, false)
172
177
  end
173
178
  end
@@ -179,58 +184,34 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
179
184
  )
180
185
  end
181
186
 
182
- def test_stop_sets_name
183
- NewRelic::Agent::Transaction.start(:controller)
184
- txn = NewRelic::Agent::Transaction.stop('new_name')
185
- assert_equal 'new_name', txn.name
186
- end
187
-
188
187
  def test_name_is_unset_if_nil
189
- txn = NewRelic::Agent::Transaction.new
190
- txn.name = nil
191
- assert !txn.name_set?
192
- end
193
-
194
- def test_name_is_unset_if_unknown
195
- txn = NewRelic::Agent::Transaction.new
196
- txn.name = NewRelic::Agent::UNKNOWN_METRIC
197
- assert !txn.name_set?
188
+ in_transaction do |txn|
189
+ txn.default_name = nil
190
+ assert !txn.name_set?
191
+ end
198
192
  end
199
193
 
200
194
  def test_name_set_if_anything_else
201
- txn = NewRelic::Agent::Transaction.new
202
- txn.name = "anything else"
203
- assert txn.name_set?
195
+ in_transaction("anything else") do |txn|
196
+ assert txn.name_set?
197
+ end
204
198
  end
205
199
 
206
200
  def test_generates_guid_on_initialization
207
- refute_empty txn.guid
208
- end
209
-
210
- def test_start_adds_controller_context_to_txn_stack
211
- NewRelic::Agent::Transaction.start(:controller)
212
- assert_equal 1, NewRelic::Agent::Transaction.stack.size
213
-
214
- NewRelic::Agent::Transaction.start(:controller)
215
- assert_equal 2, NewRelic::Agent::Transaction.stack.size
216
-
217
- NewRelic::Agent::Transaction.stop('txn')
218
- assert_equal 1, NewRelic::Agent::Transaction.stack.size
219
-
220
- NewRelic::Agent::Transaction.stop('txn')
221
- assert_equal 0, NewRelic::Agent::Transaction.stack.size
201
+ in_transaction do |txn|
202
+ refute_empty txn.guid
203
+ end
222
204
  end
223
205
 
224
206
  def test_end_applies_transaction_name_rules
225
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
226
- 'replacement' => '*',
227
- 'replace_all' => true)
228
- NewRelic::Agent.instance.transaction_rules << rule
229
- NewRelic::Agent::Transaction.start(:controller)
230
- NewRelic::Agent.set_transaction_name('foo/1/bar/22')
231
- NewRelic::Agent::Transaction.freeze_name
232
- txn = NewRelic::Agent::Transaction.stop('txn')
233
- assert_equal 'Controller/foo/*/bar/*', txn.name
207
+ in_transaction('Controller/foo/1/bar/22') do |txn|
208
+ rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
209
+ 'replacement' => '*',
210
+ 'replace_all' => true)
211
+ NewRelic::Agent.instance.transaction_rules << rule
212
+ NewRelic::Agent::Transaction.freeze_name_and_execute_if_not_ignored
213
+ assert_equal 'Controller/foo/*/bar/*', txn.best_name
214
+ end
234
215
  ensure
235
216
  NewRelic::Agent.instance.instance_variable_set(:@transaction_rules,
236
217
  NewRelic::Agent::RulesEngine.new)
@@ -246,11 +227,10 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
246
227
  end
247
228
 
248
229
  start_time = freeze_time
249
- NewRelic::Agent::Transaction.start(:controller)
250
- advance_time(5)
251
- NewRelic::Agent.set_transaction_name('foo/1/bar/22')
252
- NewRelic::Agent::Transaction.freeze_name
253
- NewRelic::Agent::Transaction.stop('txn')
230
+ in_web_transaction('Controller/foo/1/bar/22') do
231
+ advance_time(5)
232
+ NewRelic::Agent::Transaction.freeze_name_and_execute_if_not_ignored
233
+ end
254
234
 
255
235
  assert_equal 'Controller/foo/1/bar/22', name
256
236
  assert_equal start_time.to_f, timestamp
@@ -259,14 +239,15 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
259
239
  end
260
240
 
261
241
  def test_end_fires_a_transaction_finished_event_with_overview_metrics
242
+ freeze_time
262
243
  options = nil
263
244
  NewRelic::Agent.subscribe(:transaction_finished) do |payload|
264
245
  options = payload[:metrics]
265
246
  end
266
247
 
267
- NewRelic::Agent::Transaction.start(:controller)
268
- NewRelic::Agent.record_metric("HttpDispatcher", 2.1)
269
- NewRelic::Agent::Transaction.stop('txn')
248
+ in_web_transaction('Controller/foo/1/bar/22') do
249
+ NewRelic::Agent.record_metric("HttpDispatcher", 2.1)
250
+ end
270
251
 
271
252
  assert_equal 2.1, options[NewRelic::MetricSpec.new('HttpDispatcher')].total_call_time
272
253
  end
@@ -277,9 +258,9 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
277
258
  options = payload[:custom_params]
278
259
  end
279
260
 
280
- NewRelic::Agent::Transaction.start(:controller)
281
- NewRelic::Agent.add_custom_parameters('fooz' => 'barz')
282
- NewRelic::Agent::Transaction.stop('txn')
261
+ in_web_transaction('Controller/foo/1/bar/22') do
262
+ NewRelic::Agent.add_custom_parameters('fooz' => 'barz')
263
+ end
283
264
 
284
265
  assert_equal 'barz', options['fooz']
285
266
  end
@@ -339,32 +320,9 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
339
320
 
340
321
  def test_logs_warning_if_a_non_hash_arg_is_passed_to_add_custom_params
341
322
  expects_logging(:warn, includes("add_custom_parameters"))
342
- NewRelic::Agent::Transaction.start(:controller)
343
- NewRelic::Agent.add_custom_parameters('fooz')
344
- NewRelic::Agent::Transaction.stop('txn')
345
- end
346
-
347
- def test_parent_returns_parent_transaction_if_there_is_one
348
- txn, outer_txn = nil
349
- in_transaction('outer') do
350
- outer_txn = NewRelic::Agent::Transaction.current
351
- in_transaction('inner') do
352
- txn = NewRelic::Agent::Transaction.parent
353
- end
354
- end
355
- assert_same(outer_txn, txn)
356
- end
357
-
358
- def test_parent_returns_nil_if_there_is_no_parent
359
- txn = 'this is a non-nil placeholder'
360
- in_transaction('outer') do
361
- txn = NewRelic::Agent::Transaction.parent
323
+ in_transaction do
324
+ NewRelic::Agent.add_custom_parameters('fooz')
362
325
  end
363
- assert_nil(txn)
364
- end
365
-
366
- def test_parent_returns_nil_if_outside_transaction_entirely
367
- assert_nil(NewRelic::Agent::Transaction.parent)
368
326
  end
369
327
 
370
328
  def test_user_attributes_alias_to_custom_parameters
@@ -452,6 +410,117 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
452
410
  assert_equal(42, trace.params[:custom_params][:gc_time])
453
411
  end
454
412
 
413
+ def test_freeze_name_and_execute_if_not_ignored_executes_given_block_if_not_ignored
414
+ NewRelic::Agent.instance.transaction_rules.expects(:rename).
415
+ returns('non-ignored-transaction')
416
+ in_transaction('non-ignored-transaction') do
417
+ block_was_called = false
418
+ NewRelic::Agent::Transaction.freeze_name_and_execute_if_not_ignored do
419
+ block_was_called = true
420
+ end
421
+
422
+ assert block_was_called
423
+ end
424
+ end
425
+
426
+ def test_freeze_name_and_execute_if_not_ignored_ignores_given_block_if_transaction_ignored
427
+ NewRelic::Agent.instance.transaction_rules.expects(:rename).
428
+ returns(nil)
429
+ in_transaction('ignored-transaction') do
430
+ block_was_called = false
431
+ NewRelic::Agent::Transaction.freeze_name_and_execute_if_not_ignored do
432
+ block_was_called = true
433
+ end
434
+
435
+ refute block_was_called
436
+ end
437
+ end
438
+
439
+ def test_record_transaction_cpu_positive
440
+ in_transaction do |txn|
441
+ txn.expects(:cpu_burn).twice.returns(1.0)
442
+ NewRelic::Agent.instance.transaction_sampler.expects(:notice_transaction_cpu_time).twice.with(1.0)
443
+ txn.record_transaction_cpu
444
+ end
445
+ end
446
+
447
+ def test_record_transaction_cpu_negative
448
+ in_transaction do |txn|
449
+ txn.expects(:cpu_burn).twice.returns(nil)
450
+ # should not be called for the nil case
451
+ NewRelic::Agent.instance.transaction_sampler.expects(:notice_transaction_cpu_time).never
452
+ txn.record_transaction_cpu
453
+ end
454
+ end
455
+
456
+ def test_normal_cpu_burn_positive
457
+ in_transaction do |txn|
458
+ txn.instance_variable_set(:@process_cpu_start, 3)
459
+ txn.expects(:process_cpu).twice.returns(4)
460
+ assert_equal 1, txn.normal_cpu_burn
461
+ end
462
+ end
463
+
464
+ def test_normal_cpu_burn_negative
465
+ in_transaction do |txn|
466
+ txn.instance_variable_set(:@process_cpu_start, nil)
467
+ txn.expects(:process_cpu).never
468
+ assert_equal nil, txn.normal_cpu_burn
469
+ end
470
+ end
471
+
472
+ def test_jruby_cpu_burn_negative
473
+ in_transaction do |txn|
474
+ txn.instance_variable_set(:@jruby_cpu_start, nil)
475
+ txn.expects(:jruby_cpu_time).never
476
+ assert_equal nil, txn.jruby_cpu_burn
477
+ end
478
+ end
479
+
480
+ def test_cpu_burn_normal
481
+ in_transaction do |txn|
482
+ txn.expects(:normal_cpu_burn).twice.returns(1)
483
+ txn.expects(:jruby_cpu_burn).never
484
+ assert_equal 1, txn.cpu_burn
485
+ end
486
+ end
487
+
488
+ def test_cpu_burn_jruby
489
+ in_transaction do |txn|
490
+ txn.expects(:normal_cpu_burn).twice.returns(nil)
491
+ txn.expects(:jruby_cpu_burn).twice.returns(2)
492
+ assert_equal 2, txn.cpu_burn
493
+ end
494
+ end
495
+
496
+ def test_transaction_takes_child_name_if_similar_type
497
+ in_transaction('Controller/parent', :type => :sinatra) do
498
+ in_transaction('Controller/child', :type => :controller) do
499
+ end
500
+ end
501
+
502
+ assert_metrics_recorded(['Controller/child'])
503
+ end
504
+
505
+ def test_transaction_doesnt_take_child_name_if_different_type
506
+ in_transaction('Controller/parent', :type => :sinatra) do
507
+ in_transaction('Whatever/child', :type => :task) do
508
+ end
509
+ end
510
+
511
+ assert_metrics_recorded(['Controller/parent'])
512
+ end
513
+
514
+ def test_transaction_should_take_child_name_if_frozen_early
515
+ in_transaction('Controller/parent', :type => :sinatra) do
516
+ in_transaction('Controller/child', :type => :controller) do |txn|
517
+ txn.freeze_name_and_execute_if_not_ignored
518
+ end
519
+ end
520
+
521
+ assert_metrics_recorded(['Controller/child'])
522
+ end
523
+
455
524
  def assert_has_custom_parameter(key, value = key)
456
525
  assert_equal(value, NewRelic::Agent::Transaction.current.custom_parameters[key])
457
526
  end