newrelic_rpm 6.9.0.363 → 6.12.0.367

Sign up to get free protection for your applications and to get access to all the features.
Files changed (289) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +32 -2
  4. data/CHANGELOG.md +172 -10
  5. data/CODE_OF_CONDUCT.md +46 -0
  6. data/CONTRIBUTING.md +56 -12
  7. data/Gemfile +6 -2
  8. data/LICENSE +208 -38
  9. data/README.md +61 -89
  10. data/Rakefile +2 -0
  11. data/THIRD_PARTY_NOTICES.md +213 -0
  12. data/bin/nrdebug +1 -1
  13. data/init.rb +1 -1
  14. data/install.rb +1 -1
  15. data/lib/new_relic/agent.rb +15 -5
  16. data/lib/new_relic/agent/adaptive_sampler.rb +1 -1
  17. data/lib/new_relic/agent/agent.rb +11 -6
  18. data/lib/new_relic/agent/agent_logger.rb +1 -1
  19. data/lib/new_relic/agent/attribute_filter.rb +1 -1
  20. data/lib/new_relic/agent/attribute_processing.rb +1 -1
  21. data/lib/new_relic/agent/attributes.rb +3 -1
  22. data/lib/new_relic/agent/audit_logger.rb +1 -1
  23. data/lib/new_relic/agent/autostart.rb +1 -1
  24. data/lib/new_relic/agent/chained_call.rb +1 -1
  25. data/lib/new_relic/agent/commands/agent_command.rb +1 -1
  26. data/lib/new_relic/agent/commands/agent_command_router.rb +1 -1
  27. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
  28. data/lib/new_relic/agent/configuration.rb +1 -1
  29. data/lib/new_relic/agent/configuration/default_source.rb +28 -1
  30. data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -1
  31. data/lib/new_relic/agent/configuration/environment_source.rb +1 -1
  32. data/lib/new_relic/agent/configuration/event_harvest_config.rb +1 -1
  33. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -1
  34. data/lib/new_relic/agent/configuration/manager.rb +1 -1
  35. data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
  36. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
  37. data/lib/new_relic/agent/configuration/security_policy_source.rb +1 -1
  38. data/lib/new_relic/agent/configuration/server_source.rb +1 -1
  39. data/lib/new_relic/agent/configuration/yaml_source.rb +1 -1
  40. data/lib/new_relic/agent/connect/request_builder.rb +1 -1
  41. data/lib/new_relic/agent/connect/response_handler.rb +1 -1
  42. data/lib/new_relic/agent/custom_event_aggregator.rb +1 -1
  43. data/lib/new_relic/agent/database.rb +1 -1
  44. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
  45. data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
  46. data/lib/new_relic/agent/database/obfuscator.rb +1 -1
  47. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
  48. data/lib/new_relic/agent/datastores.rb +1 -1
  49. data/lib/new_relic/agent/datastores/metric_helper.rb +1 -1
  50. data/lib/new_relic/agent/datastores/mongo.rb +2 -2
  51. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +1 -1
  52. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
  53. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +1 -1
  54. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +1 -1
  55. data/lib/new_relic/agent/datastores/redis.rb +1 -1
  56. data/lib/new_relic/agent/deprecator.rb +1 -1
  57. data/lib/new_relic/agent/distributed_tracing.rb +1 -1
  58. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +3 -2
  59. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +1 -1
  60. data/lib/new_relic/agent/distributed_tracing/{distributed_trace_intrinsics.rb → distributed_trace_attributes.rb} +9 -5
  61. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +1 -1
  62. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +3 -4
  63. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +1 -1
  64. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +1 -1
  65. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +2 -2
  66. data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
  67. data/lib/new_relic/agent/error_collector.rb +31 -12
  68. data/lib/new_relic/agent/error_event_aggregator.rb +5 -5
  69. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -1
  70. data/lib/new_relic/agent/event_aggregator.rb +1 -1
  71. data/lib/new_relic/agent/event_buffer.rb +1 -1
  72. data/lib/new_relic/agent/event_listener.rb +1 -1
  73. data/lib/new_relic/agent/event_loop.rb +1 -1
  74. data/lib/new_relic/agent/external.rb +1 -1
  75. data/lib/new_relic/agent/guid_generator.rb +1 -1
  76. data/lib/new_relic/agent/harvester.rb +1 -1
  77. data/lib/new_relic/agent/heap.rb +1 -1
  78. data/lib/new_relic/agent/hostname.rb +8 -2
  79. data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
  80. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +25 -20
  81. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +29 -14
  82. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +18 -22
  83. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +11 -12
  84. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +17 -5
  85. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +5 -7
  86. data/lib/new_relic/agent/http_clients/uri_util.rb +4 -3
  87. data/lib/new_relic/agent/instrumentation.rb +1 -1
  88. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +5 -6
  89. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -1
  90. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +12 -3
  91. data/lib/new_relic/agent/instrumentation/active_job.rb +1 -1
  92. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  93. data/lib/new_relic/agent/instrumentation/active_record.rb +85 -38
  94. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +82 -24
  95. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +1 -1
  96. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +92 -34
  97. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +8 -3
  98. data/lib/new_relic/agent/instrumentation/active_storage.rb +1 -1
  99. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +9 -5
  100. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +24 -8
  101. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  102. data/lib/new_relic/agent/instrumentation/bunny.rb +114 -51
  103. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -1
  104. data/lib/new_relic/agent/instrumentation/curb.rb +92 -27
  105. data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -2
  106. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +61 -25
  107. data/lib/new_relic/agent/instrumentation/excon.rb +1 -1
  108. data/lib/new_relic/agent/instrumentation/excon/connection.rb +7 -4
  109. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -2
  110. data/lib/new_relic/agent/instrumentation/grape.rb +1 -1
  111. data/lib/new_relic/agent/instrumentation/http.rb +6 -3
  112. data/lib/new_relic/agent/instrumentation/httpclient.rb +5 -3
  113. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
  114. data/lib/new_relic/agent/instrumentation/memcache.rb +4 -2
  115. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +7 -3
  116. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  117. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  118. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +12 -4
  119. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +9 -7
  120. data/lib/new_relic/agent/instrumentation/mongo.rb +10 -4
  121. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +36 -3
  122. data/lib/new_relic/agent/instrumentation/net.rb +59 -22
  123. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +26 -2
  124. data/lib/new_relic/agent/instrumentation/padrino.rb +40 -16
  125. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
  126. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
  127. data/lib/new_relic/agent/instrumentation/rack.rb +36 -13
  128. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +1 -1
  129. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  130. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
  131. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
  132. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +1 -1
  133. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +1 -1
  134. data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +1 -1
  135. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +1 -1
  136. data/lib/new_relic/agent/instrumentation/rake.rb +54 -20
  137. data/lib/new_relic/agent/instrumentation/redis.rb +141 -56
  138. data/lib/new_relic/agent/instrumentation/resque.rb +1 -1
  139. data/lib/new_relic/agent/instrumentation/sequel.rb +1 -1
  140. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
  141. data/lib/new_relic/agent/instrumentation/sidekiq.rb +48 -24
  142. data/lib/new_relic/agent/instrumentation/sinatra.rb +62 -23
  143. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
  144. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
  145. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  146. data/lib/new_relic/agent/instrumentation/typhoeus.rb +23 -6
  147. data/lib/new_relic/agent/internal_agent_error.rb +1 -1
  148. data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
  149. data/lib/new_relic/agent/log_once.rb +1 -1
  150. data/lib/new_relic/agent/logging.rb +2 -2
  151. data/lib/new_relic/agent/memory_logger.rb +1 -1
  152. data/lib/new_relic/agent/messaging.rb +1 -1
  153. data/lib/new_relic/agent/method_tracer.rb +16 -5
  154. data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
  155. data/lib/new_relic/agent/monitors.rb +1 -1
  156. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +1 -1
  157. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +1 -1
  158. data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +1 -1
  159. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +1 -1
  160. data/lib/new_relic/agent/new_relic_service.rb +1 -2
  161. data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
  162. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -1
  163. data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
  164. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -1
  165. data/lib/new_relic/agent/noticible_error.rb +22 -0
  166. data/lib/new_relic/agent/null_logger.rb +1 -1
  167. data/lib/new_relic/agent/obfuscator.rb +1 -1
  168. data/lib/new_relic/agent/parameter_filtering.rb +1 -1
  169. data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
  170. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  171. data/lib/new_relic/agent/pipe_service.rb +1 -1
  172. data/lib/new_relic/agent/prepend_supportability.rb +1 -1
  173. data/lib/new_relic/agent/priority_sampled_buffer.rb +8 -5
  174. data/lib/new_relic/agent/range_extensions.rb +1 -1
  175. data/lib/new_relic/agent/rules_engine.rb +1 -1
  176. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +1 -1
  177. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
  178. data/lib/new_relic/agent/sampler.rb +1 -1
  179. data/lib/new_relic/agent/sampler_collection.rb +1 -1
  180. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  181. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -1
  182. data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
  183. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  184. data/lib/new_relic/agent/samplers/vm_sampler.rb +1 -1
  185. data/lib/new_relic/agent/span_event_aggregator.rb +1 -1
  186. data/lib/new_relic/agent/span_event_primitive.rb +71 -37
  187. data/lib/new_relic/agent/sql_sampler.rb +4 -4
  188. data/lib/new_relic/agent/stats.rb +1 -1
  189. data/lib/new_relic/agent/stats_engine.rb +1 -1
  190. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  191. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  192. data/lib/new_relic/agent/supported_versions.rb +1 -1
  193. data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -1
  194. data/lib/new_relic/agent/system_info.rb +13 -4
  195. data/lib/new_relic/agent/threading/agent_thread.rb +1 -1
  196. data/lib/new_relic/agent/threading/backtrace_node.rb +1 -1
  197. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
  198. data/lib/new_relic/agent/threading/thread_profile.rb +1 -1
  199. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
  200. data/lib/new_relic/agent/tracer.rb +31 -16
  201. data/lib/new_relic/agent/transaction.rb +67 -46
  202. data/lib/new_relic/agent/transaction/abstract_segment.rb +29 -2
  203. data/lib/new_relic/agent/transaction/datastore_segment.rb +1 -1
  204. data/lib/new_relic/agent/transaction/distributed_tracer.rb +3 -3
  205. data/lib/new_relic/agent/transaction/distributed_tracing.rb +2 -2
  206. data/lib/new_relic/agent/transaction/external_request_segment.rb +26 -10
  207. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -1
  208. data/lib/new_relic/agent/transaction/request_attributes.rb +1 -1
  209. data/lib/new_relic/agent/transaction/segment.rb +18 -2
  210. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
  211. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  212. data/lib/new_relic/agent/transaction/trace.rb +1 -1
  213. data/lib/new_relic/agent/transaction/trace_builder.rb +1 -1
  214. data/lib/new_relic/agent/transaction/trace_context.rb +1 -1
  215. data/lib/new_relic/agent/transaction/trace_node.rb +1 -1
  216. data/lib/new_relic/agent/transaction/tracing.rb +1 -1
  217. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
  218. data/lib/new_relic/agent/transaction_error_primitive.rb +8 -6
  219. data/lib/new_relic/agent/transaction_event_aggregator.rb +1 -1
  220. data/lib/new_relic/agent/transaction_event_primitive.rb +3 -3
  221. data/lib/new_relic/agent/transaction_event_recorder.rb +1 -1
  222. data/lib/new_relic/agent/transaction_metrics.rb +1 -1
  223. data/lib/new_relic/agent/transaction_sampler.rb +1 -1
  224. data/lib/new_relic/agent/transaction_time_aggregator.rb +1 -1
  225. data/lib/new_relic/agent/utilization/aws.rb +1 -1
  226. data/lib/new_relic/agent/utilization/azure.rb +1 -1
  227. data/lib/new_relic/agent/utilization/gcp.rb +1 -1
  228. data/lib/new_relic/agent/utilization/pcf.rb +1 -1
  229. data/lib/new_relic/agent/utilization/vendor.rb +1 -1
  230. data/lib/new_relic/agent/utilization_data.rb +1 -1
  231. data/lib/new_relic/agent/vm.rb +1 -1
  232. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
  233. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  234. data/lib/new_relic/agent/vm/mri_vm.rb +1 -1
  235. data/lib/new_relic/agent/vm/snapshot.rb +1 -1
  236. data/lib/new_relic/agent/worker_loop.rb +1 -1
  237. data/lib/new_relic/cli/command.rb +1 -1
  238. data/lib/new_relic/cli/commands/deployments.rb +1 -1
  239. data/lib/new_relic/cli/commands/install.rb +4 -3
  240. data/lib/new_relic/coerce.rb +1 -1
  241. data/lib/new_relic/collection_helper.rb +1 -1
  242. data/lib/new_relic/constants.rb +5 -1
  243. data/lib/new_relic/control.rb +1 -1
  244. data/lib/new_relic/control/class_methods.rb +1 -1
  245. data/lib/new_relic/control/frameworks.rb +1 -1
  246. data/lib/new_relic/control/frameworks/external.rb +1 -1
  247. data/lib/new_relic/control/frameworks/merb.rb +1 -1
  248. data/lib/new_relic/control/frameworks/rails.rb +1 -1
  249. data/lib/new_relic/control/frameworks/rails3.rb +1 -1
  250. data/lib/new_relic/control/frameworks/rails4.rb +1 -1
  251. data/lib/new_relic/control/frameworks/rails_notifications.rb +1 -1
  252. data/lib/new_relic/control/frameworks/ruby.rb +1 -1
  253. data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
  254. data/lib/new_relic/control/instance_methods.rb +1 -1
  255. data/lib/new_relic/control/instrumentation.rb +1 -1
  256. data/lib/new_relic/control/server_methods.rb +1 -1
  257. data/lib/new_relic/delayed_job_injection.rb +1 -1
  258. data/lib/new_relic/dependency_detection.rb +1 -1
  259. data/lib/new_relic/environment_report.rb +6 -2
  260. data/lib/new_relic/helper.rb +1 -1
  261. data/lib/new_relic/language_support.rb +1 -1
  262. data/lib/new_relic/latest_changes.rb +2 -2
  263. data/lib/new_relic/local_environment.rb +1 -1
  264. data/lib/new_relic/metric_data.rb +1 -1
  265. data/lib/new_relic/metric_spec.rb +1 -1
  266. data/lib/new_relic/metrics.rb +1 -1
  267. data/lib/new_relic/noticed_error.rb +29 -10
  268. data/lib/new_relic/rack.rb +1 -1
  269. data/lib/new_relic/rack/agent_hooks.rb +1 -1
  270. data/lib/new_relic/rack/agent_middleware.rb +1 -1
  271. data/lib/new_relic/rack/browser_monitoring.rb +3 -2
  272. data/lib/new_relic/recipes.rb +1 -1
  273. data/lib/new_relic/recipes/capistrano3.rb +1 -1
  274. data/lib/new_relic/recipes/capistrano_legacy.rb +1 -1
  275. data/lib/new_relic/supportability_helper.rb +1 -1
  276. data/lib/new_relic/version.rb +2 -2
  277. data/lib/newrelic_rpm.rb +1 -1
  278. data/lib/sequel/extensions/newrelic_instrumentation.rb +1 -1
  279. data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
  280. data/lib/tasks/all.rb +1 -1
  281. data/lib/tasks/multiverse.rb +26 -1
  282. data/lib/tasks/newrelic.rb +1 -1
  283. data/lib/tasks/tests.rake +1 -1
  284. data/newrelic_rpm.gemspec +11 -9
  285. data/recipes/newrelic.rb +1 -1
  286. data/test/agent_helper.rb +231 -70
  287. metadata +18 -15
  288. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
  289. data/true +0 -0
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  # @api public
6
6
  module NewRelic
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  require 'new_relic/agent/event_listener'
6
6
  require 'new_relic/rack/agent_middleware'
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  require 'new_relic/agent/tracer'
6
6
  require 'new_relic/agent/instrumentation/controller_instrumentation'
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  require 'rack'
6
6
  require 'new_relic/rack/agent_middleware'
@@ -37,7 +37,8 @@ module NewRelic::Rack
37
37
  if (js_to_inject != "") && should_instrument?(env, status, headers)
38
38
  response_string = autoinstrument_source(response, headers, js_to_inject)
39
39
  if headers.key?(CONTENT_LENGTH)
40
- headers[CONTENT_LENGTH] = response_string.size.to_s
40
+ content_length = response_string ? response_string.bytesize : 0
41
+ headers[CONTENT_LENGTH] = content_length.to_s
41
42
  end
42
43
 
43
44
  env[ALREADY_INSTRUMENTED_KEY] = true
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  # When installed as a plugin, this is loaded automatically.
6
6
  #
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  require 'capistrano/framework'
6
6
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  make_notify_task = Proc.new do
6
6
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  module NewRelic
6
6
  module SupportabilityHelper
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
  # encoding: utf-8
3
3
  # This file is distributed under New Relic's license terms.
4
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
5
5
 
6
6
 
7
7
  module NewRelic
@@ -11,7 +11,7 @@ module NewRelic
11
11
  end
12
12
 
13
13
  MAJOR = 6
14
- MINOR = 9
14
+ MINOR = 12
15
15
  TINY = 0
16
16
 
17
17
  begin
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  # == New Relic Initialization
6
6
  #
@@ -1,7 +1,7 @@
1
1
  # -*- ruby -*-
2
2
  # encoding: utf-8
3
3
  # This file is distributed under New Relic's license terms.
4
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
5
5
 
6
6
  require 'sequel' unless defined?( Sequel )
7
7
  require 'newrelic_rpm' unless defined?( NewRelic )
@@ -1,7 +1,7 @@
1
1
  # -*- ruby -*-
2
2
  # encoding: utf-8
3
3
  # This file is distributed under New Relic's license terms.
4
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
5
5
 
6
6
  require 'sequel' unless defined?( Sequel )
7
7
  require 'newrelic_rpm' unless defined?( NewRelic )
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  # This is required to load in task definitions from merb
6
6
  Dir.glob(File.join(File.dirname(__FILE__),'*.rake')) do |file|
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
  #
5
5
  # Rake task for running Ruby agent multiverse tests. This file may be required
6
6
  # from third party gems. It is also used by the agent itself to run multiverse.
@@ -43,11 +43,36 @@ namespace :test do
43
43
 
44
44
  namespace :multiverse do
45
45
 
46
+ def remove_local_multiverse_databases
47
+ list_databases_command = %{echo "show databases" | mysql -u root}
48
+ databases = `#{list_databases_command}`.chomp!.split("\n").select{|s| s =~ /multiverse/}
49
+ databases.each do |database|
50
+ puts "Dropping #{database}"
51
+ `echo "drop database #{database}" | mysql -u root`
52
+ end
53
+ rescue => error
54
+ puts "ERROR: Cannot get MySQL databases..."
55
+ puts error.message
56
+ end
57
+
58
+ def remove_generated_gemfiles
59
+ file_path = File.expand_path "test/multiverse/suites"
60
+ Dir.glob(File.join file_path, "**", "Gemfile*").each do |fn|
61
+ puts "Removing #{fn.gsub(file_path,'.../suites')}"
62
+ FileUtils.rm fn
63
+ end
64
+ end
65
+
46
66
  task :env do
47
67
  # ENV['SUITES_DIRECTORY'] = File.expand_path('../../test/multiverse/suites', __FILE__)
48
68
  require File.expand_path('../../../test/multiverse/lib/multiverse', __FILE__)
49
69
  end
50
70
 
71
+ task :clobber do
72
+ remove_local_multiverse_databases
73
+ remove_generated_gemfiles
74
+ end
75
+
51
76
  desc "Clean cached gemfiles from Bundler.bundle_path"
52
77
  task :clean_gemfile_cache do
53
78
  glob = File.expand_path 'multiverse-cache/Gemfile.*.lock', Bundler.bundle_path
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
  #
5
5
  # If you are looking to instrument rake tasks in a Rails environment, but the
6
6
  # task doesn't depend on :environment, this task may be included to ensure that
@@ -33,7 +33,7 @@ if defined? Rake::TestTask
33
33
 
34
34
  t.libs << "#{agent_home}/test"
35
35
  t.libs << "#{agent_home}/lib"
36
- t.pattern = file_pattern
36
+ t.pattern = Array(file_pattern)
37
37
  t.verbose = true
38
38
  end
39
39
 
@@ -10,16 +10,16 @@ Gem::Specification.new do |s|
10
10
  s.version = NewRelic::VERSION::STRING
11
11
  s.required_ruby_version = '>= 2.0.0'
12
12
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
13
- s.authors = [ "Chris Pine", "Rachel Klein", "Tanna McClure", "Michael Lang" ]
13
+ s.authors = [ "Rachel Klein", "Tanna McClure", "Michael Lang" ]
14
14
  s.date = Time.now.strftime('%Y-%m-%d')
15
- s.licenses = ['New Relic']
15
+ s.licenses = ['Apache-2.0']
16
16
  s.description = <<-EOS
17
17
  New Relic is a performance management system, developed by New Relic,
18
18
  Inc (http://www.newrelic.com). New Relic provides you with deep
19
19
  information about the performance of your web application as it runs
20
- in production. The New Relic Ruby Agent is dual-purposed as a either a
20
+ in production. The New Relic Ruby agent is dual-purposed as a either a
21
21
  Gem or plugin, hosted on
22
- https://github.com/newrelic/rpm/
22
+ https://github.com/newrelic/newrelic-ruby-agent/
23
23
  EOS
24
24
  s.email = "support@newrelic.com"
25
25
  s.executables = [ "mongrel_rpm", "newrelic_cmd", "newrelic", "nrdebug" ]
@@ -28,17 +28,19 @@ EOS
28
28
  "LICENSE",
29
29
  "README.md",
30
30
  "CONTRIBUTING.md",
31
+ "CODE_OF_CONDUCT.md",
31
32
  "newrelic.yml"
32
33
  ]
33
34
 
34
35
  s.metadata = {
35
- 'bug_tracker_uri' => 'https://support.newrelic.com/',
36
- 'changelog_uri' => 'https://github.com/newrelic/rpm/blob/master/CHANGELOG.md',
36
+ 'bug_tracker_uri' => 'https://github.com/newrelic/newrelic-ruby-agent/issues',
37
+ 'changelog_uri' => 'https://github.com/newrelic/newrelic-ruby-agent/blob/main/CHANGELOG.md',
37
38
  'documentation_uri' => 'https://docs.newrelic.com/docs/agents/ruby-agent',
38
- 'source_code_uri' => 'https://github.com/newrelic/rpm'
39
+ 'source_code_uri' => 'https://github.com/newrelic/newrelic-ruby-agent',
40
+ "homepage_uri" => "https://newrelic.com/ruby",
39
41
  }
40
42
 
41
- file_list = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/(?!agent_helper.rb)}) }
43
+ file_list = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|infinite_tracing)/(?!agent_helper.rb)}) }
42
44
  build_file_path = 'lib/new_relic/build.rb'
43
45
  file_list << build_file_path if File.exist?(build_file_path)
44
46
  s.files = file_list
@@ -51,7 +53,7 @@ EOS
51
53
  s.add_development_dependency 'rake', '12.3.3'
52
54
  s.add_development_dependency 'rb-inotify', '0.9.10' # locked to support < Ruby 2.3 (and listen 3.0.8)
53
55
  s.add_development_dependency 'listen', '3.0.8' # locked to support < Ruby 2.3
54
- s.add_development_dependency 'minitest', '~> 4.7.5'
56
+ s.add_development_dependency 'minitest', '4.7.5'
55
57
  s.add_development_dependency 'mocha', '~> 1.9.0'
56
58
  s.add_development_dependency 'yard'
57
59
  s.add_development_dependency 'pry-nav', '~> 0.3.0'
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  # The capistrano recipes in plugins are automatically
6
6
  # loaded from here. From gems, they are available from
@@ -1,30 +1,61 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  # These helpers should not have any gem dependencies except on newrelic_rpm
6
6
  # itself, and should be usable from within any multiverse suite.
7
7
 
8
8
  require 'json'
9
+ require 'net/http'
10
+ begin
11
+ require 'net/http/status'
12
+ rescue LoadError
13
+ # NOP -- Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
14
+ end
15
+
16
+ module MiniTest
17
+ module Assertions
18
+ # The failure message is backwards. This patch reverses the message
19
+ # Note: passing +msg+ caused two failure messages to be shown on failure
20
+ # and was more confusing than patching here.
21
+ def assert_match matcher, obj, msg = nil
22
+ msg = message(msg) { "Expected #{mu_pp obj} to match #{mu_pp matcher}" }
23
+ assert_respond_to matcher, :"=~"
24
+ matcher = Regexp.new Regexp.escape matcher if String === matcher
25
+ assert matcher =~ obj, msg
26
+ end
27
+ end
28
+ end
9
29
 
10
30
  class ArrayLogDevice
11
- def initialize( array=[] )
31
+ def initialize array=[]
12
32
  @array = array
13
33
  end
14
34
  attr_reader :array
15
35
 
16
- def write( message )
36
+ def write message
17
37
  @array << message
18
38
  end
19
39
 
20
40
  def close; end
21
41
  end
22
42
 
23
- def assert_between(floor, ceiling, value, message="expected #{floor} <= #{value} <= #{ceiling}")
43
+ def fake_guid length=16
44
+ NewRelic::Agent::GuidGenerator.generate_guid length
45
+ end
46
+
47
+ def assert_match matcher, obj, msg = nil
48
+ msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
49
+ assert_respond_to matcher, :"=~"
50
+ matcher = Regexp.new Regexp.escape matcher if String === matcher
51
+ assert matcher =~ obj, msg
52
+ end
53
+
54
+ def assert_between floor, ceiling, value, message="expected #{floor} <= #{value} <= #{ceiling}"
24
55
  assert((floor <= value && value <= ceiling), message)
25
56
  end
26
57
 
27
- def assert_in_delta(expected, actual, delta)
58
+ def assert_in_delta expected, actual, delta
28
59
  assert_between((expected - delta), (expected + delta), actual)
29
60
  end
30
61
 
@@ -36,7 +67,7 @@ def reset_error_traces!
36
67
  NewRelic::Agent.instance.error_collector.error_trace_aggregator.reset!
37
68
  end
38
69
 
39
- def assert_has_traced_error(error_class)
70
+ def assert_has_traced_error error_class
40
71
  errors = harvest_error_traces!
41
72
  assert \
42
73
  errors.find {|e| e.exception_class_name == error_class.name} != nil, \
@@ -55,6 +86,14 @@ def last_transaction_event
55
86
  harvest_transaction_events!.last.last
56
87
  end
57
88
 
89
+ def harvest_span_events!
90
+ NewRelic::Agent.instance.span_event_aggregator.harvest!
91
+ end
92
+
93
+ def last_span_event
94
+ harvest_span_events!.last.last
95
+ end
96
+
58
97
  def harvest_error_events!
59
98
  NewRelic::Agent.instance.error_collector.error_event_aggregator.harvest!
60
99
  end
@@ -63,38 +102,38 @@ def last_error_event
63
102
  harvest_error_events!.last.last
64
103
  end
65
104
 
66
- unless defined?( assert_block )
67
- def assert_block(*msgs)
105
+ unless defined? assert_block
106
+ def assert_block *msgs
68
107
  assert yield, *msgs
69
108
  end
70
109
  end
71
110
 
72
- unless defined?( assert_includes )
73
- def assert_includes( collection, member, msg=nil )
111
+ unless defined? assert_includes
112
+ def assert_includes collection, member, msg=nil
74
113
  msg = "Expected #{collection.inspect} to include #{member.inspect}"
75
114
  assert_block( msg ) { collection.include?(member) }
76
115
  end
77
116
  end
78
117
 
79
- unless defined?( assert_not_includes )
80
- def assert_not_includes( collection, member, msg=nil )
118
+ unless defined? assert_not_includes
119
+ def assert_not_includes collection, member, msg=nil
81
120
  msg = "Expected #{collection.inspect} not to include #{member.inspect}"
82
121
  assert !collection.include?(member), msg
83
122
  end
84
123
  end
85
124
 
86
- unless defined?( assert_empty )
87
- def assert_empty(collection, msg=nil)
125
+ unless defined? assert_empty
126
+ def assert_empty collection, msg=nil
88
127
  assert collection.empty?, msg
89
128
  end
90
129
  end
91
130
 
92
- def assert_equal_unordered(left, right)
131
+ def assert_equal_unordered left, right
93
132
  assert_equal(left.length, right.length, "Lengths don't match. #{left.length} != #{right.length}")
94
133
  left.each { |element| assert_includes(right, element) }
95
134
  end
96
135
 
97
- def assert_audit_log_contains(audit_log_contents, needle)
136
+ def assert_audit_log_contains audit_log_contents, needle
98
137
  # Original request bodies dumped to the log have symbol keys, but once
99
138
  # they go through a dump/load, they're strings again, so we strip
100
139
  # double-quotes and colons from the log, and the strings we searching for.
@@ -112,7 +151,7 @@ end
112
151
  # orderings of the key/value pairs in Hashes that were embedded in the request
113
152
  # body). So, this method traverses an object graph and only makes assertions
114
153
  # about the terminal (non-Array-or-Hash) nodes therein.
115
- def assert_audit_log_contains_object(audit_log_contents, o, format = :json)
154
+ def assert_audit_log_contains_object audit_log_contents, o, format = :json
116
155
  case o
117
156
  when Hash
118
157
  o.each do |k,v|
@@ -130,12 +169,12 @@ def assert_audit_log_contains_object(audit_log_contents, o, format = :json)
130
169
  end
131
170
  end
132
171
 
133
- def compare_metrics(expected, actual)
172
+ def compare_metrics expected, actual
134
173
  actual.delete_if {|a| a.include?('GC/Transaction/') }
135
174
  assert_equal(expected.to_a.sort, actual.to_a.sort, "extra: #{(actual - expected).to_a.inspect}; missing: #{(expected - actual).to_a.inspect}")
136
175
  end
137
176
 
138
- def metric_spec_from_specish(specish)
177
+ def metric_spec_from_specish specish
139
178
  spec = case specish
140
179
  when String then NewRelic::MetricSpec.new(specish)
141
180
  when Array then NewRelic::MetricSpec.new(*specish)
@@ -143,7 +182,7 @@ def metric_spec_from_specish(specish)
143
182
  spec
144
183
  end
145
184
 
146
- def _normalize_metric_expectations(expectations)
185
+ def _normalize_metric_expectations expectations
147
186
  case expectations
148
187
  when Array
149
188
  hash = {}
@@ -157,7 +196,7 @@ def _normalize_metric_expectations(expectations)
157
196
  end
158
197
  end
159
198
 
160
- def dump_stats(stats)
199
+ def dump_stats stats
161
200
  str = " Call count: #{stats.call_count}\n"
162
201
  str << " Total call time: #{stats.total_call_time}\n"
163
202
  str << " Total exclusive time: #{stats.total_exclusive_time}\n"
@@ -170,7 +209,7 @@ def dump_stats(stats)
170
209
  str
171
210
  end
172
211
 
173
- def assert_stats_has_values(stats, expected_spec, expected_attrs)
212
+ def assert_stats_has_values stats, expected_spec, expected_attrs
174
213
  expected_attrs.each do |attr, expected_value|
175
214
  actual_value = stats.send(attr)
176
215
  if attr == :call_count
@@ -183,7 +222,7 @@ def assert_stats_has_values(stats, expected_spec, expected_attrs)
183
222
  end
184
223
  end
185
224
 
186
- def assert_metrics_recorded(expected)
225
+ def assert_metrics_recorded expected
187
226
  expected = _normalize_metric_expectations(expected)
188
227
  expected.each do |specish, expected_attrs|
189
228
  expected_spec = metric_spec_from_specish(specish)
@@ -214,7 +253,7 @@ end
214
253
  # the :ignore_filter option. This will allow you to specify a Regex that
215
254
  # allowlists broad swathes of metric territory (e.g. 'Supportability/').
216
255
  #
217
- def assert_metrics_recorded_exclusive(expected, options={})
256
+ def assert_metrics_recorded_exclusive expected, options={}
218
257
  expected = _normalize_metric_expectations(expected)
219
258
  assert_metrics_recorded(expected)
220
259
 
@@ -252,7 +291,7 @@ def clear_metrics!
252
291
  NewRelic::Agent.instance.stats_engine.reset_for_test!
253
292
  end
254
293
 
255
- def assert_metrics_not_recorded(not_expected)
294
+ def assert_metrics_not_recorded not_expected
256
295
  not_expected = _normalize_metric_expectations(not_expected)
257
296
  found_but_not_expected = []
258
297
  not_expected.each do |specish, _|
@@ -266,7 +305,7 @@ end
266
305
 
267
306
  alias :refute_metrics_recorded :assert_metrics_not_recorded
268
307
 
269
- def assert_no_metrics_match(regex)
308
+ def assert_no_metrics_match regex
270
309
  matching_metrics = []
271
310
  NewRelic::Agent.instance.stats_engine.to_h.keys.map(&:to_s).each do |metric|
272
311
  matching_metrics << metric if metric.match regex
@@ -281,30 +320,30 @@ end
281
320
 
282
321
  alias :refute_metrics_match :assert_no_metrics_match
283
322
 
284
- def format_metric_spec_list(specs)
323
+ def format_metric_spec_list specs
285
324
  spec_strings = specs.map do |spec|
286
325
  "#{spec.name} (#{spec.scope.empty? ? '<unscoped>' : spec.scope})"
287
326
  end
288
327
  "[\n #{spec_strings.join(",\n ")}\n]"
289
328
  end
290
329
 
291
- def assert_truthy(expected, msg = nil)
330
+ def assert_truthy expected, msg=nil
292
331
  msg ||= "Expected #{expected.inspect} to be truthy"
293
332
  assert !!expected, msg
294
333
  end
295
334
 
296
- def assert_falsy(expected, msg = nil)
335
+ def assert_falsy expected, msg=nil
297
336
  msg ||= "Expected #{expected.inspect} to be falsy"
298
337
  assert !expected, msg
299
338
  end
300
339
 
301
- unless defined?( assert_false )
302
- def assert_false(expected)
340
+ unless defined? assert_false
341
+ def assert_false expected
303
342
  assert_equal false, expected
304
343
  end
305
344
  end
306
345
 
307
- unless defined?(refute)
346
+ unless defined? refute
308
347
  alias refute assert_false
309
348
  end
310
349
 
@@ -326,7 +365,7 @@ end
326
365
  # With a transaction name plus category:
327
366
  # in_transaction('foobar', :category => :controller) { ... }
328
367
  #
329
- def in_transaction(*args, &blk)
368
+ def in_transaction *args, &blk
330
369
  opts = (args.last && args.last.is_a?(Hash)) ? args.pop : {}
331
370
  category = (opts && opts.delete(:category)) || :other
332
371
 
@@ -360,30 +399,55 @@ end
360
399
  # that transaction to work with. The same arguements as provided to in_transaction
361
400
  # may be supplied.
362
401
  def with_segment *args, &blk
363
- in_transaction(*args) do |txn|
364
- yield txn.current_segment, txn
402
+ segment = nil
403
+ txn = in_transaction(*args) do |txn|
404
+ segment = txn.current_segment
405
+ yield segment, txn
406
+ end
407
+ [segment, txn]
408
+ end
409
+
410
+ # building error attributes on segments are deferred until it's time
411
+ # to publish/harvest them as spans, so for testing, we'll explicitly
412
+ # build 'em as appropriate so we can test 'em
413
+ def build_deferred_error_attributes segment
414
+ return unless segment.noticed_error
415
+ segment.noticed_error.build_error_attributes
416
+ end
417
+
418
+ def capture_segment_with_error
419
+ begin
420
+ segment_with_error = nil
421
+ with_segment do |segment|
422
+ segment_with_error = segment
423
+ raise "oops!"
424
+ end
425
+ rescue Exception => exception
426
+ assert segment_with_error, "expected to have a segment_with_error"
427
+ build_deferred_error_attributes segment_with_error
428
+ return segment_with_error, exception
365
429
  end
366
430
  end
367
431
 
368
- def stub_transaction_guid(guid)
432
+ def stub_transaction_guid guid
369
433
  NewRelic::Agent::Transaction.tl_current.instance_variable_set(:@guid, guid)
370
434
  end
371
435
 
372
436
  # Convenience wrapper around in_transaction that sets the category so that it
373
437
  # looks like we are in a web transaction
374
- def in_web_transaction(name='dummy')
438
+ def in_web_transaction name='dummy'
375
439
  in_transaction(name, :category => :controller, :request => stub(:path => '/')) do |txn|
376
440
  yield txn
377
441
  end
378
442
  end
379
443
 
380
- def in_background_transaction(name='silly')
444
+ def in_background_transaction name='silly'
381
445
  in_transaction(name, :category => :task) do |txn|
382
446
  yield txn
383
447
  end
384
448
  end
385
449
 
386
- def refute_contains_request_params(attributes)
450
+ def refute_contains_request_params attributes
387
451
  attributes.keys.each do |key|
388
452
  refute_match(/^request\.parameters\./, key.to_s)
389
453
  end
@@ -402,7 +466,7 @@ def last_transaction_trace_request_params
402
466
  end
403
467
  end
404
468
 
405
- def find_sql_trace(metric_name)
469
+ def find_sql_trace metric_name
406
470
  NewRelic::Agent.agent.sql_sampler.sql_traces.values.detect do |trace|
407
471
  trace.database_metric_name == metric_name
408
472
  end
@@ -412,7 +476,7 @@ def last_sql_trace
412
476
  NewRelic::Agent.agent.sql_sampler.sql_traces.values.last
413
477
  end
414
478
 
415
- def find_last_transaction_node(transaction_sample=nil)
479
+ def find_last_transaction_node transaction_sample=nil
416
480
  if transaction_sample
417
481
  root_node = transaction_sample.root_node
418
482
  else
@@ -425,7 +489,7 @@ def find_last_transaction_node(transaction_sample=nil)
425
489
  return last_node
426
490
  end
427
491
 
428
- def find_node_with_name(transaction_sample, name)
492
+ def find_node_with_name transaction_sample, name
429
493
  transaction_sample.root_node.each_node do |node|
430
494
  if node.metric_name == name
431
495
  return node
@@ -435,7 +499,7 @@ def find_node_with_name(transaction_sample, name)
435
499
  nil
436
500
  end
437
501
 
438
- def find_node_with_name_matching(transaction_sample, regex)
502
+ def find_node_with_name_matching transaction_sample, regex
439
503
  transaction_sample.root_node.each_node do |node|
440
504
  if node.metric_name.match regex
441
505
  return node
@@ -445,7 +509,7 @@ def find_node_with_name_matching(transaction_sample, regex)
445
509
  nil
446
510
  end
447
511
 
448
- def find_all_nodes_with_name_matching(transaction_sample, regexes)
512
+ def find_all_nodes_with_name_matching transaction_sample, regexes
449
513
  regexes = [regexes].flatten
450
514
  matching_nodes = []
451
515
 
@@ -460,7 +524,7 @@ def find_all_nodes_with_name_matching(transaction_sample, regexes)
460
524
  matching_nodes
461
525
  end
462
526
 
463
- def with_config(config_hash, at_start=true)
527
+ def with_config config_hash, at_start=true
464
528
  config = NewRelic::Agent::Configuration::DottedHash.new(config_hash, true)
465
529
  NewRelic::Agent.config.add_config_for_testing(config, at_start)
466
530
  NewRelic::Agent.instance.refresh_attribute_filter
@@ -479,13 +543,13 @@ def with_server_source config_hash, at_start=true
479
543
  end
480
544
  end
481
545
 
482
- def with_config_low_priority(config_hash)
546
+ def with_config_low_priority config_hash
483
547
  with_config(config_hash, false) do
484
548
  yield
485
549
  end
486
550
  end
487
551
 
488
- def with_transaction_renaming_rules(rule_specs)
552
+ def with_transaction_renaming_rules rule_specs
489
553
  original_engine = NewRelic::Agent.agent.instance_variable_get(:@transaction_rules)
490
554
  begin
491
555
  new_engine = NewRelic::Agent::RulesEngine.create_transaction_rules('transaction_name_rules' => rule_specs)
@@ -511,7 +575,7 @@ unless Time.respond_to?(:__original_now)
511
575
  end
512
576
  end
513
577
 
514
- def nr_freeze_time(now=Time.now)
578
+ def nr_freeze_time now=Time.now
515
579
  Time.__frozen_now = now
516
580
  end
517
581
 
@@ -519,11 +583,11 @@ def nr_unfreeze_time
519
583
  Time.__frozen_now = nil
520
584
  end
521
585
 
522
- def advance_time(seconds)
586
+ def advance_time seconds
523
587
  Time.__frozen_now = Time.now + seconds
524
588
  end
525
589
 
526
- def with_constant_defined(constant_symbol, implementation=Module.new)
590
+ def with_constant_defined constant_symbol, implementation=Module.new
527
591
  const_path = constant_path(constant_symbol.to_s)
528
592
 
529
593
  if const_path
@@ -543,7 +607,7 @@ def with_constant_defined(constant_symbol, implementation=Module.new)
543
607
  end
544
608
  end
545
609
 
546
- def constant_path(name, opts={})
610
+ def constant_path name, opts={}
547
611
  allow_partial = opts[:allow_partial]
548
612
  path = [Object]
549
613
  parts = name.gsub(/^::/, '').split('::')
@@ -556,13 +620,13 @@ def constant_path(name, opts={})
556
620
  path
557
621
  end
558
622
 
559
- def get_parent(constant_name)
623
+ def get_parent constant_name
560
624
  parent_name = constant_name.gsub(/::[^:]*$/, '')
561
625
  const_path = constant_path(parent_name)
562
626
  const_path ? const_path[-1] : nil
563
627
  end
564
628
 
565
- def undefine_constant(constant_symbol)
629
+ def undefine_constant constant_symbol
566
630
  const_str = constant_symbol.to_s
567
631
  parent = get_parent(const_str)
568
632
  const_name = const_str.gsub(/.*::/, '')
@@ -586,11 +650,11 @@ ensure
586
650
  NewRelic::Agent.logger = orig_logger
587
651
  end
588
652
 
589
- def create_agent_command(args = {})
653
+ def create_agent_command args={}
590
654
  NewRelic::Agent::Commands::AgentCommand.new([-1, { "name" => "command_name", "arguments" => args}])
591
655
  end
592
656
 
593
- def wait_for_backtrace_service_poll(opts={})
657
+ def wait_for_backtrace_service_poll opts={}
594
658
  defaults = {
595
659
  :timeout => 10.0,
596
660
  :service => NewRelic::Agent.agent.agent_command_router.backtrace_service,
@@ -616,7 +680,7 @@ def wait_for_backtrace_service_poll(opts={})
616
680
  end
617
681
  end
618
682
 
619
- def with_array_logger(level=:info)
683
+ def with_array_logger level=:info
620
684
  orig_logger = NewRelic::Agent.logger
621
685
  config = { :log_level => level }
622
686
  logdev = ArrayLogDevice.new
@@ -638,7 +702,7 @@ end
638
702
  # a core bug in the JVM implementation of Ruby. Root cause was not
639
703
  # discovered, but it was found that a combination of retrying and using
640
704
  # mutex lock around the update operation was the only consistently working
641
- # solution as the error continued to surface without the mutex and
705
+ # solution as the error continued to surface without the mutex and
642
706
  # retry alone wasn't enough, either.
643
707
  #
644
708
  # JRUBY: oraclejdk8 + jruby-9.2.6.0
@@ -651,7 +715,7 @@ class EnvUpdater
651
715
  @mutex = Mutex.new
652
716
  end
653
717
 
654
- # Will attempt the given block up to MAX_RETRIES before
718
+ # Will attempt the given block up to MAX_RETRIES before
655
719
  # surfacing the exception down the chain.
656
720
  def with_retry retry_limit=MAX_RETRIES
657
721
  retries ||= 0
@@ -703,19 +767,19 @@ class EnvUpdater
703
767
  ensure
704
768
  safe_restore(old_env)
705
769
  end
706
- end
770
+ end
707
771
 
708
772
  # must call instance here to ensure only one @mutex for all threads.
709
773
  instance
710
774
  end
711
775
 
712
- # Changes ENV settings to given and runs given block and restores ENV
776
+ # Changes ENV settings to given and runs given block and restores ENV
713
777
  # to original values before returning.
714
- def with_environment(env, &block)
778
+ def with_environment env, &block
715
779
  EnvUpdater.inject(env) { yield }
716
780
  end
717
781
 
718
- def with_argv(argv)
782
+ def with_argv argv
719
783
  old_argv = ARGV.dup
720
784
  ARGV.clear
721
785
  ARGV.concat(argv)
@@ -728,7 +792,7 @@ def with_argv(argv)
728
792
  end
729
793
  end
730
794
 
731
- def with_ignore_error_filter(filter, &blk)
795
+ def with_ignore_error_filter filter, &blk
732
796
  original_filter = NewRelic::Agent.ignore_error_filter
733
797
  NewRelic::Agent.ignore_error_filter(&filter)
734
798
 
@@ -737,7 +801,7 @@ ensure
737
801
  NewRelic::Agent::ErrorCollector.ignore_error_filter = original_filter
738
802
  end
739
803
 
740
- def json_dump_and_encode(object)
804
+ def json_dump_and_encode object
741
805
  Base64.encode64(::JSON.dump(object))
742
806
  end
743
807
 
@@ -745,7 +809,7 @@ def get_last_analytics_event
745
809
  NewRelic::Agent.agent.transaction_event_aggregator.harvest![1].last
746
810
  end
747
811
 
748
- def swap_instance_method(target, method_name, new_method_implementation, &blk)
812
+ def swap_instance_method target, method_name, new_method_implementation, &blk
749
813
  old_method_implementation = target.instance_method(method_name)
750
814
  target.send(:define_method, method_name, new_method_implementation)
751
815
  yield
@@ -760,7 +824,7 @@ def cross_agent_tests_dir
760
824
  File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'cross_agent_tests'))
761
825
  end
762
826
 
763
- def load_cross_agent_test(name)
827
+ def load_cross_agent_test name
764
828
  test_file_path = File.join(cross_agent_tests_dir, "#{name}.json")
765
829
  data = File.read(test_file_path)
766
830
  data.gsub!('callCount', 'call_count')
@@ -769,13 +833,13 @@ def load_cross_agent_test(name)
769
833
  data
770
834
  end
771
835
 
772
- def each_cross_agent_test(options)
836
+ def each_cross_agent_test options
773
837
  options = {:dir => nil, :pattern => "*"}.update(options)
774
838
  path = File.join [cross_agent_tests_dir, options[:dir], options[:pattern]].compact
775
839
  Dir.glob(path).each { |file| yield file}
776
840
  end
777
841
 
778
- def assert_event_attributes(event, test_name, expected_attributes, non_expected_attributes)
842
+ def assert_event_attributes event, test_name, expected_attributes, non_expected_attributes
779
843
  incorrect_attributes = []
780
844
 
781
845
  event_attrs = event[0]
@@ -799,11 +863,11 @@ def assert_event_attributes(event, test_name, expected_attributes, non_expected_
799
863
  assert(incorrect_attributes.empty?, msg)
800
864
 
801
865
  non_expected_attributes.each do |name|
802
- assert_nil(event_attrs[name], "Found value '#{event_attrs[name]}' for attribute '#{name}', but expected nothing in #{test_name}")
866
+ refute event_attrs[name], "Found value '#{event_attrs[name]}' for attribute '#{name}', but expected nothing in #{test_name}"
803
867
  end
804
868
  end
805
869
 
806
- def attributes_for(sample, type)
870
+ def attributes_for sample, type
807
871
  sample.attributes.instance_variable_get("@#{type}_attributes")
808
872
  end
809
873
 
@@ -815,3 +879,100 @@ def reset_buffers_and_caches
815
879
  NewRelic::Agent.drop_buffered_data
816
880
  uncache_trusted_account_key
817
881
  end
882
+
883
+ def message_for_status_code code
884
+ # Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
885
+ if defined?(Net::HTTP::STATUS_CODES)
886
+ return Net::HTTP::STATUS_CODES[code]
887
+ end
888
+
889
+ case code
890
+ when 200 then "OK"
891
+ when 404 then "Not Found"
892
+ when 403 then "Forbidden"
893
+ else "Unknown"
894
+ end
895
+ end
896
+
897
+ # wraps the given headers in a Net::HTTPResponse which has accompanying
898
+ # http status code associated with it.
899
+ # a "status_code" may be passed in the headers to alter the HTTP Status Code
900
+ # that is wrapped in the response.
901
+ def mock_http_response headers, wrap_it=true
902
+ status_code = (headers.delete("status_code") || 200).to_i
903
+ net_http_resp = Net::HTTPResponse.new(1.0, status_code, message_for_status_code(status_code))
904
+ headers.each do |key, value|
905
+ net_http_resp.add_field key.to_s, value
906
+ end
907
+ return net_http_resp unless wrap_it
908
+ NewRelic::Agent::HTTPClients::NetHTTPResponse.new(net_http_resp)
909
+ end
910
+
911
+ # +expected+ can be a string or regular expression
912
+ def assert_match_or_equal expected, value
913
+ if expected.is_a?(Regexp)
914
+ assert_match expected, value
915
+ else
916
+ assert_equal expected, value
917
+ end
918
+ end
919
+
920
+ # selects the last segment with a noticed_error and checks
921
+ # the expectations against it.
922
+ def assert_segment_noticed_error txn, segment_name, error_classes, error_message
923
+ error_segment = txn.segments.reverse.detect{|s| s.noticed_error}
924
+ assert error_segment, "Expected at least one segment with a noticed_error"
925
+
926
+ assert_match_or_equal segment_name, error_segment.name
927
+
928
+ noticed_error = error_segment.noticed_error
929
+
930
+ assert_match_or_equal error_classes, noticed_error.exception_class_name
931
+ assert_match_or_equal error_message, noticed_error.message
932
+ end
933
+
934
+ def assert_transaction_noticed_error txn, error_classes
935
+ refute_empty txn.exceptions, "Expected transaction to notice the error"
936
+ assert_match_or_equal error_classes, txn.exceptions.keys.first.class.name
937
+ end
938
+
939
+ def refute_transaction_noticed_error txn, error_class
940
+ error_segment = txn.segments.reverse.detect{|s| s.noticed_error}
941
+ assert error_segment, "Expected at least one segment with a noticed_error"
942
+ assert_empty txn.exceptions, "Expected transaction to NOT notice any segment errors"
943
+ end
944
+
945
+ def refute_raises *exp
946
+ msg = "#{exp.pop}.\n" if String === exp.last
947
+
948
+ begin
949
+ yield
950
+ rescue MiniTest::Skip => e
951
+ puts "SKIP REPORTS: #{e.inspect}"
952
+ return e if exp.include? MiniTest::Skip
953
+ raise e
954
+ rescue Exception => e
955
+ puts "EXCEPTION RAISED: #{e.inspect}\n#{e.backtrace}"
956
+ exp = exp.first if exp.size == 1
957
+ flunk msg || "unexpected exception raised: #{e}"
958
+ end
959
+ end
960
+
961
+ def assert_implements instance, method, *args
962
+ fail_message = "expected #{instance.class}##{method} method to be implemented"
963
+ refute_raises NotImplementedError, fail_message do
964
+ instance.send(method, *args)
965
+ end
966
+ end
967
+
968
+ def defer_testing_to_min_supported_rails test_file, min_rails_version, supports_jruby=true
969
+ if defined?(::Rails) &&
970
+ defined?(::Rails::VERSION::STRING) &&
971
+ (::Rails::VERSION::STRING.to_f >= min_rails_version) &&
972
+ (supports_jruby || !NewRelic::LanguageSupport.jruby?)
973
+
974
+ yield
975
+ else
976
+ puts "Skipping tests in #{test_file} because Rails >= #{min_rails_version} is unavailable"
977
+ end
978
+ end