newrelic_rpm 6.15.0 → 8.13.1

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