newrelic_rpm 6.9.0.363 → 6.13.1

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