newrelic_rpm 3.6.6.147 → 3.6.7.152

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +0 -1
  3. data/CHANGELOG +55 -17
  4. data/Guardfile +7 -0
  5. data/Rakefile +6 -0
  6. data/bin/mongrel_rpm +33 -0
  7. data/bin/newrelic +13 -0
  8. data/bin/newrelic_cmd +5 -0
  9. data/bin/nrdebug +273 -0
  10. data/install.rb +3 -3
  11. data/lib/new_relic/agent.rb +4 -6
  12. data/lib/new_relic/agent/agent.rb +76 -72
  13. data/lib/new_relic/agent/autostart.rb +18 -5
  14. data/lib/new_relic/agent/browser_monitoring.rb +41 -35
  15. data/lib/new_relic/agent/browser_token.rb +38 -0
  16. data/lib/new_relic/agent/busy_calculator.rb +7 -5
  17. data/lib/new_relic/agent/commands/agent_command.rb +19 -0
  18. data/lib/new_relic/agent/commands/agent_command_router.rb +88 -0
  19. data/lib/new_relic/agent/commands/thread_profiler.rb +80 -0
  20. data/lib/new_relic/agent/configuration/default_source.rb +700 -0
  21. data/lib/new_relic/agent/configuration/environment_source.rb +83 -30
  22. data/lib/new_relic/agent/configuration/manager.rb +8 -8
  23. data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
  24. data/lib/new_relic/agent/cross_app_monitor.rb +10 -21
  25. data/lib/new_relic/agent/cross_app_tracing.rb +3 -3
  26. data/lib/new_relic/agent/error_collector.rb +7 -10
  27. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -1
  28. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +5 -1
  29. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +5 -1
  30. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
  31. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -12
  33. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -0
  34. data/lib/new_relic/agent/instrumentation/{rails4/active_record.rb → active_record_4.rb} +1 -1
  35. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -11
  36. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -6
  37. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +12 -6
  38. data/lib/new_relic/agent/instrumentation/curb.rb +11 -2
  39. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -3
  40. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +11 -2
  41. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +13 -4
  42. data/lib/new_relic/agent/instrumentation/puma.rb +2 -1
  43. data/lib/new_relic/agent/instrumentation/rack.rb +15 -17
  44. data/lib/new_relic/agent/method_tracer.rb +181 -191
  45. data/lib/new_relic/agent/new_relic_service.rb +16 -14
  46. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  47. data/lib/new_relic/agent/request_sampler.rb +32 -165
  48. data/lib/new_relic/agent/sampled_buffer.rb +79 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -8
  50. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  51. data/lib/new_relic/agent/stats_engine.rb +1 -1
  52. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  53. data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -3
  54. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -22
  55. data/lib/new_relic/agent/threading/agent_thread.rb +41 -0
  56. data/lib/new_relic/agent/threading/backtrace_node.rb +71 -0
  57. data/lib/new_relic/agent/threading/thread_profile.rb +172 -0
  58. data/lib/new_relic/agent/transaction.rb +16 -4
  59. data/lib/new_relic/agent/transaction_sample_builder.rb +13 -3
  60. data/lib/new_relic/agent/transaction_sampler.rb +5 -8
  61. data/lib/new_relic/agent/transaction_state.rb +166 -0
  62. data/lib/new_relic/agent/transaction_timings.rb +53 -0
  63. data/lib/new_relic/cli/command.rb +91 -0
  64. data/lib/new_relic/{commands → cli}/deployments.rb +13 -9
  65. data/lib/new_relic/{commands → cli}/install.rb +2 -2
  66. data/lib/new_relic/control/frameworks/rails.rb +1 -8
  67. data/lib/new_relic/control/instance_methods.rb +1 -2
  68. data/lib/new_relic/helper.rb +9 -0
  69. data/lib/new_relic/local_environment.rb +16 -63
  70. data/lib/new_relic/rack/browser_monitoring.rb +8 -5
  71. data/lib/new_relic/recipes.rb +44 -31
  72. data/lib/new_relic/transaction_sample.rb +6 -2
  73. data/lib/new_relic/version.rb +1 -1
  74. data/lib/tasks/install.rake +21 -1
  75. data/newrelic_rpm.gemspec +5 -1
  76. data/test/agent_helper.rb +4 -9
  77. data/test/environments/.gitignore +16 -0
  78. data/test/environments/lib/environments/runner.rb +104 -0
  79. data/test/environments/norails/Gemfile +11 -0
  80. data/test/environments/norails/Rakefile +9 -0
  81. data/test/environments/rails21/Gemfile +24 -0
  82. data/test/environments/rails21/Rakefile +12 -0
  83. data/test/environments/rails21/app/controllers/application.rb +20 -0
  84. data/test/environments/rails21/config/boot.rb +113 -0
  85. data/test/environments/rails21/config/database.yml +31 -0
  86. data/test/environments/rails21/config/environment.rb +28 -0
  87. data/test/environments/rails21/config/environments/development.rb +16 -0
  88. data/test/environments/rails21/config/environments/production.rb +8 -0
  89. data/test/environments/rails21/config/environments/test.rb +10 -0
  90. data/test/environments/rails21/config/routes.rb +5 -0
  91. data/test/environments/rails21/db/schema.rb +5 -0
  92. data/test/environments/rails22/Gemfile +29 -0
  93. data/test/environments/rails22/Rakefile +12 -0
  94. data/test/environments/rails22/app/controllers/application.rb +20 -0
  95. data/test/environments/rails22/config/boot.rb +113 -0
  96. data/test/environments/rails22/config/database.yml +31 -0
  97. data/test/environments/rails22/config/environment.rb +27 -0
  98. data/test/environments/rails22/config/environments/development.rb +16 -0
  99. data/test/environments/rails22/config/environments/production.rb +8 -0
  100. data/test/environments/rails22/config/environments/test.rb +10 -0
  101. data/test/environments/rails22/config/routes.rb +5 -0
  102. data/test/environments/rails22/db/schema.rb +5 -0
  103. data/test/environments/rails23/Gemfile +22 -0
  104. data/test/environments/rails23/Rakefile +12 -0
  105. data/test/environments/rails23/app/controllers/application.rb +20 -0
  106. data/test/environments/rails23/config/boot.rb +127 -0
  107. data/test/environments/rails23/config/database.yml +31 -0
  108. data/test/environments/rails23/config/environment.rb +25 -0
  109. data/test/environments/rails23/config/environments/development.rb +16 -0
  110. data/test/environments/rails23/config/environments/production.rb +8 -0
  111. data/test/environments/rails23/config/environments/test.rb +10 -0
  112. data/test/environments/rails23/config/preinitializer.rb +25 -0
  113. data/test/environments/rails23/config/routes.rb +5 -0
  114. data/test/environments/rails23/db/schema.rb +5 -0
  115. data/test/environments/rails30/Gemfile +19 -0
  116. data/test/environments/rails30/Rakefile +9 -0
  117. data/test/environments/rails30/config/application.rb +17 -0
  118. data/test/environments/rails30/config/boot.rb +10 -0
  119. data/test/environments/rails30/config/database.yml +31 -0
  120. data/test/environments/rails30/config/environment.rb +6 -0
  121. data/test/environments/rails30/config/initializers/new_rails_defaults.rb +11 -0
  122. data/test/environments/rails30/db/schema.rb +5 -0
  123. data/test/environments/rails31/Gemfile +19 -0
  124. data/test/environments/rails31/Rakefile +9 -0
  125. data/test/environments/rails31/config/application.rb +18 -0
  126. data/test/environments/rails31/config/boot.rb +10 -0
  127. data/test/environments/rails31/config/database.yml +31 -0
  128. data/test/environments/rails31/config/environment.rb +6 -0
  129. data/test/environments/rails31/config/initializers/new_rails_defaults.rb +21 -0
  130. data/test/environments/rails31/db/schema.rb +5 -0
  131. data/test/environments/rails32/Gemfile +25 -0
  132. data/test/environments/rails32/Rakefile +9 -0
  133. data/test/environments/rails32/config/application.rb +19 -0
  134. data/test/environments/rails32/config/boot.rb +10 -0
  135. data/test/environments/rails32/config/database.yml +31 -0
  136. data/test/environments/rails32/config/environment.rb +6 -0
  137. data/test/environments/rails32/db/schema.rb +5 -0
  138. data/test/environments/rails40/Gemfile +25 -0
  139. data/test/environments/rails40/Rakefile +9 -0
  140. data/test/environments/rails40/config/application.rb +18 -0
  141. data/test/environments/rails40/config/boot.rb +10 -0
  142. data/test/environments/rails40/config/database.yml +31 -0
  143. data/test/environments/rails40/config/environment.rb +6 -0
  144. data/test/environments/rails40/db/schema.rb +5 -0
  145. data/test/multiverse/lib/multiverse/suite.rb +24 -12
  146. data/test/multiverse/suites/agent_only/logging_test.rb +18 -1
  147. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +1 -8
  148. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +10 -7
  149. data/test/multiverse/suites/curb/curb_test.rb +17 -3
  150. data/test/multiverse/suites/excon/Envfile +1 -1
  151. data/test/multiverse/suites/excon/excon_test.rb +18 -2
  152. data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
  153. data/test/multiverse/suites/net_http/net_http_test.rb +2 -2
  154. data/test/multiverse/suites/rails/error_tracing_test.rb +35 -8
  155. data/test/multiverse/suites/rails/ignore_test.rb +48 -0
  156. data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +44 -0
  157. data/test/multiverse/suites/sequel/sequel_test.rb +11 -0
  158. data/test/multiverse/suites/sinatra/ignoring_test.rb +2 -2
  159. data/test/multiverse/suites/typhoeus/Envfile +9 -2
  160. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +3 -2
  161. data/test/new_relic/agent/agent/start_test.rb +3 -22
  162. data/test/new_relic/agent/agent_test.rb +6 -5
  163. data/test/new_relic/agent/autostart_test.rb +39 -1
  164. data/test/new_relic/agent/browser_monitoring_test.rb +43 -88
  165. data/test/new_relic/agent/browser_token_test.rb +52 -0
  166. data/test/new_relic/agent/busy_calculator_test.rb +1 -1
  167. data/test/new_relic/agent/commands/agent_command_router_test.rb +98 -0
  168. data/test/new_relic/agent/commands/agent_command_test.rb +37 -0
  169. data/test/new_relic/agent/commands/thread_profiler_test.rb +177 -0
  170. data/test/new_relic/agent/configuration/default_source_test.rb +81 -0
  171. data/test/new_relic/agent/configuration/environment_source_test.rb +81 -7
  172. data/test/new_relic/agent/configuration/manager_test.rb +16 -1
  173. data/test/new_relic/agent/cross_app_monitor_test.rb +3 -5
  174. data/test/new_relic/agent/error_collector_test.rb +14 -0
  175. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
  176. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +2 -3
  177. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +29 -31
  178. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +22 -0
  179. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +2 -2
  180. data/test/new_relic/agent/method_tracer_test.rb +2 -2
  181. data/test/new_relic/agent/new_relic_service_test.rb +5 -49
  182. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -0
  183. data/test/new_relic/agent/request_sampler_test.rb +32 -95
  184. data/test/new_relic/agent/rpm_agent_test.rb +7 -5
  185. data/test/new_relic/agent/sampled_buffer_test.rb +178 -0
  186. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +0 -1
  187. data/test/new_relic/agent/stats_engine_test.rb +10 -17
  188. data/test/new_relic/agent/threading/agent_thread_test.rb +107 -0
  189. data/test/new_relic/agent/threading/backtrace_node_test.rb +96 -0
  190. data/test/new_relic/agent/{threaded_test.rb → threading/fake_thread.rb} +0 -25
  191. data/test/new_relic/agent/threading/thread_profile_test.rb +308 -0
  192. data/test/new_relic/agent/threading/threaded_test_case.rb +33 -0
  193. data/test/new_relic/agent/transaction/pop_test.rb +0 -16
  194. data/test/new_relic/agent/transaction_sample_builder_test.rb +23 -4
  195. data/test/new_relic/agent/transaction_sampler_test.rb +14 -15
  196. data/test/new_relic/agent/transaction_state_test.rb +75 -0
  197. data/test/new_relic/agent/transaction_test.rb +15 -0
  198. data/test/new_relic/agent/transaction_timings_test.rb +81 -0
  199. data/test/new_relic/agent_test.rb +12 -14
  200. data/test/new_relic/{command → cli}/deployments_test.rb +41 -13
  201. data/test/new_relic/control/frameworks/rails_test.rb +1 -2
  202. data/test/new_relic/control_test.rb +1 -2
  203. data/test/new_relic/dependency_detection_test.rb +14 -0
  204. data/test/new_relic/fake_collector.rb +1 -0
  205. data/test/new_relic/helper_test.rb +7 -2
  206. data/test/new_relic/http_client_test_cases.rb +33 -1
  207. data/test/new_relic/local_environment_test.rb +0 -23
  208. data/test/new_relic/metric_data_test.rb +4 -0
  209. data/test/new_relic/rack/browser_monitoring_test.rb +31 -30
  210. data/test/performance/lib/performance/result.rb +15 -4
  211. data/test/performance/lib/performance/timer.rb +7 -1
  212. data/test/performance/script/baselines +102 -0
  213. data/test/performance/suites/rum_autoinsertion.rb +57 -0
  214. data/test/rum/basic.result.html +10 -0
  215. data/test/rum/basic.source.html +10 -0
  216. data/test/rum/comments1.result.html +24 -0
  217. data/test/rum/comments1.source.html +24 -0
  218. data/test/rum/comments2.result.html +24 -0
  219. data/test/rum/comments2.source.html +24 -0
  220. data/test/rum/gt_in_quotes1.result.html +27 -0
  221. data/test/rum/gt_in_quotes1.source.html +27 -0
  222. data/test/rum/gt_in_quotes2.result.html +24 -0
  223. data/test/rum/gt_in_quotes2.source.html +24 -0
  224. data/test/rum/gt_in_quotes_mismatch.result.html +24 -0
  225. data/test/rum/gt_in_quotes_mismatch.source.html +24 -0
  226. data/test/rum/gt_in_single_quotes1.result.html +25 -0
  227. data/test/rum/gt_in_single_quotes1.source.html +25 -0
  228. data/test/rum/gt_in_single_quotes_mismatch.result.html +25 -0
  229. data/test/rum/gt_in_single_quotes_mismatch.source.html +25 -0
  230. data/test/rum/incomplete_non_meta_tags.result.html +10 -0
  231. data/test/rum/incomplete_non_meta_tags.source.html +10 -0
  232. data/test/rum/no_body.result.html +21 -0
  233. data/test/rum/no_body.source.html +21 -0
  234. data/test/rum/no_header.result.html +7 -0
  235. data/test/rum/no_header.source.html +7 -0
  236. data/test/rum/no_start_header.result.html +9 -0
  237. data/test/rum/no_start_header.source.html +9 -0
  238. data/test/rum/script1.result.html +19 -0
  239. data/test/rum/script1.source.html +19 -0
  240. data/test/rum/script2.result.html +17 -0
  241. data/test/rum/script2.source.html +17 -0
  242. data/test/rum/x_ua_meta_tag.result.html +10 -0
  243. data/test/rum/x_ua_meta_tag.source.html +10 -0
  244. data/test/rum/x_ua_meta_tag_multiline.result.html +11 -0
  245. data/test/rum/x_ua_meta_tag_multiline.source.html +11 -0
  246. data/test/rum/x_ua_meta_tag_with_others.result.html +11 -0
  247. data/test/rum/x_ua_meta_tag_with_others.source.html +11 -0
  248. data/test/rum/x_ua_meta_tag_with_spaces.result.html +10 -0
  249. data/test/rum/x_ua_meta_tag_with_spaces.source.html +10 -0
  250. data/test/script/ci.sh +1 -12
  251. data/test/test_helper.rb +1 -0
  252. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +11 -0
  253. metadata +225 -32
  254. metadata.gz.sig +0 -0
  255. data/lib/new_relic/agent/configuration/defaults.rb +0 -157
  256. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +0 -56
  257. data/lib/new_relic/agent/thread.rb +0 -37
  258. data/lib/new_relic/agent/thread_profiler.rb +0 -323
  259. data/lib/new_relic/agent/transaction_info.rb +0 -114
  260. data/lib/new_relic/command.rb +0 -89
  261. data/test/new_relic/agent/agent_test_controller_test.rb +0 -348
  262. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +0 -70
  263. data/test/new_relic/agent/thread_profiler_test.rb +0 -586
  264. data/test/new_relic/agent/thread_test.rb +0 -93
  265. data/test/new_relic/agent/transaction_info_test.rb +0 -99
@@ -39,6 +39,17 @@ class ErrorController < ApplicationController
39
39
  raise ServerIgnoredError.new('this is a server ignored error')
40
40
  end
41
41
 
42
+ def frozen_error
43
+ e = RuntimeError.new("frozen errors make a refreshing treat on a hot summer day")
44
+ e.freeze
45
+ raise e
46
+ end
47
+
48
+ def string_noticed_error
49
+ NewRelic::Agent.notice_error("trilobites died out millions of years ago")
50
+ render :text => 'trilobites'
51
+ end
52
+
42
53
  def noticed_error
43
54
  newrelic_notice_error(RuntimeError.new('this error should be noticed'))
44
55
  render :text => "Shoulda noticed an error"
@@ -102,6 +113,18 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
102
113
  'Controller/error/noticed_error')
103
114
  end
104
115
 
116
+ def test_should_capture_frozen_errors
117
+ get '/error/frozen_error'
118
+ assert_error_reported_once("frozen errors make a refreshing treat on a hot summer day",
119
+ "Controller/error/frozen_error")
120
+ end
121
+
122
+ def test_should_capture_string_noticed_errors
123
+ get '/error/string_noticed_error'
124
+ assert_error_reported_once("trilobites died out millions of years ago",
125
+ "Controller/error/string_noticed_error")
126
+ end
127
+
105
128
  # Important choice of controllor_error, since this goes through both the
106
129
  # transaction and the rack error collector, so risks multiple counting!
107
130
  def test_should_capture_multiple_errors
@@ -109,17 +132,17 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
109
132
  get '/error/controller_error'
110
133
  end
111
134
 
112
- assert_errors_reported('this is an uncaught controller error', 20, 40)
135
+ assert_errors_reported('this is an uncaught controller error', 20, 40, nil, 40)
113
136
  end
114
137
 
115
138
  def test_should_capture_manually_noticed_error
116
139
  NewRelic::Agent.notice_error(RuntimeError.new('this is a noticed error'))
117
- assert_error_reported_once('this is a noticed error')
140
+ assert_error_reported_once('this is a noticed error', nil, nil)
118
141
  end
119
142
 
120
143
  def test_should_capture_routing_error
121
144
  get '/bad_route'
122
- assert_error_reported_once('this is an uncaught routing error')
145
+ assert_error_reported_once('this is an uncaught routing error', nil, nil)
123
146
  end
124
147
 
125
148
  def test_should_apply_parameter_filtering
@@ -171,28 +194,32 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
171
194
 
172
195
  def test_should_capture_errors_raised_in_middleware_before_call
173
196
  get '/error/middleware_error/before'
174
- assert_error_reported_once('middleware error')
197
+ assert_error_reported_once('middleware error', nil, nil)
175
198
  end
176
199
 
177
200
  def test_should_capture_errors_raised_in_middleware_after_call
178
201
  get '/error/middleware_error/after'
179
- assert_error_reported_once('middleware error')
202
+ assert_error_reported_once('middleware error', nil, nil)
180
203
  end
181
204
 
182
205
  protected
183
206
 
184
- def assert_errors_reported(message, queued_count, total_count=queued_count, txn_name=nil)
207
+ def assert_errors_reported(message, queued_count, total_count=queued_count, txn_name=nil, apdex_f=1)
185
208
  expected = { :call_count => total_count }
186
209
  assert_metrics_recorded("Errors/all" => expected)
187
210
  assert_metrics_recorded("Errors/#{txn_name}" => expected) if txn_name
188
211
 
212
+ unless apdex_f.nil?
213
+ assert_metrics_recorded("Apdex" => { :apdex_f => apdex_f })
214
+ end
215
+
189
216
  assert_equal(queued_count,
190
217
  @error_collector.errors.select{|error| error.message == message}.size,
191
218
  "Wrong number of errors with message #{message.inspect} found")
192
219
  end
193
220
 
194
- def assert_error_reported_once(message, txn_name=nil)
195
- assert_errors_reported(message, 1, 1, txn_name)
221
+ def assert_error_reported_once(message, txn_name=nil, apdex_f=1)
222
+ assert_errors_reported(message, 1, 1, txn_name, apdex_f)
196
223
  end
197
224
  end
198
225
 
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ # https://newrelic.atlassian.net/browse/RUBY-927
6
+
7
+ require 'rails/test_help'
8
+ require './app'
9
+ require 'multiverse_helpers'
10
+
11
+ class IgnoredController < ApplicationController
12
+ include Rails.application.routes.url_helpers
13
+
14
+ newrelic_ignore :only => :action_to_ignore
15
+ newrelic_ignore_apdex :only => :action_to_ignore_apdex
16
+
17
+ def action_to_ignore
18
+ render :text => "Ignore this"
19
+ end
20
+
21
+ def action_to_ignore_apdex
22
+ render :text => "This too"
23
+ end
24
+ end
25
+
26
+ class IgnoredActionsTest < ActionDispatch::IntegrationTest
27
+
28
+ include MultiverseHelpers
29
+
30
+ setup_and_teardown_agent
31
+
32
+ def after_setup
33
+ # Make sure we've got a blank slate for doing easier metric comparisons
34
+ NewRelic::Agent.instance.reset_stats
35
+ end
36
+
37
+ def test_metric__ignore
38
+ get 'ignored/action_to_ignore'
39
+ assert_metrics_recorded_exclusive([])
40
+ end
41
+
42
+ def test_metric__ignore_apdex
43
+ get 'ignored/action_to_ignore_apdex'
44
+ assert_metrics_recorded(["Controller/ignored/action_to_ignore_apdex"])
45
+ assert_metrics_not_recorded(["Apdex"])
46
+ end
47
+
48
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ # https://newrelic.atlassian.net/browse/RUBY-927
6
+
7
+ # Mongrel is only supported on older versions, so don't check for queue depth
8
+ if Rails::VERSION::MAJOR.to_i < 4
9
+
10
+ require 'rails/test_help'
11
+ require './app'
12
+ require 'multiverse_helpers'
13
+ require 'ostruct'
14
+
15
+ class MongrelController < ApplicationController
16
+ include Rails.application.routes.url_helpers
17
+
18
+ def deep
19
+ respond_to do |format|
20
+ format.html { render :text => "<html><head></head><body>Deep</body></html>" }
21
+ end
22
+ end
23
+ end
24
+
25
+ class MongrelQueueDepthTest < ActionDispatch::IntegrationTest
26
+
27
+ include MultiverseHelpers
28
+
29
+ setup_and_teardown_agent(:beacon => "beacon", :browser_key => "key")
30
+
31
+ def test_mongrel_queue
32
+ mongrel = OpenStruct.new(:workers => OpenStruct.new(:list => OpenStruct.new(:length => "10")))
33
+ NewRelic::Control.instance.local_env.mongrel = mongrel
34
+
35
+ get('/mongrel/deep')
36
+
37
+ assert_metrics_recorded(['HttpDispatcher'])
38
+ assert_metrics_recorded('Mongrel/Queue Length' => {:call_count => 1, :total_call_time => 9.0})
39
+ assert_metrics_not_recorded(['WebFrontend/Mongrel/Average Queue Time'])
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -31,4 +31,15 @@ class SequelTest < MiniTest::Unit::TestCase
31
31
  assert u.is_a?( User ), "#{u} isn't a User"
32
32
  end
33
33
 
34
+ # The oldest version of Sequel that we test against does not define a VERSION
35
+ # constant, or the in_transaction? method, so skip this test for that version.
36
+ if DB.respond_to?(:in_transaction?)
37
+ def test_should_not_clobber_in_transaction
38
+ require 'newrelic_rpm'
39
+
40
+ DB.transaction do
41
+ assert_equal(true, DB.in_transaction?)
42
+ end
43
+ end
44
+ end
34
45
  end
@@ -129,7 +129,7 @@ class SinatraIgnoreTest < SinatraTestCase
129
129
  def test_ignore_enduser
130
130
  get_and_assert_ok '/no_enduser'
131
131
 
132
- assert NewRelic::Agent::TransactionInfo.get.ignore_end_user?
132
+ assert NewRelic::Agent::TransactionState.get.request_ignore_enduser
133
133
  assert_metrics_recorded([
134
134
  "Controller/Sinatra/#{app_name}/GET no_enduser",
135
135
  "Apdex/Sinatra/#{app_name}/GET no_enduser"])
@@ -183,6 +183,6 @@ class SinatraIgnoreApdexAndEndUserTest < SinatraTestCase
183
183
 
184
184
  def test_ignores_enduser
185
185
  get_and_assert_ok '/'
186
- assert NewRelic::Agent::TransactionInfo.get.ignore_end_user?
186
+ assert NewRelic::Agent::TransactionState.get.request_ignore_enduser
187
187
  end
188
188
  end
@@ -1,5 +1,12 @@
1
- suite_condition("Typhoeus not supported in 1.8.6") do
2
- RUBY_VERSION != '1.8.6'
1
+ suite_condition("Typhoeus not supported in 1.8.6 and excluded on 1.8.7 non-REE") do
2
+
3
+ # Under Ruby 1.8.7 (but not REE), there are persistent segfaults with Typhoeus
4
+ # and the Ruby agent. This predated our Typhoeus instrumentation, but given
5
+ # usage levels and obscurity of the issue, it isn't worth deeper digging.
6
+ # Just use REE, or better yet >= 1.9
7
+
8
+ (RUBY_VERSION != '1.8.6') &&
9
+ (RUBY_VERSION != '1.8.7' || RUBY_DESCRIPTION =~ /Enterprise/)
3
10
  end
4
11
 
5
12
  gemfile <<-RB
@@ -30,8 +30,9 @@ if NewRelic::Agent::Instrumentation::TyphoeusTracing.is_supported_version?
30
30
 
31
31
  # We use the Typhoeus::Request rather than right on Typhoeus to support
32
32
  # prior to convenience methods being added on the top-level module (0.5.x)
33
- def get_response(url=nil)
34
- Typhoeus::Request.get(url || default_url, ssl_option)
33
+ def get_response(url=nil, headers=nil)
34
+ options = {:headers => headers}.merge(ssl_option)
35
+ Typhoeus::Request.get(url || default_url, options)
35
36
  end
36
37
 
37
38
  def head_response
@@ -51,10 +51,11 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
51
51
  end
52
52
 
53
53
  def test_check_config_and_start_agent_normal
54
+
54
55
  self.expects(:generate_environment_report)
55
56
  self.expects(:start_worker_thread)
56
57
  self.expects(:install_exit_handler)
57
- with_config(:sync_startup => false, :monitor_mode => true, :license_key => 'a' * 40) do
58
+ with_config(:dispatcher => 'test', :sync_startup => false, :monitor_mode => true, :license_key => 'a' * 40) do
58
59
  check_config_and_start_agent
59
60
  end
60
61
  end
@@ -64,7 +65,7 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
64
65
  self.expects(:connect_in_foreground)
65
66
  self.expects(:start_worker_thread)
66
67
  self.expects(:install_exit_handler)
67
- with_config(:sync_startup => true, :monitor_mode => true, :license_key => 'a' * 40) do
68
+ with_config(:dispatcher => 'test', :sync_startup => true, :monitor_mode => true, :license_key => 'a' * 40) do
68
69
  check_config_and_start_agent
69
70
  end
70
71
  end
@@ -172,26 +173,6 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
172
173
  end
173
174
  end
174
175
 
175
- def test_log_unless_positive
176
- # should not log
177
- assert log_unless(true, :warn, "DURRR")
178
- end
179
-
180
- def test_log_unless_negative
181
- # should log
182
- expects_logging(:warn, "DURRR")
183
- assert !log_unless(false, :warn, "DURRR")
184
- end
185
-
186
- def test_log_if_positive
187
- expects_logging(:warn, "WHEE")
188
- assert log_if(true, :warn, "WHEE")
189
- end
190
-
191
- def test_log_if_negative
192
- assert !log_if(false, :warn, "WHEE")
193
- end
194
-
195
176
  private
196
177
 
197
178
  def mocked_control
@@ -3,7 +3,7 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
- require 'new_relic/agent/thread_profiler'
6
+ require 'new_relic/agent/commands/thread_profiler'
7
7
 
8
8
  module NewRelic
9
9
  module Agent
@@ -13,6 +13,7 @@ module NewRelic
13
13
  super
14
14
  @agent = NewRelic::Agent::Agent.new
15
15
  @agent.service = default_service
16
+ @agent.agent_command_router.stubs(:service).returns(@agent.service)
16
17
  @agent.stubs(:start_worker_thread)
17
18
  end
18
19
 
@@ -21,7 +22,7 @@ module NewRelic
21
22
  #
22
23
 
23
24
  def with_profile(opts)
24
- profile = NewRelic::Agent::ThreadProfile.new(-1, 0, 0, true)
25
+ profile = NewRelic::Agent::Threading::ThreadProfile.new(create_agent_command)
25
26
  profile.aggregate(["chunky.rb:42:in `bacon'"], profile.traces[:other])
26
27
  profile.instance_variable_set(:@finished, opts[:finished])
27
28
 
@@ -173,9 +174,9 @@ module NewRelic
173
174
  assert_equal([], @agent.send(:harvest_errors), 'should return errors')
174
175
  end
175
176
 
176
- def test_check_for_agent_commands
177
+ def test_handle_for_agent_commands
177
178
  @agent.service.expects(:get_agent_commands).returns([]).once
178
- @agent.send :check_for_agent_commands
179
+ @agent.send :handle_agent_commands
179
180
  end
180
181
 
181
182
  def test_merge_data_from_empty
@@ -253,7 +254,7 @@ module NewRelic
253
254
 
254
255
  # This method should NOT increment error counts, since that has already
255
256
  # been counted in the child
256
- assert_equal 0, NewRelic::Agent.get_stats("Errors/all").call_count
257
+ assert_equal 0, @agent.stats_engine.get_stats("Errors/all").call_count
257
258
  end
258
259
 
259
260
  def test_connect_retries_on_timeout
@@ -14,7 +14,7 @@ class AutostartTest < Test::Unit::TestCase
14
14
  if defined?(::Rails)
15
15
  def test_agent_wont_autostart_if_RAILS_CONSOLE_constant_is_defined
16
16
  assert !defined?(::Rails::Console), "precondition: Rails::Console shouldn't be defined"
17
- Rails.const_set(:Console, true)
17
+ Rails.const_set(:Console, Class.new)
18
18
  assert ! ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't autostart in Rails Console session"
19
19
  ensure
20
20
  Rails.send(:remove_const, :Console)
@@ -23,6 +23,13 @@ class AutostartTest < Test::Unit::TestCase
23
23
  puts "Skipping tests in #{__FILE__} because Rails is unavailable"
24
24
  end
25
25
 
26
+ def test_agent_will_autostart_if_global_CONSOLE_constant_is_defined
27
+ Object.const_set(:Console, Class.new)
28
+ assert ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't find ::Console"
29
+ ensure
30
+ Object.send(:remove_const, :Console)
31
+ end
32
+
26
33
  def test_agent_wont_start_if_dollar_0_is_irb
27
34
  @orig_dollar_0, $0 = $0, '/foo/bar/irb'
28
35
  assert ! ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't autostart when process is invoked by irb"
@@ -68,4 +75,35 @@ class AutostartTest < Test::Unit::TestCase
68
75
  assert ! ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't during blacklisted rake task"
69
76
  end
70
77
  end
78
+
79
+ module ::Outer
80
+ class Included
81
+ end
82
+ end
83
+
84
+ class ::Excluded
85
+ end
86
+
87
+ module ::ContainsAnObject
88
+ class ContainedObject
89
+ end
90
+ end
91
+
92
+ def test_should_look_within_module
93
+ assert_equal ::Outer::Included, NewRelic::Agent::Autostart.constant_is_defined?("Outer::Included")
94
+ end
95
+
96
+ def test_shouldnt_look_outside_module_for_class
97
+ assert_equal false, NewRelic::Agent::Autostart.constant_is_defined?("Outer::Excluded")
98
+ end
99
+
100
+ def test_shouldnt_look_outside_module_for_module
101
+ assert_equal false, NewRelic::Agent::Autostart.constant_is_defined?("Outer::Outer")
102
+ end
103
+
104
+ def test_should_allow_object_in_module_names
105
+ assert_equal ::ContainsAnObject::ContainedObject,
106
+ NewRelic::Agent::Autostart.constant_is_defined?("ContainsAnObject::ContainedObject")
107
+ end
108
+
71
109
  end
@@ -5,7 +5,7 @@
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
6
  require "new_relic/agent/browser_monitoring"
7
7
  require "new_relic/rack/browser_monitoring"
8
- require 'ostruct'
8
+ require 'base64'
9
9
 
10
10
  class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
11
11
  include NewRelic::Agent::BrowserMonitoring
@@ -28,10 +28,15 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
28
28
  NewRelic::Agent.instance.instance_eval do
29
29
  @beacon_configuration = NewRelic::Agent::BeaconConfiguration.new
30
30
  end
31
+
32
+ # By default we expect our transaction to have a start time
33
+ # All sorts of basics don't output without this setup initially
34
+ NewRelic::Agent::TransactionState.reset(nil)
35
+ current_transaction.start_time = Time.now
31
36
  end
32
37
 
33
38
  def teardown
34
- NewRelic::Agent::TransactionInfo.clear
39
+ NewRelic::Agent::TransactionState.clear
35
40
  NewRelic::Agent.config.remove_config(@config)
36
41
  mocha_teardown
37
42
  end
@@ -40,7 +45,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
40
45
  assert NewRelic::Agent.config[:'browser_monitoring.auto_instrument']
41
46
  end
42
47
 
43
- def test_browser_monitoring_start_time_is_reset_each_request_when_auto_instrument_is_disabled
48
+ def test_start_time_reset_each_request_when_auto_instrument_is_disabled
44
49
  controller = Object.new
45
50
  def controller.perform_action_without_newrelic_trace(method, options={});
46
51
  # noop; instrument me
@@ -51,9 +56,10 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
51
56
 
52
57
  with_config(:'browser_monitoring.auto_instrument' => false) do
53
58
  controller.perform_action_with_newrelic_trace(:index)
54
- first_request_start_time = controller.send(:browser_monitoring_start_time)
59
+ first_request_start_time = current_transaction.start_time
60
+
55
61
  controller.perform_action_with_newrelic_trace(:index)
56
- second_request_start_time = controller.send(:browser_monitoring_start_time)
62
+ second_request_start_time = current_transaction.start_time
57
63
 
58
64
  # assert that these aren't the same time object
59
65
  # the start time should be reinitialized each request to the controller
@@ -104,9 +110,10 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
104
110
 
105
111
  def test_browser_timing_footer
106
112
  with_config(:license_key => 'a' * 13) do
113
+ NewRelic::Agent::TransactionState.reset
107
114
  browser_timing_header
108
115
  footer = browser_timing_footer
109
- snippet = '<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
116
+ snippet = '<script type="text/javascript">if (typeof NREUMQ !== "undefined") { if (!NREUMQ.f) { NREUMQ.f=function() {
110
117
  NREUMQ.push(["load",new Date().getTime()]);
111
118
  var e=document.createElement("script");'
112
119
  assert(footer.include?(snippet),
@@ -134,6 +141,7 @@ var e=document.createElement("script");'
134
141
  end
135
142
 
136
143
  def test_browser_timing_footer_with_rum_enabled_not_specified
144
+ NewRelic::Agent::TransactionState.reset
137
145
  browser_timing_header
138
146
 
139
147
  license_bytes = [];
@@ -142,10 +150,10 @@ var e=document.createElement("script");'
142
150
  config.expects(:license_bytes).returns(license_bytes).at_least_once
143
151
  NewRelic::Agent.instance.stubs(:beacon_configuration).returns(config).at_least_once
144
152
  footer = browser_timing_footer
145
- beginning_snippet = '<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
153
+ beginning_snippet = '<script type="text/javascript">if (typeof NREUMQ !== "undefined") { if (!NREUMQ.f) { NREUMQ.f=function() {
146
154
  NREUMQ.push(["load",new Date().getTime()]);
147
155
  var e=document.createElement("script");'
148
- ending_snippet = "]);</script>"
156
+ ending_snippet = "]);}</script>"
149
157
  assert(footer.include?(beginning_snippet),
150
158
  "expected footer to include beginning snippet: #{beginning_snippet}, but was #{footer}")
151
159
  assert(footer.include?(ending_snippet),
@@ -189,13 +197,12 @@ var e=document.createElement("script");'
189
197
  end
190
198
 
191
199
  def test_generate_footer_js_null_case
192
- self.expects(:browser_monitoring_start_time).returns(nil)
200
+ current_transaction.start_time = nil
193
201
  assert_equal('', generate_footer_js(NewRelic::Agent.instance.beacon_configuration), "should not send javascript when there is no start time")
194
202
  end
195
203
 
196
204
  def test_generate_footer_js_with_start_time
197
205
  with_config(:browser_key => 'a' * 40) do
198
- self.expects(:browser_monitoring_start_time).returns(Time.at(100))
199
206
  fake_bc = mock('beacon configuration')
200
207
  NewRelic::Agent.instance.stubs(:beacon_configuration).returns(fake_bc)
201
208
  self.expects(:footer_js_string).with(NewRelic::Agent.instance.beacon_configuration).returns('footer js')
@@ -205,20 +212,18 @@ var e=document.createElement("script");'
205
212
  end
206
213
 
207
214
  def test_browser_monitoring_transaction_name_basic
208
- mock = stub_everything('transaction info')
209
- NewRelic::Agent::TransactionInfo.set(mock)
210
215
  txn = NewRelic::Agent::Transaction.new
211
216
  txn.name = 'a transaction name'
212
- mock.stubs(:transaction).returns(txn)
217
+ NewRelic::Agent::TransactionState.get.transaction = txn
213
218
 
214
219
  assert_equal('a transaction name', browser_monitoring_transaction_name, "should take the value from the thread local")
215
220
  end
216
221
 
217
222
  def test_browser_monitoring_transaction_name_empty
218
- mock = mock('transaction sample')
219
- NewRelic::Agent::TransactionInfo.set(mock)
223
+ txn = NewRelic::Agent::Transaction.new
224
+ txn.name = ''
225
+ NewRelic::Agent::TransactionState.get.transaction = txn
220
226
 
221
- mock.stubs(:transaction).returns(stub(:name => ''))
222
227
  assert_equal('', browser_monitoring_transaction_name, "should take the value even when it is empty")
223
228
  end
224
229
 
@@ -237,78 +242,19 @@ var e=document.createElement("script");'
237
242
  end
238
243
  end
239
244
 
240
- def test_browser_monitoring_start_time
241
- mock = mock('transaction info')
242
-
243
- NewRelic::Agent::TransactionInfo.set(mock)
244
-
245
- mock.stubs(:start_time).returns(Time.at(100))
246
- mock.stubs(:guid).returns('ABC')
247
- assert_equal(Time.at(100), browser_monitoring_start_time, "should take the value from the thread local")
248
- end
249
-
250
- def test_clamp_to_positive
251
- assert_equal(0.0, clamp_to_positive(-1), "should clamp a negative value to zero")
252
- assert_equal(1232, clamp_to_positive(1232), "should pass through the value when it is positive")
253
- assert_equal(0, clamp_to_positive(0), "should not mess with zero when passing it through")
254
- end
255
-
256
- def test_browser_monitoring_app_time_nonzero
257
- start = Time.now
258
- self.expects(:browser_monitoring_start_time).returns(start - 1)
259
- Time.stubs(:now).returns(start)
260
- assert_equal(1000, browser_monitoring_app_time, 'should return a rounded time')
261
- end
262
-
263
- def test_browser_monitoring_queue_time_nil
264
- assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is no queue time')
265
- end
266
-
267
- def test_browser_monitoring_queue_time_zero
268
- in_transaction do
269
- NewRelic::Agent::Transaction.current.expects(:queue_time).returns(0.0)
270
- assert_equal(0.0, browser_monitoring_queue_time,
271
- 'should return zero when there is zero queue time')
272
- end
273
- end
274
-
275
- def test_browser_monitoring_queue_time_ducks
276
- in_transaction do
277
- NewRelic::Agent::Transaction.current.expects(:queue_time) \
278
- .returns('a duck')
279
- assert_equal(0.0, browser_monitoring_queue_time,
280
- 'should return zero when there is an incorrect queue time')
281
- end
282
- end
283
-
284
- def test_browser_monitoring_queue_time_nonzero
285
- in_transaction do
286
- NewRelic::Agent::Transaction.current.expects(:queue_time) \
287
- .returns(3.00002)
288
- assert_equal(3000, browser_monitoring_queue_time,
289
- 'should return a rounded time')
290
- end
291
- end
292
-
293
245
  def test_footer_js_string_basic
294
- # mocking this because JRuby thinks that Time.now - Time.now
295
- # always takes at least 1ms
296
- self.expects(:browser_monitoring_app_time).returns(0)
246
+ freeze_time
297
247
  in_transaction do
298
248
  txn = NewRelic::Agent::Transaction.current
299
249
  user_attributes = {:user => "user", :account => "account", :product => "product"}
300
- txn.expects(:user_attributes).returns(user_attributes).at_least_once
301
- txn.expects(:queue_time).returns(0)
250
+ txn.stubs(:user_attributes).returns(user_attributes)
251
+ txn.stubs(:queue_time).returns(0)
252
+ txn.stubs(:start_time).returns(Time.now - 10)
302
253
  txn.name = 'most recent transaction'
303
254
 
304
- sample = stub_everything('transaction info',
305
- :start_time => Time.at(100),
306
- :guid => 'ABC',
307
- :transaction => txn,
308
- :include_guid? => true,
309
- :duration => 12.0,
310
- :token => '0123456789ABCDEF')
311
- NewRelic::Agent::TransactionInfo.set(sample)
255
+ NewRelic::Agent::TransactionState.get.reset(nil)
256
+ NewRelic::Agent::TransactionState.get.request_token = '0123456789ABCDEF'
257
+ NewRelic::Agent::TransactionState.get.request_guid = 'ABC'
312
258
 
313
259
  self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'most recent transaction').returns('most recent transaction')
314
260
  self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'user').returns('user')
@@ -316,7 +262,7 @@ var e=document.createElement("script");'
316
262
  self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'product').returns('product')
317
263
 
318
264
  value = footer_js_string(NewRelic::Agent.instance.beacon_configuration)
319
- assert_equal(%'<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push(["load",new Date().getTime()]);\nvar e=document.createElement("script");\ne.type="text/javascript";\ne.src=(("http:"===document.location.protocol)?"http:":"https:") + "//" +\n "this_is_my_file";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\nNREUMQ.push(["nrfj","beacon","browserKey","5, 6","most recent transaction",0,0,new Date().getTime(),"ABC","0123456789ABCDEF","user","account","product"]);</script>', value, "should return the javascript given some default values")
265
+ assert_equal(%'<script type="text/javascript">if (typeof NREUMQ !== "undefined") { if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push(["load",new Date().getTime()]);\nvar e=document.createElement("script");\ne.type="text/javascript";\ne.src=(("http:"===document.location.protocol)?"http:":"https:") + "//" +\n "this_is_my_file";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\nNREUMQ.push(["nrfj","beacon","browserKey","5, 6","most recent transaction",0,10000,new Date().getTime(),"ABC","0123456789ABCDEF","user","account","product"]);}</script>', value, "should return the javascript given some default values")
320
266
  end
321
267
  end
322
268
 
@@ -355,6 +301,17 @@ var e=document.createElement("script");'
355
301
  assert_equal('YCJrZXV2fih5Y25vaCFtZSR2a2ZkZSp/aXV1YyNsZHZ3cSl6YmluZCJsYiV1amllZit4aHl2YiRtZ3d4cCp7ZWhiZyNrYyZ0ZWhmZyx5ZHp3ZSVuZnh5cyt8ZGRhZiRqYCd7ZGtnYC11Z3twZCZvaXl6cix9aGdgYSVpYSh6Z2pgYSF2Znxx', output, "should output obfuscated text")
356
302
  end
357
303
 
304
+ def test_obfuscate_utf8
305
+ text = "foooooééoooo - blah"
306
+ key = (1..40).to_a
307
+ NewRelic::Agent.instance.beacon_configuration.expects(:license_bytes).returns(key).at_least_once
308
+ output = obfuscate(NewRelic::Agent.instance.beacon_configuration, text)
309
+ assert_equal('Z21sa2ppxKHKo2RjYm4iLiRnamZg', output, "should output obfuscated text")
310
+
311
+ unoutput = obfuscate(NewRelic::Agent.instance.beacon_configuration, Base64.decode64(output))
312
+ assert_equal Base64.encode64(text).gsub("\n", ''), unoutput
313
+ end
314
+
358
315
  def test_no_mobile_response_header_if_no_mobile_request_header_given
359
316
  request = Rack::Request.new({})
360
317
  response = Rack::Response.new
@@ -390,7 +347,7 @@ var e=document.createElement("script");'
390
347
  response = mobile_transaction
391
348
  txn_name = obfuscate(NewRelic::Agent.instance.beacon_configuration,
392
349
  browser_monitoring_transaction_name)
393
- expected_payload = %|["5, 6","#{txn_name}",#{browser_monitoring_queue_time},#{browser_monitoring_app_time}]|
350
+ expected_payload = %|["5, 6","#{txn_name}",#{current_timings.queue_time_in_millis},#{current_timings.app_time_in_millis}]|
394
351
 
395
352
  assert_equal expected_payload, response['X-NewRelic-App-Server-Metrics'].strip
396
353
  end
@@ -410,10 +367,8 @@ var e=document.createElement("script");'
410
367
  response = Rack::Response.new
411
368
  txn = NewRelic::Agent::Transaction.new
412
369
  txn.name = 'a transaction name'
413
- txn_data = OpenStruct.new(:transaction => txn,
414
- :start_time => 5,
415
- :force_persist_sample? => false)
416
- NewRelic::Agent::TransactionInfo.set(txn_data)
370
+ txn.start_time = Time.at(5)
371
+ NewRelic::Agent::TransactionState.get.transaction = txn
417
372
  NewRelic::Agent::BrowserMonitoring.insert_mobile_response_header(request, response)
418
373
  response
419
374
  end