newrelic_rpm 8.2.0 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (439) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -2
  3. data/.rubocop.yml +1919 -0
  4. data/.rubocop_todo.yml +100 -0
  5. data/.simplecov +15 -0
  6. data/.snyk +11 -0
  7. data/.yardopts +1 -0
  8. data/Brewfile +12 -0
  9. data/CHANGELOG.md +3654 -2951
  10. data/CONTRIBUTING.md +21 -6
  11. data/DOCKER.md +167 -0
  12. data/Dockerfile +10 -0
  13. data/Gemfile +0 -1
  14. data/Guardfile +9 -8
  15. data/LICENSE +0 -6
  16. data/README.md +20 -20
  17. data/Rakefile +27 -29
  18. data/THIRD_PARTY_NOTICES.md +14 -199
  19. data/Thorfile +5 -0
  20. data/bin/newrelic +3 -2
  21. data/bin/newrelic_cmd +1 -0
  22. data/bin/nrdebug +76 -53
  23. data/config.dot +5 -5
  24. data/docker-compose.yml +107 -0
  25. data/init.rb +4 -6
  26. data/install.rb +2 -2
  27. data/lefthook.yml +9 -0
  28. data/lib/new_relic/agent/adaptive_sampler.rb +11 -7
  29. data/lib/new_relic/agent/agent.rb +94 -924
  30. data/lib/new_relic/agent/agent_helpers/connect.rb +227 -0
  31. data/lib/new_relic/agent/agent_helpers/harvest.rb +153 -0
  32. data/lib/new_relic/agent/agent_helpers/shutdown.rb +72 -0
  33. data/lib/new_relic/agent/agent_helpers/special_startup.rb +74 -0
  34. data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +167 -0
  35. data/lib/new_relic/agent/agent_helpers/startup.rb +202 -0
  36. data/lib/new_relic/agent/agent_helpers/transmit.rb +76 -0
  37. data/lib/new_relic/agent/agent_logger.rb +23 -19
  38. data/lib/new_relic/agent/attribute_filter.rb +64 -47
  39. data/lib/new_relic/agent/attribute_processing.rb +7 -7
  40. data/lib/new_relic/agent/attributes.rb +5 -4
  41. data/lib/new_relic/agent/audit_logger.rb +8 -3
  42. data/lib/new_relic/agent/autostart.rb +20 -18
  43. data/lib/new_relic/agent/chained_call.rb +1 -1
  44. data/lib/new_relic/agent/commands/agent_command.rb +3 -3
  45. data/lib/new_relic/agent/commands/agent_command_router.rb +12 -11
  46. data/lib/new_relic/agent/commands/thread_profiler_session.rb +5 -7
  47. data/lib/new_relic/agent/configuration/default_source.rb +1353 -1355
  48. data/lib/new_relic/agent/configuration/dotted_hash.rb +6 -5
  49. data/lib/new_relic/agent/configuration/environment_source.rb +11 -9
  50. data/lib/new_relic/agent/configuration/event_harvest_config.rb +13 -6
  51. data/lib/new_relic/agent/configuration/high_security_source.rb +8 -9
  52. data/lib/new_relic/agent/configuration/manager.rb +82 -68
  53. data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
  54. data/lib/new_relic/agent/configuration/mask_defaults.rb +3 -3
  55. data/lib/new_relic/agent/configuration/security_policy_source.rb +82 -85
  56. data/lib/new_relic/agent/configuration/server_source.rb +19 -18
  57. data/lib/new_relic/agent/configuration/yaml_source.rb +16 -13
  58. data/lib/new_relic/agent/configuration.rb +1 -1
  59. data/lib/new_relic/agent/connect/request_builder.rb +17 -19
  60. data/lib/new_relic/agent/connect/response_handler.rb +5 -8
  61. data/lib/new_relic/agent/custom_event_aggregator.rb +14 -15
  62. data/lib/new_relic/agent/database/explain_plan_helpers.rb +4 -5
  63. data/lib/new_relic/agent/database/obfuscation_helpers.rb +14 -13
  64. data/lib/new_relic/agent/database/obfuscator.rb +2 -2
  65. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +3 -3
  66. data/lib/new_relic/agent/database.rb +37 -48
  67. data/lib/new_relic/agent/database_adapter.rb +3 -1
  68. data/lib/new_relic/agent/datastores/metric_helper.rb +17 -18
  69. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +7 -6
  70. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +6 -10
  71. data/lib/new_relic/agent/datastores/mongo.rb +1 -1
  72. data/lib/new_relic/agent/datastores/nosql_obfuscator.rb +41 -0
  73. data/lib/new_relic/agent/datastores/redis.rb +5 -7
  74. data/lib/new_relic/agent/datastores.rb +7 -9
  75. data/lib/new_relic/agent/deprecator.rb +1 -1
  76. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +6 -6
  77. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +31 -29
  78. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +22 -21
  79. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +19 -19
  80. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +49 -51
  81. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +5 -6
  82. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +76 -77
  83. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +37 -36
  84. data/lib/new_relic/agent/distributed_tracing.rb +33 -35
  85. data/lib/new_relic/agent/encoding_normalizer.rb +4 -2
  86. data/lib/new_relic/agent/error_collector.rb +27 -23
  87. data/lib/new_relic/agent/error_event_aggregator.rb +4 -5
  88. data/lib/new_relic/agent/error_filter.rb +15 -16
  89. data/lib/new_relic/agent/error_trace_aggregator.rb +4 -3
  90. data/lib/new_relic/agent/event_aggregator.rb +22 -21
  91. data/lib/new_relic/agent/event_buffer.rb +7 -8
  92. data/lib/new_relic/agent/event_listener.rb +1 -2
  93. data/lib/new_relic/agent/event_loop.rb +22 -20
  94. data/lib/new_relic/agent/external.rb +11 -12
  95. data/lib/new_relic/agent/guid_generator.rb +13 -11
  96. data/lib/new_relic/agent/harvester.rb +4 -5
  97. data/lib/new_relic/agent/heap.rb +7 -9
  98. data/lib/new_relic/agent/hostname.rb +20 -13
  99. data/lib/new_relic/agent/http_clients/abstract.rb +8 -9
  100. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +6 -11
  101. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +8 -9
  102. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +4 -5
  103. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +2 -4
  104. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +2 -4
  105. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +4 -5
  106. data/lib/new_relic/agent/http_clients/uri_util.rb +1 -3
  107. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +9 -22
  108. data/lib/new_relic/agent/instrumentation/action_controller_other_subscriber.rb +39 -0
  109. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +37 -30
  110. data/lib/new_relic/agent/instrumentation/action_dispatch.rb +31 -0
  111. data/lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb +64 -0
  112. data/lib/new_relic/agent/instrumentation/action_mailbox.rb +30 -0
  113. data/lib/new_relic/agent/instrumentation/action_mailbox_subscriber.rb +33 -0
  114. data/lib/new_relic/agent/instrumentation/action_mailer.rb +30 -0
  115. data/lib/new_relic/agent/instrumentation/action_mailer_subscriber.rb +85 -0
  116. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +18 -19
  117. data/lib/new_relic/agent/instrumentation/active_job.rb +33 -13
  118. data/lib/new_relic/agent/instrumentation/active_job_subscriber.rb +41 -0
  119. data/lib/new_relic/agent/instrumentation/active_merchant.rb +19 -5
  120. data/lib/new_relic/agent/instrumentation/active_record.rb +37 -35
  121. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +71 -61
  122. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +49 -46
  123. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +4 -4
  124. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +26 -17
  125. data/lib/new_relic/agent/instrumentation/active_storage.rb +7 -3
  126. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +8 -33
  127. data/lib/new_relic/agent/instrumentation/active_support.rb +27 -0
  128. data/lib/new_relic/agent/instrumentation/active_support_logger/chain.rb +23 -0
  129. data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +20 -0
  130. data/lib/new_relic/agent/instrumentation/active_support_logger/prepend.rb +12 -0
  131. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +24 -0
  132. data/lib/new_relic/agent/instrumentation/active_support_subscriber.rb +41 -0
  133. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +11 -11
  134. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +20 -22
  135. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +4 -4
  136. data/lib/new_relic/agent/instrumentation/bunny.rb +4 -5
  137. data/lib/new_relic/agent/instrumentation/concurrent_ruby/chain.rb +36 -0
  138. data/lib/new_relic/agent/instrumentation/concurrent_ruby/instrumentation.rb +21 -0
  139. data/lib/new_relic/agent/instrumentation/concurrent_ruby/prepend.rb +27 -0
  140. data/lib/new_relic/agent/instrumentation/concurrent_ruby.rb +31 -0
  141. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +67 -58
  142. data/lib/new_relic/agent/instrumentation/curb/chain.rb +41 -43
  143. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +52 -53
  144. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +12 -14
  145. data/lib/new_relic/agent/instrumentation/curb.rb +7 -7
  146. data/lib/new_relic/agent/instrumentation/custom_events.rb +12 -0
  147. data/lib/new_relic/agent/instrumentation/custom_events_subscriber.rb +37 -0
  148. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +6 -9
  149. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +4 -9
  150. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +1 -2
  151. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +28 -10
  152. data/lib/new_relic/agent/instrumentation/elasticsearch/chain.rb +29 -0
  153. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +66 -0
  154. data/lib/new_relic/agent/instrumentation/elasticsearch/prepend.rb +13 -0
  155. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +31 -0
  156. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +6 -6
  157. data/lib/new_relic/agent/instrumentation/excon.rb +24 -8
  158. data/lib/new_relic/agent/instrumentation/fiber/chain.rb +20 -0
  159. data/lib/new_relic/agent/instrumentation/fiber/instrumentation.rb +24 -0
  160. data/lib/new_relic/agent/instrumentation/fiber/prepend.rb +18 -0
  161. data/lib/new_relic/agent/instrumentation/fiber.rb +25 -0
  162. data/lib/new_relic/agent/instrumentation/grape/chain.rb +7 -8
  163. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +12 -12
  164. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +4 -4
  165. data/lib/new_relic/agent/instrumentation/grape.rb +12 -13
  166. data/lib/new_relic/agent/instrumentation/grpc/client/chain.rb +97 -0
  167. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +89 -0
  168. data/lib/new_relic/agent/instrumentation/grpc/client/prepend.rb +111 -0
  169. data/lib/new_relic/agent/instrumentation/grpc/client/request_wrapper.rb +30 -0
  170. data/lib/new_relic/agent/instrumentation/grpc/helper.rb +32 -0
  171. data/lib/new_relic/agent/instrumentation/grpc/server/chain.rb +69 -0
  172. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +134 -0
  173. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_desc_prepend.rb +35 -0
  174. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_server_prepend.rb +26 -0
  175. data/lib/new_relic/agent/instrumentation/grpc_client.rb +23 -0
  176. data/lib/new_relic/agent/instrumentation/grpc_server.rb +25 -0
  177. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +3 -4
  178. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +7 -8
  179. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +1 -3
  180. data/lib/new_relic/agent/instrumentation/httpclient.rb +3 -3
  181. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +3 -3
  182. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +11 -11
  183. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +2 -2
  184. data/lib/new_relic/agent/instrumentation/httprb.rb +4 -4
  185. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +4 -5
  186. data/lib/new_relic/agent/instrumentation/logger/chain.rb +2 -2
  187. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +27 -20
  188. data/lib/new_relic/agent/instrumentation/logger/prepend.rb +1 -1
  189. data/lib/new_relic/agent/instrumentation/logger.rb +7 -6
  190. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +2 -3
  191. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +26 -18
  192. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +8 -10
  193. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +20 -18
  194. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +22 -15
  195. data/lib/new_relic/agent/instrumentation/memcache.rb +22 -23
  196. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +11 -12
  197. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +5 -7
  198. data/lib/new_relic/agent/instrumentation/mongo.rb +3 -3
  199. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +21 -18
  200. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +4 -5
  201. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +10 -10
  202. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +5 -5
  203. data/lib/new_relic/agent/instrumentation/net_http.rb +8 -8
  204. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +51 -9
  205. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +1 -1
  206. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +4 -3
  207. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +2 -2
  208. data/lib/new_relic/agent/instrumentation/padrino.rb +4 -9
  209. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +6 -6
  210. data/lib/new_relic/agent/instrumentation/queue_time.rb +5 -6
  211. data/lib/new_relic/agent/instrumentation/rack/chain.rb +27 -19
  212. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +3 -2
  213. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +14 -12
  214. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +13 -7
  215. data/lib/new_relic/agent/instrumentation/rack.rb +15 -15
  216. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +15 -15
  217. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +4 -4
  218. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +9 -8
  219. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +17 -5
  220. data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +8 -5
  221. data/lib/new_relic/agent/instrumentation/rails_notifications/custom_events.rb +30 -0
  222. data/lib/new_relic/agent/instrumentation/rake/chain.rb +2 -7
  223. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +14 -16
  224. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +1 -1
  225. data/lib/new_relic/agent/instrumentation/rake.rb +9 -9
  226. data/lib/new_relic/agent/instrumentation/redis/chain.rb +25 -14
  227. data/lib/new_relic/agent/instrumentation/redis/constants.rb +17 -0
  228. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +53 -25
  229. data/lib/new_relic/agent/instrumentation/redis/middleware.rb +16 -0
  230. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +10 -5
  231. data/lib/new_relic/agent/instrumentation/redis.rb +13 -7
  232. data/lib/new_relic/agent/instrumentation/resque/chain.rb +4 -5
  233. data/lib/new_relic/agent/instrumentation/resque/helper.rb +2 -2
  234. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +4 -5
  235. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +2 -3
  236. data/lib/new_relic/agent/instrumentation/resque.rb +17 -17
  237. data/lib/new_relic/agent/instrumentation/sequel.rb +16 -19
  238. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +2 -2
  239. data/lib/new_relic/agent/instrumentation/sidekiq/client.rb +20 -0
  240. data/lib/new_relic/agent/instrumentation/sidekiq/extensions/delayed_class.rb +30 -0
  241. data/lib/new_relic/agent/instrumentation/sidekiq/server.rb +37 -0
  242. data/lib/new_relic/agent/instrumentation/sidekiq.rb +24 -70
  243. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +1 -1
  244. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +2 -3
  245. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +5 -4
  246. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +1 -1
  247. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +2 -2
  248. data/lib/new_relic/agent/instrumentation/sinatra.rb +26 -17
  249. data/lib/new_relic/agent/instrumentation/thread/chain.rb +24 -0
  250. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +28 -0
  251. data/lib/new_relic/agent/instrumentation/thread/prepend.rb +22 -0
  252. data/lib/new_relic/agent/instrumentation/thread.rb +20 -0
  253. data/lib/new_relic/agent/instrumentation/tilt/chain.rb +1 -1
  254. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +2 -2
  255. data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +1 -1
  256. data/lib/new_relic/agent/instrumentation/tilt.rb +4 -4
  257. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +5 -5
  258. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +13 -15
  259. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +2 -2
  260. data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
  261. data/lib/new_relic/agent/instrumentation.rb +1 -1
  262. data/lib/new_relic/agent/internal_agent_error.rb +2 -2
  263. data/lib/new_relic/agent/javascript_instrumentor.rb +38 -37
  264. data/lib/new_relic/agent/linking_metadata.rb +44 -0
  265. data/lib/new_relic/agent/local_log_decorator.rb +37 -0
  266. data/lib/new_relic/agent/log_event_aggregator.rb +235 -0
  267. data/lib/new_relic/agent/log_once.rb +1 -1
  268. data/lib/new_relic/agent/log_priority.rb +20 -0
  269. data/lib/new_relic/agent/logging.rb +21 -17
  270. data/lib/new_relic/agent/memory_logger.rb +2 -2
  271. data/lib/new_relic/agent/messaging.rb +61 -63
  272. data/lib/new_relic/agent/method_tracer.rb +28 -22
  273. data/lib/new_relic/agent/method_tracer_helpers.rb +88 -11
  274. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +16 -16
  275. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +5 -4
  276. data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +1 -2
  277. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +6 -9
  278. data/lib/new_relic/agent/monitors.rb +6 -7
  279. data/lib/new_relic/agent/new_relic_service/encoders.rb +6 -6
  280. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +5 -5
  281. data/lib/new_relic/agent/new_relic_service/marshaller.rb +2 -2
  282. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +4 -4
  283. data/lib/new_relic/agent/new_relic_service.rb +242 -185
  284. data/lib/new_relic/agent/{noticible_error.rb → noticeable_error.rb} +2 -5
  285. data/lib/new_relic/agent/null_logger.rb +7 -3
  286. data/lib/new_relic/agent/obfuscator.rb +8 -10
  287. data/lib/new_relic/agent/parameter_filtering.rb +24 -10
  288. data/lib/new_relic/agent/payload_metric_mapping.rb +9 -10
  289. data/lib/new_relic/agent/pipe_channel_manager.rb +17 -11
  290. data/lib/new_relic/agent/pipe_service.rb +7 -4
  291. data/lib/new_relic/agent/prepend_supportability.rb +2 -2
  292. data/lib/new_relic/agent/priority_sampled_buffer.rb +8 -11
  293. data/lib/new_relic/agent/range_extensions.rb +8 -28
  294. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +11 -11
  295. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +12 -13
  296. data/lib/new_relic/agent/rules_engine.rb +5 -4
  297. data/lib/new_relic/agent/sampler.rb +3 -4
  298. data/lib/new_relic/agent/sampler_collection.rb +3 -4
  299. data/lib/new_relic/agent/samplers/cpu_sampler.rb +2 -1
  300. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +6 -6
  301. data/lib/new_relic/agent/samplers/memory_sampler.rb +24 -13
  302. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  303. data/lib/new_relic/agent/samplers/vm_sampler.rb +21 -19
  304. data/lib/new_relic/agent/span_event_aggregator.rb +10 -10
  305. data/lib/new_relic/agent/span_event_primitive.rb +62 -56
  306. data/lib/new_relic/agent/sql_sampler.rb +17 -17
  307. data/lib/new_relic/agent/stats.rb +78 -41
  308. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +9 -11
  309. data/lib/new_relic/agent/stats_engine/stats_hash.rb +12 -13
  310. data/lib/new_relic/agent/stats_engine.rb +7 -7
  311. data/lib/new_relic/agent/synthetics_event_aggregator.rb +7 -8
  312. data/lib/new_relic/agent/system_info.rb +85 -65
  313. data/lib/new_relic/agent/threading/agent_thread.rb +18 -14
  314. data/lib/new_relic/agent/threading/backtrace_node.rb +12 -13
  315. data/lib/new_relic/agent/threading/backtrace_service.rb +10 -9
  316. data/lib/new_relic/agent/threading/thread_profile.rb +22 -22
  317. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
  318. data/lib/new_relic/agent/tracer.rb +82 -56
  319. data/lib/new_relic/agent/transaction/abstract_segment.rb +100 -37
  320. data/lib/new_relic/agent/transaction/datastore_segment.rb +19 -18
  321. data/lib/new_relic/agent/transaction/distributed_tracer.rb +62 -56
  322. data/lib/new_relic/agent/transaction/distributed_tracing.rb +43 -44
  323. data/lib/new_relic/agent/transaction/external_request_segment.rb +41 -34
  324. data/lib/new_relic/agent/transaction/message_broker_segment.rb +30 -29
  325. data/lib/new_relic/agent/transaction/request_attributes.rb +35 -35
  326. data/lib/new_relic/agent/transaction/segment.rb +17 -10
  327. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -3
  328. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  329. data/lib/new_relic/agent/transaction/trace.rb +15 -11
  330. data/lib/new_relic/agent/transaction/trace_builder.rb +10 -10
  331. data/lib/new_relic/agent/transaction/trace_context.rb +35 -35
  332. data/lib/new_relic/agent/transaction/trace_node.rb +25 -24
  333. data/lib/new_relic/agent/transaction/tracing.rb +14 -11
  334. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +5 -5
  335. data/lib/new_relic/agent/transaction.rb +169 -125
  336. data/lib/new_relic/agent/transaction_error_primitive.rb +27 -25
  337. data/lib/new_relic/agent/transaction_event_aggregator.rb +12 -12
  338. data/lib/new_relic/agent/transaction_event_primitive.rb +32 -33
  339. data/lib/new_relic/agent/transaction_event_recorder.rb +16 -15
  340. data/lib/new_relic/agent/transaction_metrics.rb +10 -9
  341. data/lib/new_relic/agent/transaction_sampler.rb +5 -6
  342. data/lib/new_relic/agent/transaction_time_aggregator.rb +21 -20
  343. data/lib/new_relic/agent/utilization/aws.rb +33 -3
  344. data/lib/new_relic/agent/utilization/azure.rb +3 -3
  345. data/lib/new_relic/agent/utilization/gcp.rb +7 -7
  346. data/lib/new_relic/agent/utilization/pcf.rb +5 -4
  347. data/lib/new_relic/agent/utilization/vendor.rb +43 -28
  348. data/lib/new_relic/agent/utilization_data.rb +7 -5
  349. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
  350. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +2 -2
  351. data/lib/new_relic/agent/vm/mri_vm.rb +40 -15
  352. data/lib/new_relic/agent/vm/snapshot.rb +4 -4
  353. data/lib/new_relic/agent/vm.rb +1 -1
  354. data/lib/new_relic/agent/worker_loop.rb +5 -7
  355. data/lib/new_relic/agent.rb +62 -81
  356. data/lib/new_relic/cli/command.rb +20 -22
  357. data/lib/new_relic/cli/commands/deployments.rb +91 -41
  358. data/lib/new_relic/cli/commands/install.rb +21 -24
  359. data/lib/new_relic/coerce.rb +15 -13
  360. data/lib/new_relic/collection_helper.rb +50 -48
  361. data/lib/new_relic/constants.rb +2 -1
  362. data/lib/new_relic/control/class_methods.rb +3 -3
  363. data/lib/new_relic/control/frameworks/external.rb +2 -2
  364. data/lib/new_relic/control/frameworks/rails.rb +13 -9
  365. data/lib/new_relic/control/frameworks/rails3.rb +3 -4
  366. data/lib/new_relic/control/frameworks/rails4.rb +1 -1
  367. data/lib/new_relic/control/frameworks/rails_notifications.rb +1 -1
  368. data/lib/new_relic/control/frameworks/ruby.rb +3 -3
  369. data/lib/new_relic/control/frameworks/sinatra.rb +7 -1
  370. data/lib/new_relic/control/frameworks.rb +1 -1
  371. data/lib/new_relic/control/instance_methods.rb +26 -45
  372. data/lib/new_relic/control/instrumentation.rb +39 -11
  373. data/lib/new_relic/control/private_instance_methods.rb +48 -0
  374. data/lib/new_relic/control/server_methods.rb +3 -4
  375. data/lib/new_relic/control.rb +1 -2
  376. data/lib/new_relic/delayed_job_injection.rb +1 -1
  377. data/lib/new_relic/dependency_detection.rb +29 -28
  378. data/lib/new_relic/environment_report.rb +40 -32
  379. data/lib/new_relic/helper.rb +48 -7
  380. data/lib/new_relic/language_support.rb +29 -5
  381. data/lib/new_relic/latest_changes.rb +7 -6
  382. data/lib/new_relic/local_environment.rb +22 -26
  383. data/lib/new_relic/metric_data.rb +31 -26
  384. data/lib/new_relic/metric_spec.rb +8 -6
  385. data/lib/new_relic/noticed_error.rb +17 -21
  386. data/lib/new_relic/rack/agent_hooks.rb +1 -1
  387. data/lib/new_relic/rack/agent_middleware.rb +5 -3
  388. data/lib/new_relic/rack/browser_monitoring.rb +133 -123
  389. data/lib/new_relic/rack.rb +1 -1
  390. data/lib/new_relic/recipes/capistrano3.rb +3 -61
  391. data/lib/new_relic/recipes/capistrano_legacy.rb +23 -26
  392. data/lib/new_relic/recipes/helpers/send_deployment.rb +70 -0
  393. data/lib/new_relic/recipes.rb +1 -1
  394. data/lib/new_relic/supportability_helper.rb +8 -9
  395. data/lib/new_relic/traced_thread.rb +39 -0
  396. data/lib/new_relic/version.rb +6 -17
  397. data/lib/newrelic_rpm.rb +14 -3
  398. data/lib/sequel/extensions/{newrelic_instrumentation.rb → new_relic_instrumentation.rb} +15 -18
  399. data/lib/sequel/plugins/{newrelic_instrumentation.rb → new_relic_instrumentation.rb} +8 -14
  400. data/lib/tasks/all.rb +2 -2
  401. data/lib/tasks/config.rake +21 -117
  402. data/lib/tasks/coverage_report.rake +28 -0
  403. data/lib/tasks/helpers/format.rb +123 -0
  404. data/lib/tasks/helpers/matches.rb +12 -0
  405. data/lib/tasks/helpers/prompt.rb +24 -0
  406. data/lib/tasks/helpers/removers.rb +33 -0
  407. data/lib/tasks/install.rake +4 -0
  408. data/lib/tasks/instrumentation_generator/README.md +63 -0
  409. data/lib/tasks/instrumentation_generator/TODO.md +33 -0
  410. data/lib/tasks/instrumentation_generator/instrumentation.thor +121 -0
  411. data/lib/tasks/instrumentation_generator/templates/Envfile.tt +9 -0
  412. data/lib/tasks/instrumentation_generator/templates/chain.tt +22 -0
  413. data/lib/tasks/instrumentation_generator/templates/chain_method.tt +8 -0
  414. data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +29 -0
  415. data/lib/tasks/instrumentation_generator/templates/instrumentation.tt +13 -0
  416. data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +3 -0
  417. data/lib/tasks/instrumentation_generator/templates/newrelic.yml.tt +19 -0
  418. data/lib/tasks/instrumentation_generator/templates/prepend.tt +13 -0
  419. data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +3 -0
  420. data/lib/tasks/instrumentation_generator/templates/test.tt +15 -0
  421. data/lib/tasks/multiverse.rake +4 -0
  422. data/lib/tasks/multiverse.rb +5 -32
  423. data/lib/tasks/newrelic.rb +1 -1
  424. data/lib/tasks/tests.rake +10 -15
  425. data/newrelic.yml +544 -452
  426. data/newrelic_rpm.gemspec +35 -31
  427. data/recipes/newrelic.rb +2 -2
  428. data/test/agent_helper.rb +196 -180
  429. metadata +130 -102
  430. data/ROADMAP.md +0 -24
  431. data/bin/mongrel_rpm +0 -33
  432. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +0 -44
  433. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +0 -75
  434. data/lib/new_relic/agent/instrumentation/authlogic.rb +0 -25
  435. data/lib/new_relic/agent/instrumentation/data_mapper.rb +0 -204
  436. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +0 -26
  437. data/lib/new_relic/agent/instrumentation/sunspot.rb +0 -33
  438. /data/lib/tasks/{config.html.erb → helpers/config.html.erb} +0 -0
  439. /data/lib/tasks/{config.text.erb → helpers/config.text.erb} +0 -0
data/test/agent_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
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.
@@ -13,49 +13,28 @@ rescue LoadError
13
13
  # NOP -- Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
14
14
  end
15
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
29
-
30
16
  class ArrayLogDevice
31
- def initialize array=[]
17
+ def initialize(array = [])
32
18
  @array = array
33
19
  end
34
20
  attr_reader :array
35
21
 
36
- def write message
22
+ def write(message)
37
23
  @array << message
38
24
  end
39
25
 
40
26
  def close; end
41
27
  end
42
28
 
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
29
+ def fake_guid(length = 16)
30
+ NewRelic::Agent::GuidGenerator.generate_guid(length)
52
31
  end
53
32
 
54
- def assert_between floor, ceiling, value, message="expected #{floor} <= #{value} <= #{ceiling}"
33
+ def assert_between(floor, ceiling, value, message = "expected #{floor} <= #{value} <= #{ceiling}")
55
34
  assert((floor <= value && value <= ceiling), message)
56
35
  end
57
36
 
58
- def assert_in_delta expected, actual, delta
37
+ def assert_in_delta(expected, actual, delta)
59
38
  assert_between((expected - delta), (expected + delta), actual)
60
39
  end
61
40
 
@@ -67,10 +46,10 @@ def reset_error_traces!
67
46
  NewRelic::Agent.instance.error_collector.error_trace_aggregator.reset!
68
47
  end
69
48
 
70
- def assert_has_traced_error error_class
49
+ def assert_has_traced_error(error_class)
71
50
  errors = harvest_error_traces!
72
- assert \
73
- errors.find {|e| e.exception_class_name == error_class.name} != nil, \
51
+
52
+ refute_nil errors.find { |e| e.exception_class_name == error_class.name }, \
74
53
  "Didn't find error of class #{error_class}"
75
54
  end
76
55
 
@@ -102,51 +81,48 @@ def last_error_event
102
81
  harvest_error_events!.last.last
103
82
  end
104
83
 
105
- unless defined? assert_block
106
- def assert_block *msgs
107
- assert yield, *msgs
108
- end
109
- end
110
-
111
84
  unless defined? assert_includes
112
- def assert_includes collection, member, msg=nil
85
+ def assert_includes(collection, member, msg = nil)
113
86
  msg = "Expected #{collection.inspect} to include #{member.inspect}"
114
- assert_block( msg ) { collection.include?(member) }
87
+
88
+ assert_includes collection, member, msg
115
89
  end
116
90
  end
117
91
 
118
92
  unless defined? assert_not_includes
119
- def assert_not_includes collection, member, msg=nil
93
+ def assert_not_includes(collection, member, msg = nil)
120
94
  msg = "Expected #{collection.inspect} not to include #{member.inspect}"
121
- assert !collection.include?(member), msg
95
+
96
+ refute_includes collection, member, msg
122
97
  end
123
98
  end
124
99
 
125
100
  unless defined? assert_empty
126
- def assert_empty collection, msg=nil
127
- assert collection.empty?, msg
101
+ def assert_empty(collection, msg = nil)
102
+ assert_empty collection, msg
128
103
  end
129
104
  end
130
105
 
131
- def assert_equal_unordered left, right
106
+ def assert_equal_unordered(left, right)
132
107
  assert_equal(left.length, right.length, "Lengths don't match. #{left.length} != #{right.length}")
133
108
  left.each { |element| assert_includes(right, element) }
134
109
  end
135
110
 
136
111
  def assert_log_contains(log, message)
137
112
  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
113
+
114
+ assert (lines.any? { |line| line.match(message) })
140
115
  end
141
116
 
142
- def assert_audit_log_contains audit_log_contents, needle
117
+ def assert_audit_log_contains(audit_log_contents, needle)
143
118
  # Original request bodies dumped to the log have symbol keys, but once
144
119
  # they go through a dump/load, they're strings again, so we strip
145
120
  # double-quotes and colons from the log, and the strings we searching for.
146
121
  regex = /[:"]/
147
122
  needle = needle.gsub(regex, '')
148
123
  haystack = audit_log_contents.gsub(regex, '')
149
- assert(haystack.include?(needle), "Expected log to contain '#{needle}'")
124
+
125
+ assert_includes(haystack, needle, "Expected log to contain '#{needle}'")
150
126
  end
151
127
 
152
128
  # Because we don't generate a strictly machine-readable representation of
@@ -157,53 +133,56 @@ end
157
133
  # orderings of the key/value pairs in Hashes that were embedded in the request
158
134
  # body). So, this method traverses an object graph and only makes assertions
159
135
  # about the terminal (non-Array-or-Hash) nodes therein.
160
- def assert_audit_log_contains_object audit_log_contents, o, format = :json
136
+ def assert_audit_log_contains_object(audit_log_contents, o, format = :json)
161
137
  case o
162
138
  when Hash
163
- o.each do |k,v|
139
+ o.each do |k, v|
164
140
  assert_audit_log_contains_object(audit_log_contents, v, format)
165
141
  assert_audit_log_contains_object(audit_log_contents, k, format)
166
142
  end
167
143
  when Array
144
+
168
145
  o.each do |el|
169
146
  assert_audit_log_contains_object(audit_log_contents, el, format)
170
147
  end
171
148
  when NilClass
149
+
172
150
  assert_audit_log_contains(audit_log_contents, format == :json ? "null" : "nil")
173
151
  else
174
152
  assert_audit_log_contains(audit_log_contents, o.inspect)
175
153
  end
176
154
  end
177
155
 
178
- def compare_metrics expected, actual
179
- actual.delete_if {|a| a.include?('GC/Transaction/') }
156
+ def compare_metrics(expected, actual)
157
+ actual.delete_if { |a| a.include?('GC/Transaction/') }
158
+
180
159
  assert_equal(expected.to_a.sort, actual.to_a.sort, "extra: #{(actual - expected).to_a.inspect}; missing: #{(expected - actual).to_a.inspect}")
181
160
  end
182
161
 
183
- def metric_spec_from_specish specish
162
+ def metric_spec_from_specish(specish)
184
163
  spec = case specish
185
164
  when String then NewRelic::MetricSpec.new(specish)
186
- when Array then NewRelic::MetricSpec.new(*specish)
165
+ when Array then NewRelic::MetricSpec.new(*specish)
187
166
  end
188
167
  spec
189
168
  end
190
169
 
191
- def _normalize_metric_expectations expectations
170
+ def _normalize_metric_expectations(expectations)
192
171
  case expectations
193
172
  when Array
194
173
  hash = {}
195
174
  # Just assert that the metric is present, nothing about the attributes
196
- expectations.each { |k| hash[k] = { } }
175
+ expectations.each { |k| hash[k] = {} }
197
176
  hash
198
177
  when String
199
- { expectations => {} }
178
+ {expectations => {}}
200
179
  else
201
180
  expectations
202
181
  end
203
182
  end
204
183
 
205
- def dump_stats stats
206
- str = " Call count: #{stats.call_count}\n"
184
+ def dump_stats(stats)
185
+ str = String.new(" Call count: #{stats.call_count}\n")
207
186
  str << " Total call time: #{stats.total_call_time}\n"
208
187
  str << " Total exclusive time: #{stats.total_exclusive_time}\n"
209
188
  str << " Min call time: #{stats.min_call_time}\n"
@@ -215,20 +194,35 @@ def dump_stats stats
215
194
  str
216
195
  end
217
196
 
218
- def assert_stats_has_values stats, expected_spec, expected_attrs
197
+ def assert_stats_has_values(stats, expected_spec, expected_attrs)
219
198
  expected_attrs.each do |attr, expected_value|
220
199
  actual_value = stats.send(attr)
200
+
201
+ msg = "Expected #{attr} for #{expected_spec} to be #{'~' unless attr == :call_count}#{expected_value}, " \
202
+ "got #{actual_value}.\nActual stats:\n#{dump_stats(stats)}"
203
+
221
204
  if attr == :call_count
222
- assert_equal(expected_value, actual_value,
223
- "Expected #{attr} for #{expected_spec} to be #{expected_value}, got #{actual_value}.\nActual stats:\n#{dump_stats(stats)}")
205
+ assert_stats_has_values_with_call_count(expected_value, actual_value, msg)
224
206
  else
225
- assert_in_delta(expected_value, actual_value, 0.0001,
226
- "Expected #{attr} for #{expected_spec} to be ~#{expected_value}, got #{actual_value}.\nActual stats:\n#{dump_stats(stats)}")
207
+ assert_in_delta(expected_value, actual_value, 0.0001, msg)
227
208
  end
228
209
  end
229
210
  end
230
211
 
231
- def assert_metrics_recorded expected
212
+ def assert_stats_has_values_with_call_count(expected_value, actual_value, msg)
213
+ # >, <, >=, <= comparisons
214
+ if expected_value.to_s =~ /([<>]=?)\s*(\d+)/
215
+ operator = Regexp.last_match(1).to_sym
216
+ count = Regexp.last_match(2).to_i
217
+
218
+ assert_operator(actual_value, operator, count, msg)
219
+ # == comparison
220
+ else
221
+ assert_equal(expected_value, actual_value, msg)
222
+ end
223
+ end
224
+
225
+ def assert_metrics_recorded(expected)
232
226
  expected = _normalize_metric_expectations(expected)
233
227
  expected.each do |specish, expected_attrs|
234
228
  expected_spec = metric_spec_from_specish(specish)
@@ -244,6 +238,7 @@ def assert_metrics_recorded expected
244
238
 
245
239
  assert(actual_stats, msg)
246
240
  end
241
+
247
242
  assert_stats_has_values(actual_stats, expected_spec, expected_attrs)
248
243
  end
249
244
  end
@@ -259,8 +254,9 @@ end
259
254
  # the :ignore_filter option. This will allow you to specify a Regex that
260
255
  # allowlists broad swathes of metric territory (e.g. 'Supportability/').
261
256
  #
262
- def assert_metrics_recorded_exclusive expected, options={}
257
+ def assert_metrics_recorded_exclusive(expected, options = {})
263
258
  expected = _normalize_metric_expectations(expected)
259
+
264
260
  assert_metrics_recorded(expected)
265
261
 
266
262
  recorded_metrics = NewRelic::Agent.instance.stats_engine.to_h.keys
@@ -272,14 +268,23 @@ def assert_metrics_recorded_exclusive expected, options={}
272
268
  recorded_metrics.reject! { |m| m.name.match(options[:ignore_filter]) }
273
269
  end
274
270
 
275
- expected_metrics = expected.keys.map { |s| metric_spec_from_specish(s) }
271
+ expected_metrics = expected.keys.map { |s| metric_spec_from_specish(s) }
276
272
 
277
273
  unexpected_metrics = recorded_metrics - expected_metrics
278
- unexpected_metrics.reject! { |m| m.name =~ /GC\/Transaction/ }
274
+ unexpected_metrics.reject! { |m| m.name.include?('GC/Transaction') }
279
275
 
280
276
  assert_equal(0, unexpected_metrics.size, "Found unexpected metrics: #{format_metric_spec_list(unexpected_metrics)}")
281
277
  end
282
278
 
279
+ def assert_newrelic_metadata_present(metadata)
280
+ assert metadata.key?('newrelic')
281
+ refute_nil metadata['newrelic']
282
+ end
283
+
284
+ def assert_distributed_tracing_payload_created_for_transaction(transaction)
285
+ assert transaction.distributed_tracer.instance_variable_get(:@distributed_trace_payload_created)
286
+ end
287
+
283
288
  # The clear_metrics! method prevents metrics from "leaking" between tests by resetting
284
289
  # the @stats_hash instance variable in the current instance of NewRelic::Agent::StatsEngine.
285
290
 
@@ -297,7 +302,7 @@ def clear_metrics!
297
302
  NewRelic::Agent.instance.stats_engine.reset_for_test!
298
303
  end
299
304
 
300
- def assert_metrics_not_recorded not_expected
305
+ def assert_metrics_not_recorded(not_expected)
301
306
  not_expected = _normalize_metric_expectations(not_expected)
302
307
  found_but_not_expected = []
303
308
  not_expected.each do |specish, _|
@@ -306,46 +311,48 @@ def assert_metrics_not_recorded not_expected
306
311
  found_but_not_expected << spec
307
312
  end
308
313
  end
309
- assert_equal([], found_but_not_expected, "Found unexpected metrics: #{format_metric_spec_list(found_but_not_expected)}")
314
+
315
+ assert_empty(found_but_not_expected, "Found unexpected metrics: #{format_metric_spec_list(found_but_not_expected)}")
310
316
  end
311
317
 
312
318
  alias :refute_metrics_recorded :assert_metrics_not_recorded
313
319
 
314
- def assert_no_metrics_match regex
320
+ def assert_no_metrics_match(regex)
315
321
  matching_metrics = []
316
322
  NewRelic::Agent.instance.stats_engine.to_h.keys.map(&:to_s).each do |metric|
317
- matching_metrics << metric if metric.match regex
323
+ matching_metrics << metric if metric.match(regex)
318
324
  end
319
325
 
320
- assert_equal(
321
- [],
326
+ assert_empty(
322
327
  matching_metrics,
323
- "Found unexpected metrics:\n" + matching_metrics.map { |m| " '#{m}'"}.join("\n") + "\n\n"
328
+ "Found unexpected metrics:\n" + matching_metrics.map { |m| " '#{m}'" }.join("\n") + "\n\n"
324
329
  )
325
330
  end
326
331
 
327
332
  alias :refute_metrics_match :assert_no_metrics_match
328
333
 
329
- def format_metric_spec_list specs
334
+ def format_metric_spec_list(specs)
330
335
  spec_strings = specs.map do |spec|
331
336
  "#{spec.name} (#{spec.scope.empty? ? '<unscoped>' : spec.scope})"
332
337
  end
333
338
  "[\n #{spec_strings.join(",\n ")}\n]"
334
339
  end
335
340
 
336
- def assert_truthy expected, msg=nil
341
+ def assert_truthy(expected, msg = nil)
337
342
  msg ||= "Expected #{expected.inspect} to be truthy"
338
- assert !!expected, msg
343
+
344
+ refute !expected, msg
339
345
  end
340
346
 
341
- def assert_falsy expected, msg=nil
347
+ def assert_falsy(expected, msg = nil)
342
348
  msg ||= "Expected #{expected.inspect} to be falsy"
343
- assert !expected, msg
349
+
350
+ refute expected, msg
344
351
  end
345
352
 
346
353
  unless defined? assert_false
347
- def assert_false expected
348
- assert_equal false, expected
354
+ def assert_false(expected)
355
+ refute expected
349
356
  end
350
357
  end
351
358
 
@@ -371,27 +378,26 @@ end
371
378
  # With a transaction name plus category:
372
379
  # in_transaction('foobar', :category => :controller) { ... }
373
380
  #
374
- def in_transaction *args, &blk
375
- opts = (args.last && args.last.is_a?(Hash)) ? args.pop : {}
381
+ def in_transaction(*args, &blk)
382
+ opts = args.last && args.last.is_a?(Hash) ? args.pop : {}
376
383
  category = (opts && opts.delete(:category)) || :other
377
384
 
378
385
  # At least one test passes `:transaction_name => nil`, so handle it gently
379
- name = opts.key?(:transaction_name) ? opts.delete(:transaction_name) :
380
- args.first || 'dummy'
386
+ name = opts.key?(:transaction_name) ? opts.delete(:transaction_name) : args.first || 'dummy'
381
387
 
382
388
  state = NewRelic::Agent::Tracer.state
383
389
  txn = nil
384
390
 
385
391
  NewRelic::Agent::Tracer.in_transaction(name: name, category: category, options: opts) do
386
392
  txn = state.current_transaction
387
- yield state.current_transaction
393
+ yield(state.current_transaction)
388
394
  end
389
395
 
390
396
  txn
391
397
  end
392
398
 
393
399
  # Temporarily disables default transformer so tests with invalid inputs can be tried
394
- def with_disabled_defaults_transformer key
400
+ def with_disabled_defaults_transformer(key)
395
401
  begin
396
402
  transformer = NewRelic::Agent::Configuration::DEFAULTS[key][:transform]
397
403
  NewRelic::Agent::Configuration::DEFAULTS[key][:transform] = nil
@@ -402,13 +408,13 @@ def with_disabled_defaults_transformer key
402
408
  end
403
409
 
404
410
  # Convenience wrapper to stand up a transaction and provide a segment within
405
- # that transaction to work with. The same arguements as provided to in_transaction
411
+ # that transaction to work with. The same arguments as provided to in_transaction
406
412
  # may be supplied.
407
- def with_segment *args, &blk
413
+ def with_segment(*args, &blk)
408
414
  segment = nil
409
- txn = in_transaction(*args) do |txn|
410
- segment = txn.current_segment
411
- yield segment, txn
415
+ txn = in_transaction(*args) do |t|
416
+ segment = t.current_segment
417
+ yield(segment, t)
412
418
  end
413
419
  [segment, txn]
414
420
  end
@@ -416,9 +422,10 @@ end
416
422
  # building error attributes on segments are deferred until it's time
417
423
  # to publish/harvest them as spans, so for testing, we'll explicitly
418
424
  # build 'em as appropriate so we can test 'em
419
- def build_deferred_error_attributes segment
425
+ def build_deferred_error_attributes(segment)
420
426
  return unless segment.noticed_error
421
427
  return if segment.noticed_error_attributes.frozen?
428
+
422
429
  segment.noticed_error.build_error_attributes
423
430
  end
424
431
 
@@ -431,30 +438,30 @@ def capture_segment_with_error
431
438
  end
432
439
  rescue Exception => exception
433
440
  assert segment_with_error, "expected to have a segment_with_error"
434
- build_deferred_error_attributes segment_with_error
441
+ build_deferred_error_attributes(segment_with_error)
435
442
  return segment_with_error, exception
436
443
  end
437
444
  end
438
445
 
439
- def stub_transaction_guid guid
446
+ def stub_transaction_guid(guid)
440
447
  NewRelic::Agent::Transaction.tl_current.instance_variable_set(:@guid, guid)
441
448
  end
442
449
 
443
450
  # Convenience wrapper around in_transaction that sets the category so that it
444
451
  # looks like we are in a web transaction
445
- def in_web_transaction name='dummy'
452
+ def in_web_transaction(name = 'dummy')
446
453
  in_transaction(name, :category => :controller, :request => stub(:path => '/')) do |txn|
447
- yield txn
454
+ yield(txn)
448
455
  end
449
456
  end
450
457
 
451
- def in_background_transaction name='silly'
458
+ def in_background_transaction(name = 'silly')
452
459
  in_transaction(name, :category => :task) do |txn|
453
- yield txn
460
+ yield(txn)
454
461
  end
455
462
  end
456
463
 
457
- def refute_contains_request_params attributes
464
+ def refute_contains_request_params(attributes)
458
465
  attributes.keys.each do |key|
459
466
  refute_match(/^request\.parameters\./, key.to_s)
460
467
  end
@@ -462,6 +469,7 @@ end
462
469
 
463
470
  def last_transaction_trace
464
471
  return unless last_sample = NewRelic::Agent.agent.transaction_sampler.last_sample
472
+
465
473
  NewRelic::Agent::Transaction::TraceBuilder.build_trace(last_sample)
466
474
  end
467
475
 
@@ -473,7 +481,7 @@ def last_transaction_trace_request_params
473
481
  end
474
482
  end
475
483
 
476
- def find_sql_trace metric_name
484
+ def find_sql_trace(metric_name)
477
485
  NewRelic::Agent.agent.sql_sampler.sql_traces.values.detect do |trace|
478
486
  trace.database_metric_name == metric_name
479
487
  end
@@ -483,7 +491,7 @@ def last_sql_trace
483
491
  NewRelic::Agent.agent.sql_sampler.sql_traces.values.last
484
492
  end
485
493
 
486
- def find_last_transaction_node transaction_sample=nil
494
+ def find_last_transaction_node(transaction_sample = nil)
487
495
  if transaction_sample
488
496
  root_node = transaction_sample.root_node
489
497
  else
@@ -491,12 +499,12 @@ def find_last_transaction_node transaction_sample=nil
491
499
  end
492
500
 
493
501
  last_node = nil
494
- root_node.each_node {|s| last_node = s }
502
+ root_node.each_node { |s| last_node = s }
495
503
 
496
504
  return last_node
497
505
  end
498
506
 
499
- def find_node_with_name transaction_sample, name
507
+ def find_node_with_name(transaction_sample, name)
500
508
  transaction_sample.root_node.each_node do |node|
501
509
  if node.metric_name == name
502
510
  return node
@@ -506,9 +514,9 @@ def find_node_with_name transaction_sample, name
506
514
  nil
507
515
  end
508
516
 
509
- def find_node_with_name_matching transaction_sample, regex
517
+ def find_node_with_name_matching(transaction_sample, regex)
510
518
  transaction_sample.root_node.each_node do |node|
511
- if node.metric_name.match regex
519
+ if node.metric_name.match(regex)
512
520
  return node
513
521
  end
514
522
  end
@@ -516,13 +524,13 @@ def find_node_with_name_matching transaction_sample, regex
516
524
  nil
517
525
  end
518
526
 
519
- def find_all_nodes_with_name_matching transaction_sample, regexes
527
+ def find_all_nodes_with_name_matching(transaction_sample, regexes)
520
528
  regexes = [regexes].flatten
521
529
  matching_nodes = []
522
530
 
523
531
  transaction_sample.root_node.each_node do |node|
524
532
  regexes.each do |regex|
525
- if node.metric_name.match regex
533
+ if node.metric_name.match(regex)
526
534
  matching_nodes << node
527
535
  end
528
536
  end
@@ -531,7 +539,7 @@ def find_all_nodes_with_name_matching transaction_sample, regexes
531
539
  matching_nodes
532
540
  end
533
541
 
534
- def with_config config_hash, at_start=true
542
+ def with_config(config_hash, at_start = true)
535
543
  config = NewRelic::Agent::Configuration::DottedHash.new(config_hash, true)
536
544
  NewRelic::Agent.config.add_config_for_testing(config, at_start)
537
545
  NewRelic::Agent.instance.refresh_attribute_filter
@@ -543,20 +551,20 @@ def with_config config_hash, at_start=true
543
551
  end
544
552
  end
545
553
 
546
- def with_server_source config_hash, at_start=true
547
- with_config config_hash, at_start do
554
+ def with_server_source(config_hash, at_start = true)
555
+ with_config(config_hash, at_start) do
548
556
  NewRelic::Agent.config.notify_server_source_added
549
557
  yield
550
558
  end
551
559
  end
552
560
 
553
- def with_config_low_priority config_hash
561
+ def with_config_low_priority(config_hash)
554
562
  with_config(config_hash, false) do
555
563
  yield
556
564
  end
557
565
  end
558
566
 
559
- def with_transaction_renaming_rules rule_specs
567
+ def with_transaction_renaming_rules(rule_specs)
560
568
  original_engine = NewRelic::Agent.agent.instance_variable_get(:@transaction_rules)
561
569
  begin
562
570
  new_engine = NewRelic::Agent::RulesEngine.create_transaction_rules('transaction_name_rules' => rule_specs)
@@ -582,7 +590,7 @@ unless Time.respond_to?(:__original_now)
582
590
  end
583
591
  end
584
592
 
585
- def nr_freeze_time now=Time.now
593
+ def nr_freeze_time(now = Time.now)
586
594
  Time.__frozen_now = now
587
595
  end
588
596
 
@@ -590,7 +598,7 @@ def nr_unfreeze_time
590
598
  Time.__frozen_now = nil
591
599
  end
592
600
 
593
- def advance_time seconds
601
+ def advance_time(seconds)
594
602
  Time.__frozen_now = Time.now + seconds
595
603
  end
596
604
 
@@ -607,11 +615,11 @@ unless Process.respond_to?(:__original_clock_gettime)
607
615
  end
608
616
  end
609
617
 
610
- def advance_process_time(seconds, clock_id=Process::CLOCK_REALTIME)
618
+ def advance_process_time(seconds, clock_id = Process::CLOCK_REALTIME)
611
619
  Process.__frozen_clock_gettime = Process.clock_gettime(clock_id) + seconds
612
620
  end
613
621
 
614
- def nr_freeze_process_time(now=Process.clock_gettime(Process::CLOCK_REALTIME))
622
+ def nr_freeze_process_time(now = Process.clock_gettime(Process::CLOCK_REALTIME))
615
623
  Process.__frozen_clock_gettime = now
616
624
  end
617
625
 
@@ -619,7 +627,7 @@ def nr_unfreeze_process_time
619
627
  Process.__frozen_clock_gettime = nil
620
628
  end
621
629
 
622
- def with_constant_defined constant_symbol, implementation=Module.new
630
+ def with_constant_defined(constant_symbol, implementation = Module.new)
623
631
  const_path = constant_path(constant_symbol.to_s)
624
632
 
625
633
  if const_path
@@ -639,7 +647,7 @@ def with_constant_defined constant_symbol, implementation=Module.new
639
647
  end
640
648
  end
641
649
 
642
- def constant_path name, opts={}
650
+ def constant_path(name, opts = {})
643
651
  allow_partial = opts[:allow_partial]
644
652
  path = [Object]
645
653
  parts = name.gsub(/^::/, '').split('::')
@@ -647,22 +655,24 @@ def constant_path name, opts={}
647
655
  if !path.last.constants.include?(part.to_sym)
648
656
  return allow_partial ? path : nil
649
657
  end
658
+
650
659
  path << path.last.const_get(part)
651
660
  end
652
661
  path
653
662
  end
654
663
 
655
- def get_parent constant_name
664
+ def get_parent(constant_name)
656
665
  parent_name = constant_name.gsub(/::[^:]*$/, '')
657
666
  const_path = constant_path(parent_name)
658
667
  const_path ? const_path[-1] : nil
659
668
  end
660
669
 
661
- def undefine_constant constant_symbol
670
+ def undefine_constant(constant_symbol)
662
671
  const_str = constant_symbol.to_s
663
672
  parent = get_parent(const_str)
664
673
  const_name = const_str.gsub(/.*::/, '')
665
674
  return yield unless parent && parent.constants.include?(const_name.to_sym)
675
+
666
676
  removed_constant = parent.send(:remove_const, const_name)
667
677
  yield
668
678
  ensure
@@ -673,7 +683,7 @@ def with_debug_logging
673
683
  orig_logger = NewRelic::Agent.logger
674
684
  $stderr.puts '', '---', ''
675
685
  NewRelic::Agent.logger =
676
- NewRelic::Agent::AgentLogger.new('', Logger.new($stderr) )
686
+ NewRelic::Agent::AgentLogger.new('', Logger.new($stderr))
677
687
 
678
688
  with_config(:log_level => 'debug') do
679
689
  yield
@@ -682,11 +692,11 @@ ensure
682
692
  NewRelic::Agent.logger = orig_logger
683
693
  end
684
694
 
685
- def create_agent_command args={}
686
- NewRelic::Agent::Commands::AgentCommand.new([-1, { "name" => "command_name", "arguments" => args}])
695
+ def create_agent_command(args = {})
696
+ NewRelic::Agent::Commands::AgentCommand.new([-1, {"name" => "command_name", "arguments" => args}])
687
697
  end
688
698
 
689
- def wait_for_backtrace_service_poll opts={}
699
+ def wait_for_backtrace_service_poll(opts = {})
690
700
  defaults = {
691
701
  :timeout => 10.0,
692
702
  :service => NewRelic::Agent.agent.agent_command_router.backtrace_service,
@@ -703,18 +713,18 @@ def wait_for_backtrace_service_poll opts={}
703
713
  sleep(0.01)
704
714
  if Process.clock_gettime(Process::CLOCK_REALTIME) > deadline
705
715
  raise "Timed out waiting #{opts[:timeout]} s for backtrace service poll\n" +
706
- "Worker loop ran for #{opts[:service].worker_loop.iterations} iterations\n\n" +
707
- Thread.list.map { |t|
708
- "#{t.to_s}: newrelic_label: #{t[:newrelic_label].inspect}\n\n" +
709
- (t.backtrace || []).join("\n\t")
710
- }.join("\n\n")
716
+ "Worker loop ran for #{opts[:service].worker_loop.iterations} iterations\n\n" +
717
+ Thread.list.map { |t|
718
+ "#{t.to_s}: newrelic_label: #{t[:newrelic_label].inspect}\n\n" +
719
+ (t.backtrace || []).join("\n\t")
720
+ }.join("\n\n")
711
721
  end
712
722
  end
713
723
  end
714
724
 
715
- def with_array_logger level=:info
725
+ def with_array_logger(level = :info)
716
726
  orig_logger = NewRelic::Agent.logger
717
- config = { :log_level => level }
727
+ config = {:log_level => level}
718
728
  logdev = ArrayLogDevice.new
719
729
  override_logger = Logger.new(logdev)
720
730
 
@@ -749,7 +759,7 @@ class EnvUpdater
749
759
 
750
760
  # Will attempt the given block up to MAX_RETRIES before
751
761
  # surfacing the exception down the chain.
752
- def with_retry retry_limit=MAX_RETRIES
762
+ def with_retry(retry_limit = MAX_RETRIES)
753
763
  retries ||= 0
754
764
  sleep(retries)
755
765
  yield
@@ -758,19 +768,19 @@ class EnvUpdater
758
768
  end
759
769
 
760
770
  # Locks and updates the ENV
761
- def safe_update env
771
+ def safe_update(env)
762
772
  with_retry do
763
773
  @mutex.synchronize do
764
- env.each{ |key, val| ENV[key] = val.to_s }
774
+ env.each { |key, val| ENV[key] = val.to_s }
765
775
  end
766
776
  end
767
777
  end
768
778
 
769
779
  # Locks and restores the ENV
770
- def safe_restore old_env
780
+ def safe_restore(old_env)
771
781
  with_retry do
772
782
  @mutex.synchronize do
773
- old_env.each{ |key, val| val ? ENV[key] = val : ENV.delete(key) }
783
+ old_env.each { |key, val| val ? ENV[key] = val : ENV.delete(key) }
774
784
  end
775
785
  end
776
786
  end
@@ -780,19 +790,19 @@ class EnvUpdater
780
790
  @@instance ||= EnvUpdater.new
781
791
  end
782
792
 
783
- def self.safe_update env
784
- instance.safe_update env
793
+ def self.safe_update(env)
794
+ instance.safe_update(env)
785
795
  end
786
796
 
787
- def self.safe_restore old_env
788
- instance.safe_restore old_env
797
+ def self.safe_restore(old_env)
798
+ instance.safe_restore(old_env)
789
799
  end
790
800
 
791
801
  # Effectively saves current ENV settings for given env's key/values,
792
802
  # runs given block, then restores ENV to original state before returning.
793
- def self.inject env, &block
803
+ def self.inject(env, &block)
794
804
  old_env = {}
795
- env.each{ |key, val| old_env[key] = ENV[key] }
805
+ env.each { |key, val| old_env[key] = ENV[key] }
796
806
  begin
797
807
  safe_update(env)
798
808
  yield
@@ -807,11 +817,11 @@ end
807
817
 
808
818
  # Changes ENV settings to given and runs given block and restores ENV
809
819
  # to original values before returning.
810
- def with_environment env, &block
820
+ def with_environment(env, &block)
811
821
  EnvUpdater.inject(env) { yield }
812
822
  end
813
823
 
814
- def with_argv argv
824
+ def with_argv(argv)
815
825
  old_argv = ARGV.dup
816
826
  ARGV.clear
817
827
  ARGV.concat(argv)
@@ -824,7 +834,7 @@ def with_argv argv
824
834
  end
825
835
  end
826
836
 
827
- def with_ignore_error_filter filter, &blk
837
+ def with_ignore_error_filter(filter, &blk)
828
838
  original_filter = NewRelic::Agent.ignore_error_filter
829
839
  NewRelic::Agent.ignore_error_filter(&filter)
830
840
 
@@ -833,15 +843,15 @@ ensure
833
843
  NewRelic::Agent::ErrorCollector.ignore_error_filter = original_filter
834
844
  end
835
845
 
836
- def json_dump_and_encode object
837
- Base64.encode64(::JSON.dump(object))
846
+ def json_dump_and_encode(object)
847
+ Base64.encode64(JSON.dump(object))
838
848
  end
839
849
 
840
850
  def get_last_analytics_event
841
851
  NewRelic::Agent.agent.transaction_event_aggregator.harvest![1].last
842
852
  end
843
853
 
844
- def swap_instance_method target, method_name, new_method_implementation, &blk
854
+ def swap_instance_method(target, method_name, new_method_implementation, &blk)
845
855
  old_method_implementation = target.instance_method(method_name)
846
856
  target.send(:define_method, method_name, new_method_implementation)
847
857
  yield
@@ -856,22 +866,22 @@ def cross_agent_tests_dir
856
866
  File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'cross_agent_tests'))
857
867
  end
858
868
 
859
- def load_cross_agent_test name
869
+ def load_cross_agent_test(name)
860
870
  test_file_path = File.join(cross_agent_tests_dir, "#{name}.json")
861
871
  data = File.read(test_file_path)
862
872
  data.gsub!('callCount', 'call_count')
863
- data = ::JSON.load(data)
864
- data.each { |testcase| testcase['testname'].gsub! ' ', '_' if String === testcase['testname'] }
873
+ data = JSON.load(data)
874
+ data.each { |testcase| testcase['testname'].tr!(' ', '_') if String === testcase['testname'] }
865
875
  data
866
876
  end
867
877
 
868
- def each_cross_agent_test options
878
+ def each_cross_agent_test(options)
869
879
  options = {:dir => nil, :pattern => "*"}.update(options)
870
- path = File.join [cross_agent_tests_dir, options[:dir], options[:pattern]].compact
871
- Dir.glob(path).each { |file| yield file}
880
+ path = File.join([cross_agent_tests_dir, options[:dir], options[:pattern]].compact)
881
+ Dir.glob(path).each { |file| yield(file) }
872
882
  end
873
883
 
874
- def assert_event_attributes event, test_name, expected_attributes, non_expected_attributes
884
+ def assert_event_attributes(event, test_name, expected_attributes, non_expected_attributes)
875
885
  incorrect_attributes = []
876
886
 
877
887
  event_attrs = event[0]
@@ -881,7 +891,7 @@ def assert_event_attributes event, test_name, expected_attributes, non_expected_
881
891
  incorrect_attributes << name unless actual_value == expected_value
882
892
  end
883
893
 
884
- msg = "Found missing or incorrect attribute values in #{test_name}:\n"
894
+ msg = String.new("Found missing or incorrect attribute values in #{test_name}:\n")
885
895
 
886
896
  incorrect_attributes.each do |name|
887
897
  msg << " #{name}: expected = #{expected_attributes[name].inspect}, actual = #{event_attrs[name].inspect}\n"
@@ -892,19 +902,20 @@ def assert_event_attributes event, test_name, expected_attributes, non_expected_
892
902
  event_attrs.each do |name, actual_value|
893
903
  msg << " #{name}: #{actual_value.inspect}\n"
894
904
  end
895
- assert(incorrect_attributes.empty?, msg)
905
+
906
+ assert_empty(incorrect_attributes, msg)
896
907
 
897
908
  non_expected_attributes.each do |name|
898
909
  refute event_attrs[name], "Found value '#{event_attrs[name]}' for attribute '#{name}', but expected nothing in #{test_name}"
899
910
  end
900
911
  end
901
912
 
902
- def attributes_for sample, type
913
+ def attributes_for(sample, type)
903
914
  sample.attributes.instance_variable_get("@#{type}_attributes")
904
915
  end
905
916
 
906
917
  def uncache_trusted_account_key
907
- NewRelic::Agent::Transaction::TraceContext::AccountHelpers.instance_variable_set :@trace_state_entry_key, nil
918
+ NewRelic::Agent::Transaction::TraceContext::AccountHelpers.instance_variable_set(:@trace_state_entry_key, nil)
908
919
  end
909
920
 
910
921
  def reset_buffers_and_caches
@@ -912,7 +923,7 @@ def reset_buffers_and_caches
912
923
  uncache_trusted_account_key
913
924
  end
914
925
 
915
- def message_for_status_code code
926
+ def message_for_status_code(code)
916
927
  # Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
917
928
  if defined?(Net::HTTP::STATUS_CODES)
918
929
  return Net::HTTP::STATUS_CODES[code]
@@ -930,18 +941,19 @@ end
930
941
  # http status code associated with it.
931
942
  # a "status_code" may be passed in the headers to alter the HTTP Status Code
932
943
  # that is wrapped in the response.
933
- def mock_http_response headers, wrap_it=true
944
+ def mock_http_response(headers, wrap_it = true)
934
945
  status_code = (headers.delete("status_code") || 200).to_i
935
946
  net_http_resp = Net::HTTPResponse.new(1.0, status_code, message_for_status_code(status_code))
936
947
  headers.each do |key, value|
937
- net_http_resp.add_field key.to_s, value
948
+ net_http_resp.add_field(key.to_s, value)
938
949
  end
939
950
  return net_http_resp unless wrap_it
951
+
940
952
  NewRelic::Agent::HTTPClients::NetHTTPResponse.new(net_http_resp)
941
953
  end
942
954
 
943
955
  # +expected+ can be a string or regular expression
944
- def assert_match_or_equal expected, value
956
+ def assert_match_or_equal(expected, value)
945
957
  if expected.is_a?(Regexp)
946
958
  assert_match expected, value
947
959
  else
@@ -951,8 +963,9 @@ end
951
963
 
952
964
  # selects the last segment with a noticed_error and checks
953
965
  # the expectations against it.
954
- def assert_segment_noticed_error txn, segment_name, error_classes, error_message
955
- error_segment = txn.segments.reverse.detect{|s| s.noticed_error}
966
+ def assert_segment_noticed_error(txn, segment_name, error_classes, error_message)
967
+ error_segment = txn.segments.reverse.detect { |s| s.noticed_error }
968
+
956
969
  assert error_segment, "Expected at least one segment with a noticed_error"
957
970
 
958
971
  assert_match_or_equal segment_name, error_segment.name
@@ -963,48 +976,51 @@ def assert_segment_noticed_error txn, segment_name, error_classes, error_message
963
976
  assert_match_or_equal error_message, noticed_error.message
964
977
  end
965
978
 
966
- def assert_transaction_noticed_error txn, error_classes
979
+ def assert_transaction_noticed_error(txn, error_classes)
967
980
  refute_empty txn.exceptions, "Expected transaction to notice the error"
968
981
  assert_match_or_equal error_classes, txn.exceptions.keys.first.class.name
969
982
  end
970
983
 
971
- def refute_transaction_noticed_error txn, error_class
972
- error_segment = txn.segments.reverse.detect{|s| s.noticed_error}
984
+ def refute_transaction_noticed_error(txn, error_class)
985
+ error_segment = txn.segments.reverse.detect { |s| s.noticed_error }
986
+
973
987
  assert error_segment, "Expected at least one segment with a noticed_error"
974
988
  assert_empty txn.exceptions, "Expected transaction to NOT notice any segment errors"
975
989
  end
976
990
 
977
- def refute_raises *exp
991
+ def refute_raises(*exp)
978
992
  msg = "#{exp.pop}.\n" if String === exp.last
979
993
 
980
994
  begin
981
995
  yield
982
996
  rescue MiniTest::Skip => e
983
997
  puts "SKIP REPORTS: #{e.inspect}"
984
- return e if exp.include? MiniTest::Skip
998
+ return e if exp.include?(MiniTest::Skip)
999
+
985
1000
  raise e
986
1001
  rescue Exception => e
987
1002
  puts "EXCEPTION RAISED: #{e.inspect}\n#{e.backtrace}"
988
1003
  exp = exp.first if exp.size == 1
989
- flunk msg || "unexpected exception raised: #{e}"
1004
+
1005
+ flunk(msg || "unexpected exception raised: #{e}")
990
1006
  end
991
1007
  end
992
1008
 
993
- def assert_implements instance, method, *args
1009
+ def assert_implements(instance, method, *args)
994
1010
  fail_message = "expected #{instance.class}##{method} method to be implemented"
995
1011
  refute_raises NotImplementedError, fail_message do
996
1012
  instance.send(method, *args)
997
1013
  end
998
1014
  end
999
1015
 
1000
- def defer_testing_to_min_supported_rails test_file, min_rails_version, supports_jruby=true
1001
- if defined?(::Rails) &&
1002
- defined?(::Rails::VERSION::STRING) &&
1003
- (::Rails::VERSION::STRING.to_f >= min_rails_version) &&
1004
- (supports_jruby || !NewRelic::LanguageSupport.jruby?)
1016
+ def defer_testing_to_min_supported_rails(test_file, min_rails_version, supports_jruby = true)
1017
+ if defined?(Rails) &&
1018
+ defined?(Rails::VERSION::STRING) &&
1019
+ (Rails::VERSION::STRING.to_f >= min_rails_version) &&
1020
+ (supports_jruby || !NewRelic::LanguageSupport.jruby?)
1005
1021
 
1006
1022
  yield
1007
1023
  else
1008
- puts "Skipping tests in #{test_file} because Rails >= #{min_rails_version} is unavailable"
1024
+ puts "Skipping tests in #{File.basename(test_file)} because Rails >= #{min_rails_version} is unavailable" if ENV["VERBOSE_TEST_OUTPUT"]
1009
1025
  end
1010
1026
  end