newrelic_rpm 6.7.0.359 → 6.12.0.367

Sign up to get free protection for your applications and to get access to all the features.
Files changed (297) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.travis.yml +72 -7
  4. data/CHANGELOG.md +306 -4
  5. data/CODE_OF_CONDUCT.md +46 -0
  6. data/CONTRIBUTING.md +56 -12
  7. data/Gemfile +6 -2
  8. data/Guardfile +18 -1
  9. data/LICENSE +208 -38
  10. data/README.md +61 -89
  11. data/Rakefile +2 -0
  12. data/THIRD_PARTY_NOTICES.md +213 -0
  13. data/bin/nrdebug +1 -1
  14. data/init.rb +1 -1
  15. data/install.rb +1 -1
  16. data/lib/new_relic/agent.rb +49 -7
  17. data/lib/new_relic/agent/adaptive_sampler.rb +1 -1
  18. data/lib/new_relic/agent/agent.rb +57 -40
  19. data/lib/new_relic/agent/agent_logger.rb +5 -1
  20. data/lib/new_relic/agent/attribute_filter.rb +8 -8
  21. data/lib/new_relic/agent/attribute_processing.rb +1 -1
  22. data/lib/new_relic/agent/attributes.rb +152 -0
  23. data/lib/new_relic/agent/audit_logger.rb +1 -1
  24. data/lib/new_relic/agent/autostart.rb +20 -15
  25. data/lib/new_relic/agent/chained_call.rb +1 -1
  26. data/lib/new_relic/agent/commands/agent_command.rb +1 -1
  27. data/lib/new_relic/agent/commands/agent_command_router.rb +1 -1
  28. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
  29. data/lib/new_relic/agent/configuration.rb +1 -1
  30. data/lib/new_relic/agent/configuration/default_source.rb +111 -16
  31. data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -1
  32. data/lib/new_relic/agent/configuration/environment_source.rb +1 -1
  33. data/lib/new_relic/agent/configuration/event_harvest_config.rb +1 -1
  34. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -1
  35. data/lib/new_relic/agent/configuration/manager.rb +1 -1
  36. data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
  37. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
  38. data/lib/new_relic/agent/configuration/security_policy_source.rb +1 -1
  39. data/lib/new_relic/agent/configuration/server_source.rb +2 -2
  40. data/lib/new_relic/agent/configuration/yaml_source.rb +12 -7
  41. data/lib/new_relic/agent/connect/request_builder.rb +4 -12
  42. data/lib/new_relic/agent/connect/response_handler.rb +1 -1
  43. data/lib/new_relic/agent/custom_event_aggregator.rb +1 -1
  44. data/lib/new_relic/agent/database.rb +2 -3
  45. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
  46. data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
  47. data/lib/new_relic/agent/database/obfuscator.rb +1 -1
  48. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
  49. data/lib/new_relic/agent/datastores.rb +1 -1
  50. data/lib/new_relic/agent/datastores/metric_helper.rb +1 -1
  51. data/lib/new_relic/agent/datastores/mongo.rb +2 -2
  52. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +3 -3
  53. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
  54. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +9 -9
  55. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +1 -1
  56. data/lib/new_relic/agent/datastores/redis.rb +1 -1
  57. data/lib/new_relic/agent/deprecator.rb +1 -1
  58. data/lib/new_relic/agent/distributed_tracing.rb +156 -7
  59. data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +3 -2
  60. data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +61 -46
  61. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +84 -0
  62. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  63. data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +25 -102
  64. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
  65. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
  66. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
  67. data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
  68. data/lib/new_relic/agent/error_collector.rb +34 -17
  69. data/lib/new_relic/agent/error_event_aggregator.rb +8 -6
  70. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -1
  71. data/lib/new_relic/agent/event_aggregator.rb +1 -1
  72. data/lib/new_relic/agent/event_buffer.rb +1 -1
  73. data/lib/new_relic/agent/event_listener.rb +1 -1
  74. data/lib/new_relic/agent/event_loop.rb +1 -1
  75. data/lib/new_relic/agent/external.rb +8 -8
  76. data/lib/new_relic/agent/guid_generator.rb +28 -0
  77. data/lib/new_relic/agent/harvester.rb +1 -1
  78. data/lib/new_relic/agent/heap.rb +1 -1
  79. data/lib/new_relic/agent/hostname.rb +8 -2
  80. data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
  81. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +25 -20
  82. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +29 -14
  83. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +18 -22
  84. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +11 -12
  85. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +17 -5
  86. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +5 -7
  87. data/lib/new_relic/agent/http_clients/uri_util.rb +4 -3
  88. data/lib/new_relic/agent/instrumentation.rb +1 -1
  89. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +6 -8
  90. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -1
  91. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +12 -3
  92. data/lib/new_relic/agent/instrumentation/active_job.rb +1 -1
  93. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  94. data/lib/new_relic/agent/instrumentation/active_record.rb +85 -38
  95. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +82 -24
  96. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +1 -1
  97. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +92 -34
  98. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +8 -3
  99. data/lib/new_relic/agent/instrumentation/active_storage.rb +1 -1
  100. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +9 -5
  101. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +24 -8
  102. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  103. data/lib/new_relic/agent/instrumentation/bunny.rb +115 -52
  104. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -1
  105. data/lib/new_relic/agent/instrumentation/curb.rb +93 -28
  106. data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -2
  107. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +61 -25
  108. data/lib/new_relic/agent/instrumentation/excon.rb +2 -2
  109. data/lib/new_relic/agent/instrumentation/excon/connection.rb +7 -4
  110. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -2
  111. data/lib/new_relic/agent/instrumentation/grape.rb +6 -11
  112. data/lib/new_relic/agent/instrumentation/http.rb +7 -4
  113. data/lib/new_relic/agent/instrumentation/httpclient.rb +6 -4
  114. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
  115. data/lib/new_relic/agent/instrumentation/memcache.rb +4 -2
  116. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +7 -3
  117. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  118. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  119. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +12 -4
  120. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +9 -7
  121. data/lib/new_relic/agent/instrumentation/mongo.rb +10 -4
  122. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +36 -3
  123. data/lib/new_relic/agent/instrumentation/net.rb +60 -23
  124. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +26 -2
  125. data/lib/new_relic/agent/instrumentation/padrino.rb +40 -16
  126. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
  127. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
  128. data/lib/new_relic/agent/instrumentation/rack.rb +36 -13
  129. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +1 -1
  130. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  131. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
  132. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
  133. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +1 -1
  134. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +1 -1
  135. data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +1 -1
  136. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +1 -1
  137. data/lib/new_relic/agent/instrumentation/rake.rb +54 -20
  138. data/lib/new_relic/agent/instrumentation/redis.rb +141 -56
  139. data/lib/new_relic/agent/instrumentation/resque.rb +4 -1
  140. data/lib/new_relic/agent/instrumentation/sequel.rb +1 -1
  141. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
  142. data/lib/new_relic/agent/instrumentation/sidekiq.rb +48 -24
  143. data/lib/new_relic/agent/instrumentation/sinatra.rb +62 -23
  144. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
  145. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
  146. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  147. data/lib/new_relic/agent/instrumentation/typhoeus.rb +24 -7
  148. data/lib/new_relic/agent/internal_agent_error.rb +1 -1
  149. data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
  150. data/lib/new_relic/agent/log_once.rb +1 -1
  151. data/lib/new_relic/agent/logging.rb +19 -5
  152. data/lib/new_relic/agent/memory_logger.rb +1 -1
  153. data/lib/new_relic/agent/messaging.rb +6 -74
  154. data/lib/new_relic/agent/method_tracer.rb +19 -7
  155. data/lib/new_relic/agent/method_tracer_helpers.rb +3 -3
  156. data/lib/new_relic/agent/monitors.rb +27 -0
  157. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
  158. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
  159. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +2 -2
  160. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +3 -5
  161. data/lib/new_relic/agent/new_relic_service.rb +8 -7
  162. data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
  163. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -1
  164. data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
  165. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -1
  166. data/lib/new_relic/agent/noticible_error.rb +22 -0
  167. data/lib/new_relic/agent/null_logger.rb +1 -1
  168. data/lib/new_relic/agent/obfuscator.rb +1 -1
  169. data/lib/new_relic/agent/parameter_filtering.rb +1 -1
  170. data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
  171. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  172. data/lib/new_relic/agent/pipe_service.rb +1 -1
  173. data/lib/new_relic/agent/prepend_supportability.rb +1 -1
  174. data/lib/new_relic/agent/priority_sampled_buffer.rb +8 -5
  175. data/lib/new_relic/agent/range_extensions.rb +1 -1
  176. data/lib/new_relic/agent/rules_engine.rb +1 -1
  177. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +1 -1
  178. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
  179. data/lib/new_relic/agent/sampler.rb +1 -1
  180. data/lib/new_relic/agent/sampler_collection.rb +1 -1
  181. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  182. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -1
  183. data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
  184. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  185. data/lib/new_relic/agent/samplers/vm_sampler.rb +1 -1
  186. data/lib/new_relic/agent/span_event_aggregator.rb +2 -1
  187. data/lib/new_relic/agent/span_event_primitive.rb +106 -54
  188. data/lib/new_relic/agent/sql_sampler.rb +6 -6
  189. data/lib/new_relic/agent/stats.rb +1 -1
  190. data/lib/new_relic/agent/stats_engine.rb +1 -1
  191. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  192. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  193. data/lib/new_relic/agent/supported_versions.rb +3 -3
  194. data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -1
  195. data/lib/new_relic/agent/system_info.rb +13 -4
  196. data/lib/new_relic/agent/threading/agent_thread.rb +1 -1
  197. data/lib/new_relic/agent/threading/backtrace_node.rb +1 -1
  198. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
  199. data/lib/new_relic/agent/threading/thread_profile.rb +1 -1
  200. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
  201. data/lib/new_relic/agent/tracer.rb +34 -19
  202. data/lib/new_relic/agent/transaction.rb +104 -82
  203. data/lib/new_relic/agent/transaction/abstract_segment.rb +31 -4
  204. data/lib/new_relic/agent/transaction/datastore_segment.rb +1 -1
  205. data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
  206. data/lib/new_relic/agent/transaction/distributed_tracing.rb +58 -147
  207. data/lib/new_relic/agent/transaction/external_request_segment.rb +30 -37
  208. data/lib/new_relic/agent/transaction/message_broker_segment.rb +4 -12
  209. data/lib/new_relic/agent/transaction/request_attributes.rb +1 -1
  210. data/lib/new_relic/agent/transaction/segment.rb +24 -2
  211. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
  212. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  213. data/lib/new_relic/agent/transaction/trace.rb +3 -5
  214. data/lib/new_relic/agent/transaction/trace_builder.rb +1 -1
  215. data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
  216. data/lib/new_relic/agent/transaction/trace_node.rb +11 -9
  217. data/lib/new_relic/agent/transaction/tracing.rb +1 -1
  218. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
  219. data/lib/new_relic/agent/transaction_error_primitive.rb +11 -16
  220. data/lib/new_relic/agent/transaction_event_aggregator.rb +1 -1
  221. data/lib/new_relic/agent/transaction_event_primitive.rb +29 -40
  222. data/lib/new_relic/agent/transaction_event_recorder.rb +1 -1
  223. data/lib/new_relic/agent/transaction_metrics.rb +1 -1
  224. data/lib/new_relic/agent/transaction_sampler.rb +1 -1
  225. data/lib/new_relic/agent/transaction_time_aggregator.rb +1 -1
  226. data/lib/new_relic/agent/utilization/aws.rb +1 -1
  227. data/lib/new_relic/agent/utilization/azure.rb +1 -1
  228. data/lib/new_relic/agent/utilization/gcp.rb +1 -1
  229. data/lib/new_relic/agent/utilization/pcf.rb +1 -1
  230. data/lib/new_relic/agent/utilization/vendor.rb +1 -1
  231. data/lib/new_relic/agent/utilization_data.rb +1 -1
  232. data/lib/new_relic/agent/vm.rb +1 -1
  233. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
  234. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  235. data/lib/new_relic/agent/vm/mri_vm.rb +1 -1
  236. data/lib/new_relic/agent/vm/snapshot.rb +1 -1
  237. data/lib/new_relic/agent/worker_loop.rb +1 -1
  238. data/lib/new_relic/cli/command.rb +1 -1
  239. data/lib/new_relic/cli/commands/deployments.rb +1 -1
  240. data/lib/new_relic/cli/commands/install.rb +4 -3
  241. data/lib/new_relic/coerce.rb +32 -7
  242. data/lib/new_relic/collection_helper.rb +1 -1
  243. data/lib/new_relic/constants.rb +38 -0
  244. data/lib/new_relic/control.rb +1 -1
  245. data/lib/new_relic/control/class_methods.rb +1 -1
  246. data/lib/new_relic/control/frameworks.rb +1 -1
  247. data/lib/new_relic/control/frameworks/external.rb +1 -1
  248. data/lib/new_relic/control/frameworks/merb.rb +1 -1
  249. data/lib/new_relic/control/frameworks/rails.rb +1 -1
  250. data/lib/new_relic/control/frameworks/rails3.rb +1 -1
  251. data/lib/new_relic/control/frameworks/rails4.rb +1 -1
  252. data/lib/new_relic/control/frameworks/rails_notifications.rb +1 -1
  253. data/lib/new_relic/control/frameworks/ruby.rb +1 -1
  254. data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
  255. data/lib/new_relic/control/instance_methods.rb +11 -2
  256. data/lib/new_relic/control/instrumentation.rb +1 -1
  257. data/lib/new_relic/control/server_methods.rb +1 -1
  258. data/lib/new_relic/delayed_job_injection.rb +1 -1
  259. data/lib/new_relic/dependency_detection.rb +5 -5
  260. data/lib/new_relic/environment_report.rb +6 -2
  261. data/lib/new_relic/helper.rb +1 -1
  262. data/lib/new_relic/language_support.rb +1 -1
  263. data/lib/new_relic/latest_changes.rb +2 -2
  264. data/lib/new_relic/local_environment.rb +1 -1
  265. data/lib/new_relic/metric_data.rb +1 -1
  266. data/lib/new_relic/metric_spec.rb +1 -1
  267. data/lib/new_relic/metrics.rb +1 -1
  268. data/lib/new_relic/noticed_error.rb +39 -18
  269. data/lib/new_relic/rack.rb +1 -1
  270. data/lib/new_relic/rack/agent_hooks.rb +1 -1
  271. data/lib/new_relic/rack/agent_middleware.rb +1 -1
  272. data/lib/new_relic/rack/browser_monitoring.rb +6 -1
  273. data/lib/new_relic/recipes.rb +1 -1
  274. data/lib/new_relic/recipes/capistrano3.rb +1 -1
  275. data/lib/new_relic/recipes/capistrano_legacy.rb +1 -1
  276. data/lib/new_relic/supportability_helper.rb +15 -1
  277. data/lib/new_relic/version.rb +2 -2
  278. data/lib/newrelic_rpm.rb +1 -1
  279. data/lib/sequel/extensions/newrelic_instrumentation.rb +1 -1
  280. data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
  281. data/lib/tasks/all.rb +1 -1
  282. data/lib/tasks/multiverse.rb +26 -1
  283. data/lib/tasks/newrelic.rb +1 -1
  284. data/lib/tasks/tests.rake +6 -1
  285. data/newrelic_rpm.gemspec +19 -13
  286. data/recipes/newrelic.rb +1 -1
  287. data/test/agent_helper.rb +332 -72
  288. metadata +103 -38
  289. data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
  290. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -40
  291. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
  292. data/lib/new_relic/agent/transaction/attributes.rb +0 -154
  293. data/lib/tasks/versions.html.erb +0 -28
  294. data/lib/tasks/versions.postface.html +0 -8
  295. data/lib/tasks/versions.preface.html +0 -9
  296. data/lib/tasks/versions.rake +0 -65
  297. data/lib/tasks/versions.txt.erb +0 -14
@@ -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'
@@ -21,6 +21,7 @@ module NewRelic::Rack
21
21
 
22
22
  CONTENT_TYPE = 'Content-Type'.freeze
23
23
  CONTENT_DISPOSITION = 'Content-Disposition'.freeze
24
+ CONTENT_LENGTH = 'Content-Length'.freeze
24
25
  ATTACHMENT = 'attachment'.freeze
25
26
  TEXT_HTML = 'text/html'.freeze
26
27
 
@@ -35,6 +36,10 @@ module NewRelic::Rack
35
36
  js_to_inject = NewRelic::Agent.browser_timing_header
36
37
  if (js_to_inject != "") && should_instrument?(env, status, headers)
37
38
  response_string = autoinstrument_source(response, headers, js_to_inject)
39
+ if headers.key?(CONTENT_LENGTH)
40
+ content_length = response_string ? response_string.bytesize : 0
41
+ headers[CONTENT_LENGTH] = content_length.to_s
42
+ end
38
43
 
39
44
  env[ALREADY_INSTRUMENTED_KEY] = true
40
45
  if response_string
@@ -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
@@ -11,6 +11,8 @@ module NewRelic
11
11
  # transaction, just to eke out a bit less performance hit
12
12
  #
13
13
  API_SUPPORTABILITY_METRICS = [
14
+ :accept_distributed_trace_headers,
15
+ :create_distributed_trace_headers,
14
16
  :add_custom_attributes,
15
17
  :add_instrumentation,
16
18
  :add_method_tracer,
@@ -64,5 +66,17 @@ module NewRelic
64
66
  NewRelic::Agent.logger.debug "API supportability metric not found for :#{method_name}"
65
67
  end
66
68
  end
69
+
70
+ def valid_api_argument_class? arg, name, klass
71
+ return true if arg.is_a?(klass)
72
+
73
+ caller_location = caller_locations.first.label
74
+
75
+ message = "Bad argument passed to ##{caller_location}. " \
76
+ "Expected #{klass} for `#{name}` but got #{headers.class}"
77
+
78
+ NewRelic::Agent.logger.warn message
79
+ nil
80
+ end
67
81
  end
68
82
  end
@@ -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 = 7
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
@@ -26,9 +26,14 @@ if defined? Rake::TestTask
26
26
  agent_home = File.expand_path(File.join(File.dirname(__FILE__),'..','..'))
27
27
 
28
28
  Rake::TestTask.new(:newrelic) do |t|
29
+
30
+ file_pattern = ENV["file"]
31
+ file_pattern = file_pattern.split(",").map{|f| "#{agent_home}/#{f}".gsub("//", "/")} if file_pattern
32
+ file_pattern ||= "#{agent_home}/test/new_relic/**/*_test.rb"
33
+
29
34
  t.libs << "#{agent_home}/test"
30
35
  t.libs << "#{agent_home}/lib"
31
- t.pattern = "#{agent_home}/test/new_relic/**/*_test.rb"
36
+ t.pattern = Array(file_pattern)
32
37
  t.verbose = true
33
38
  end
34
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 = [ "Matthew Wear", "Chris Pine", "Rachel Klein", "Justin Foote" ]
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
@@ -48,12 +50,16 @@ EOS
48
50
  s.rubygems_version = Gem::VERSION
49
51
  s.summary = "New Relic Ruby Agent"
50
52
 
51
- s.add_development_dependency 'rake', '10.1.0'
52
- s.add_development_dependency 'minitest', '~> 4.7.5'
53
- s.add_development_dependency 'mocha', '~> 0.13.0'
53
+ s.add_development_dependency 'rake', '12.3.3'
54
+ s.add_development_dependency 'rb-inotify', '0.9.10' # locked to support < Ruby 2.3 (and listen 3.0.8)
55
+ s.add_development_dependency 'listen', '3.0.8' # locked to support < Ruby 2.3
56
+ s.add_development_dependency 'minitest', '4.7.5'
57
+ s.add_development_dependency 'mocha', '~> 1.9.0'
54
58
  s.add_development_dependency 'yard'
55
- s.add_development_dependency 'pry-nav', '~> 0.2.4'
59
+ s.add_development_dependency 'pry-nav', '~> 0.3.0'
56
60
  s.add_development_dependency 'pry-stack_explorer', '~> 0.4.9'
61
+ s.add_development_dependency 'guard', '~> 2.16.0'
62
+ s.add_development_dependency 'guard-minitest', '~> 2.4.0'
57
63
  s.add_development_dependency 'hometown', '~> 0.2.5'
58
- s.add_development_dependency 'bundler', '< 2.0'
64
+ s.add_development_dependency 'bundler'
59
65
  end
@@ -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)
@@ -212,9 +251,9 @@ end
212
251
  #
213
252
  # If you want to *allow* unexpected metrics matching certain patterns, use
214
253
  # the :ignore_filter option. This will allow you to specify a Regex that
215
- # whitelists broad swathes of metric territory (e.g. 'Supportability/').
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
 
@@ -345,25 +384,70 @@ def in_transaction(*args, &blk)
345
384
  txn
346
385
  end
347
386
 
348
- def stub_transaction_guid(guid)
387
+ # Temporarily disables default transformer so tests with invalid inputs can be tried
388
+ def with_disabled_defaults_transformer key
389
+ begin
390
+ transformer = NewRelic::Agent::Configuration::DEFAULTS[key][:transform]
391
+ NewRelic::Agent::Configuration::DEFAULTS[key][:transform] = nil
392
+ yield
393
+ ensure
394
+ NewRelic::Agent::Configuration::DEFAULTS[key][:transform] = transformer
395
+ end
396
+ end
397
+
398
+ # Convenience wrapper to stand up a transaction and provide a segment within
399
+ # that transaction to work with. The same arguements as provided to in_transaction
400
+ # may be supplied.
401
+ def with_segment *args, &blk
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
429
+ end
430
+ end
431
+
432
+ def stub_transaction_guid guid
349
433
  NewRelic::Agent::Transaction.tl_current.instance_variable_set(:@guid, guid)
350
434
  end
351
435
 
352
436
  # Convenience wrapper around in_transaction that sets the category so that it
353
437
  # looks like we are in a web transaction
354
- def in_web_transaction(name='dummy')
438
+ def in_web_transaction name='dummy'
355
439
  in_transaction(name, :category => :controller, :request => stub(:path => '/')) do |txn|
356
440
  yield txn
357
441
  end
358
442
  end
359
443
 
360
- def in_background_transaction(name='silly')
444
+ def in_background_transaction name='silly'
361
445
  in_transaction(name, :category => :task) do |txn|
362
446
  yield txn
363
447
  end
364
448
  end
365
449
 
366
- def refute_contains_request_params(attributes)
450
+ def refute_contains_request_params attributes
367
451
  attributes.keys.each do |key|
368
452
  refute_match(/^request\.parameters\./, key.to_s)
369
453
  end
@@ -382,7 +466,7 @@ def last_transaction_trace_request_params
382
466
  end
383
467
  end
384
468
 
385
- def find_sql_trace(metric_name)
469
+ def find_sql_trace metric_name
386
470
  NewRelic::Agent.agent.sql_sampler.sql_traces.values.detect do |trace|
387
471
  trace.database_metric_name == metric_name
388
472
  end
@@ -392,7 +476,7 @@ def last_sql_trace
392
476
  NewRelic::Agent.agent.sql_sampler.sql_traces.values.last
393
477
  end
394
478
 
395
- def find_last_transaction_node(transaction_sample=nil)
479
+ def find_last_transaction_node transaction_sample=nil
396
480
  if transaction_sample
397
481
  root_node = transaction_sample.root_node
398
482
  else
@@ -405,7 +489,7 @@ def find_last_transaction_node(transaction_sample=nil)
405
489
  return last_node
406
490
  end
407
491
 
408
- def find_node_with_name(transaction_sample, name)
492
+ def find_node_with_name transaction_sample, name
409
493
  transaction_sample.root_node.each_node do |node|
410
494
  if node.metric_name == name
411
495
  return node
@@ -415,7 +499,7 @@ def find_node_with_name(transaction_sample, name)
415
499
  nil
416
500
  end
417
501
 
418
- def find_node_with_name_matching(transaction_sample, regex)
502
+ def find_node_with_name_matching transaction_sample, regex
419
503
  transaction_sample.root_node.each_node do |node|
420
504
  if node.metric_name.match regex
421
505
  return node
@@ -425,7 +509,7 @@ def find_node_with_name_matching(transaction_sample, regex)
425
509
  nil
426
510
  end
427
511
 
428
- def find_all_nodes_with_name_matching(transaction_sample, regexes)
512
+ def find_all_nodes_with_name_matching transaction_sample, regexes
429
513
  regexes = [regexes].flatten
430
514
  matching_nodes = []
431
515
 
@@ -440,7 +524,7 @@ def find_all_nodes_with_name_matching(transaction_sample, regexes)
440
524
  matching_nodes
441
525
  end
442
526
 
443
- def with_config(config_hash, at_start=true)
527
+ def with_config config_hash, at_start=true
444
528
  config = NewRelic::Agent::Configuration::DottedHash.new(config_hash, true)
445
529
  NewRelic::Agent.config.add_config_for_testing(config, at_start)
446
530
  NewRelic::Agent.instance.refresh_attribute_filter
@@ -459,13 +543,13 @@ def with_server_source config_hash, at_start=true
459
543
  end
460
544
  end
461
545
 
462
- def with_config_low_priority(config_hash)
546
+ def with_config_low_priority config_hash
463
547
  with_config(config_hash, false) do
464
548
  yield
465
549
  end
466
550
  end
467
551
 
468
- def with_transaction_renaming_rules(rule_specs)
552
+ def with_transaction_renaming_rules rule_specs
469
553
  original_engine = NewRelic::Agent.agent.instance_variable_get(:@transaction_rules)
470
554
  begin
471
555
  new_engine = NewRelic::Agent::RulesEngine.create_transaction_rules('transaction_name_rules' => rule_specs)
@@ -491,7 +575,7 @@ unless Time.respond_to?(:__original_now)
491
575
  end
492
576
  end
493
577
 
494
- def nr_freeze_time(now=Time.now)
578
+ def nr_freeze_time now=Time.now
495
579
  Time.__frozen_now = now
496
580
  end
497
581
 
@@ -499,11 +583,11 @@ def nr_unfreeze_time
499
583
  Time.__frozen_now = nil
500
584
  end
501
585
 
502
- def advance_time(seconds)
586
+ def advance_time seconds
503
587
  Time.__frozen_now = Time.now + seconds
504
588
  end
505
589
 
506
- def with_constant_defined(constant_symbol, implementation=Module.new)
590
+ def with_constant_defined constant_symbol, implementation=Module.new
507
591
  const_path = constant_path(constant_symbol.to_s)
508
592
 
509
593
  if const_path
@@ -523,7 +607,7 @@ def with_constant_defined(constant_symbol, implementation=Module.new)
523
607
  end
524
608
  end
525
609
 
526
- def constant_path(name, opts={})
610
+ def constant_path name, opts={}
527
611
  allow_partial = opts[:allow_partial]
528
612
  path = [Object]
529
613
  parts = name.gsub(/^::/, '').split('::')
@@ -536,13 +620,13 @@ def constant_path(name, opts={})
536
620
  path
537
621
  end
538
622
 
539
- def get_parent(constant_name)
623
+ def get_parent constant_name
540
624
  parent_name = constant_name.gsub(/::[^:]*$/, '')
541
625
  const_path = constant_path(parent_name)
542
626
  const_path ? const_path[-1] : nil
543
627
  end
544
628
 
545
- def undefine_constant(constant_symbol)
629
+ def undefine_constant constant_symbol
546
630
  const_str = constant_symbol.to_s
547
631
  parent = get_parent(const_str)
548
632
  const_name = const_str.gsub(/.*::/, '')
@@ -566,11 +650,11 @@ ensure
566
650
  NewRelic::Agent.logger = orig_logger
567
651
  end
568
652
 
569
- def create_agent_command(args = {})
653
+ def create_agent_command args={}
570
654
  NewRelic::Agent::Commands::AgentCommand.new([-1, { "name" => "command_name", "arguments" => args}])
571
655
  end
572
656
 
573
- def wait_for_backtrace_service_poll(opts={})
657
+ def wait_for_backtrace_service_poll opts={}
574
658
  defaults = {
575
659
  :timeout => 10.0,
576
660
  :service => NewRelic::Agent.agent.agent_command_router.backtrace_service,
@@ -596,7 +680,7 @@ def wait_for_backtrace_service_poll(opts={})
596
680
  end
597
681
  end
598
682
 
599
- def with_array_logger(level=:info)
683
+ def with_array_logger level=:info
600
684
  orig_logger = NewRelic::Agent.logger
601
685
  config = { :log_level => level }
602
686
  logdev = ArrayLogDevice.new
@@ -612,20 +696,90 @@ ensure
612
696
  NewRelic::Agent.logger = orig_logger
613
697
  end
614
698
 
615
- def with_environment(env)
616
- old_env = {}
617
- env.each do |key, val|
618
- old_env[key] = ENV[key]
619
- ENV[key] = val.to_s
699
+ # The EnvUpdater was introduced due to random fails in JRuby environment
700
+ # whereby attempting to set ENV[key] = some_value randomly failed.
701
+ # It is conjectured that this is thread related, but may also be
702
+ # a core bug in the JVM implementation of Ruby. Root cause was not
703
+ # discovered, but it was found that a combination of retrying and using
704
+ # mutex lock around the update operation was the only consistently working
705
+ # solution as the error continued to surface without the mutex and
706
+ # retry alone wasn't enough, either.
707
+ #
708
+ # JRUBY: oraclejdk8 + jruby-9.2.6.0
709
+ #
710
+ # NOTE: Singleton pattern to ensure one mutex lock for all threads
711
+ class EnvUpdater
712
+ MAX_RETRIES = 5
713
+
714
+ def initialize
715
+ @mutex = Mutex.new
620
716
  end
621
- begin
717
+
718
+ # Will attempt the given block up to MAX_RETRIES before
719
+ # surfacing the exception down the chain.
720
+ def with_retry retry_limit=MAX_RETRIES
721
+ retries ||= 0
722
+ sleep(retries)
622
723
  yield
623
- ensure
624
- old_env.each { |key, old_val| ENV[key] = old_val }
724
+ rescue
725
+ (retries += 1) < retry_limit ? retry : raise
726
+ end
727
+
728
+ # Locks and updates the ENV
729
+ def safe_update env
730
+ with_retry do
731
+ @mutex.synchronize do
732
+ env.each{ |key, val| ENV[key] = val.to_s }
733
+ end
734
+ end
735
+ end
736
+
737
+ # Locks and restores the ENV
738
+ def safe_restore old_env
739
+ with_retry do
740
+ @mutex.synchronize do
741
+ old_env.each{ |key, val| val ? ENV[key] = val : ENV.delete(key) }
742
+ end
743
+ end
744
+ end
745
+
746
+ # Singleton pattern implemented via @@instance
747
+ def self.instance
748
+ @@instance ||= EnvUpdater.new
749
+ end
750
+
751
+ def self.safe_update env
752
+ instance.safe_update env
753
+ end
754
+
755
+ def self.safe_restore old_env
756
+ instance.safe_restore old_env
625
757
  end
758
+
759
+ # Effectively saves current ENV settings for given env's key/values,
760
+ # runs given block, then restores ENV to original state before returning.
761
+ def self.inject env, &block
762
+ old_env = {}
763
+ env.each{ |key, val| old_env[key] = ENV[key] }
764
+ begin
765
+ safe_update(env)
766
+ yield
767
+ ensure
768
+ safe_restore(old_env)
769
+ end
770
+ end
771
+
772
+ # must call instance here to ensure only one @mutex for all threads.
773
+ instance
774
+ end
775
+
776
+ # Changes ENV settings to given and runs given block and restores ENV
777
+ # to original values before returning.
778
+ def with_environment env, &block
779
+ EnvUpdater.inject(env) { yield }
626
780
  end
627
781
 
628
- def with_argv(argv)
782
+ def with_argv argv
629
783
  old_argv = ARGV.dup
630
784
  ARGV.clear
631
785
  ARGV.concat(argv)
@@ -638,7 +792,7 @@ def with_argv(argv)
638
792
  end
639
793
  end
640
794
 
641
- def with_ignore_error_filter(filter, &blk)
795
+ def with_ignore_error_filter filter, &blk
642
796
  original_filter = NewRelic::Agent.ignore_error_filter
643
797
  NewRelic::Agent.ignore_error_filter(&filter)
644
798
 
@@ -647,7 +801,7 @@ ensure
647
801
  NewRelic::Agent::ErrorCollector.ignore_error_filter = original_filter
648
802
  end
649
803
 
650
- def json_dump_and_encode(object)
804
+ def json_dump_and_encode object
651
805
  Base64.encode64(::JSON.dump(object))
652
806
  end
653
807
 
@@ -655,7 +809,7 @@ def get_last_analytics_event
655
809
  NewRelic::Agent.agent.transaction_event_aggregator.harvest![1].last
656
810
  end
657
811
 
658
- def swap_instance_method(target, method_name, new_method_implementation, &blk)
812
+ def swap_instance_method target, method_name, new_method_implementation, &blk
659
813
  old_method_implementation = target.instance_method(method_name)
660
814
  target.send(:define_method, method_name, new_method_implementation)
661
815
  yield
@@ -670,7 +824,7 @@ def cross_agent_tests_dir
670
824
  File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'cross_agent_tests'))
671
825
  end
672
826
 
673
- def load_cross_agent_test(name)
827
+ def load_cross_agent_test name
674
828
  test_file_path = File.join(cross_agent_tests_dir, "#{name}.json")
675
829
  data = File.read(test_file_path)
676
830
  data.gsub!('callCount', 'call_count')
@@ -679,13 +833,13 @@ def load_cross_agent_test(name)
679
833
  data
680
834
  end
681
835
 
682
- def each_cross_agent_test(options)
836
+ def each_cross_agent_test options
683
837
  options = {:dir => nil, :pattern => "*"}.update(options)
684
838
  path = File.join [cross_agent_tests_dir, options[:dir], options[:pattern]].compact
685
839
  Dir.glob(path).each { |file| yield file}
686
840
  end
687
841
 
688
- 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
689
843
  incorrect_attributes = []
690
844
 
691
845
  event_attrs = event[0]
@@ -709,10 +863,116 @@ def assert_event_attributes(event, test_name, expected_attributes, non_expected_
709
863
  assert(incorrect_attributes.empty?, msg)
710
864
 
711
865
  non_expected_attributes.each do |name|
712
- 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}"
713
867
  end
714
868
  end
715
869
 
716
- def attributes_for(sample, type)
870
+ def attributes_for sample, type
717
871
  sample.attributes.instance_variable_get("@#{type}_attributes")
718
872
  end
873
+
874
+ def uncache_trusted_account_key
875
+ NewRelic::Agent::Transaction::TraceContext::AccountHelpers.instance_variable_set :@trace_state_entry_key, nil
876
+ end
877
+
878
+ def reset_buffers_and_caches
879
+ NewRelic::Agent.drop_buffered_data
880
+ uncache_trusted_account_key
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