newrelic_rpm 8.9.0 → 8.10.0

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