newrelic_rpm 6.10.0.364 → 8.15.0

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