newrelic_rpm 8.0.0 → 8.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +1936 -0
  4. data/Brewfile +10 -0
  5. data/CHANGELOG.md +96 -0
  6. data/CONTRIBUTING.md +15 -3
  7. data/Guardfile +8 -8
  8. data/README.md +3 -1
  9. data/Rakefile +7 -9
  10. data/bin/mongrel_rpm +8 -9
  11. data/bin/newrelic +1 -1
  12. data/bin/nrdebug +14 -14
  13. data/init.rb +0 -2
  14. data/lefthook.yml +9 -0
  15. data/lib/new_relic/agent/adaptive_sampler.rb +7 -3
  16. data/lib/new_relic/agent/agent.rb +38 -40
  17. data/lib/new_relic/agent/agent_logger.rb +8 -9
  18. data/lib/new_relic/agent/attribute_filter.rb +31 -31
  19. data/lib/new_relic/agent/attributes.rb +2 -2
  20. data/lib/new_relic/agent/autostart.rb +6 -7
  21. data/lib/new_relic/agent/commands/agent_command.rb +2 -2
  22. data/lib/new_relic/agent/commands/agent_command_router.rb +6 -5
  23. data/lib/new_relic/agent/commands/thread_profiler_session.rb +0 -3
  24. data/lib/new_relic/agent/configuration/default_source.rb +343 -337
  25. data/lib/new_relic/agent/configuration/dotted_hash.rb +3 -3
  26. data/lib/new_relic/agent/configuration/environment_source.rb +3 -4
  27. data/lib/new_relic/agent/configuration/event_harvest_config.rb +2 -4
  28. data/lib/new_relic/agent/configuration/high_security_source.rb +7 -7
  29. data/lib/new_relic/agent/configuration/manager.rb +57 -57
  30. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
  31. data/lib/new_relic/agent/configuration/security_policy_source.rb +73 -73
  32. data/lib/new_relic/agent/configuration/server_source.rb +10 -10
  33. data/lib/new_relic/agent/configuration/yaml_source.rb +9 -9
  34. data/lib/new_relic/agent/connect/request_builder.rb +13 -16
  35. data/lib/new_relic/agent/connect/response_handler.rb +0 -3
  36. data/lib/new_relic/agent/custom_event_aggregator.rb +9 -10
  37. data/lib/new_relic/agent/database/explain_plan_helpers.rb +3 -4
  38. data/lib/new_relic/agent/database/obfuscation_helpers.rb +12 -12
  39. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +2 -2
  40. data/lib/new_relic/agent/database.rb +20 -24
  41. data/lib/new_relic/agent/datastores/metric_helper.rb +10 -10
  42. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -3
  43. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +3 -5
  44. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +1 -2
  45. data/lib/new_relic/agent/datastores/redis.rb +2 -4
  46. data/lib/new_relic/agent/datastores.rb +1 -3
  47. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +5 -5
  48. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +11 -10
  49. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +10 -11
  50. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +41 -42
  51. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +3 -3
  52. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +41 -43
  53. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +24 -24
  54. data/lib/new_relic/agent/distributed_tracing.rb +17 -18
  55. data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
  56. data/lib/new_relic/agent/error_collector.rb +17 -17
  57. data/lib/new_relic/agent/error_event_aggregator.rb +1 -1
  58. data/lib/new_relic/agent/error_filter.rb +16 -10
  59. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -1
  60. data/lib/new_relic/agent/event_aggregator.rb +1 -1
  61. data/lib/new_relic/agent/event_buffer.rb +6 -7
  62. data/lib/new_relic/agent/event_listener.rb +0 -1
  63. data/lib/new_relic/agent/event_loop.rb +10 -10
  64. data/lib/new_relic/agent/external.rb +1 -2
  65. data/lib/new_relic/agent/guid_generator.rb +2 -9
  66. data/lib/new_relic/agent/harvester.rb +3 -4
  67. data/lib/new_relic/agent/heap.rb +1 -3
  68. data/lib/new_relic/agent/hostname.rb +3 -3
  69. data/lib/new_relic/agent/http_clients/abstract.rb +5 -7
  70. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -5
  71. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +4 -4
  72. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +3 -3
  73. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +1 -2
  74. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +8 -3
  75. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +2 -3
  76. data/lib/new_relic/agent/http_clients/uri_util.rb +0 -1
  77. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +2 -3
  78. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +9 -10
  79. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +5 -7
  80. data/lib/new_relic/agent/instrumentation/active_job.rb +4 -3
  81. data/lib/new_relic/agent/instrumentation/active_merchant.rb +2 -2
  82. data/lib/new_relic/agent/instrumentation/active_record.rb +20 -18
  83. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +36 -42
  84. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +28 -25
  85. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +3 -3
  86. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +5 -6
  87. data/lib/new_relic/agent/instrumentation/active_storage.rb +1 -1
  88. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +8 -9
  89. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +1 -1
  90. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +7 -8
  91. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +41 -41
  92. data/lib/new_relic/agent/instrumentation/curb/chain.rb +19 -20
  93. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +34 -38
  94. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +9 -10
  95. data/lib/new_relic/agent/instrumentation/data_mapper.rb +10 -10
  96. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +5 -7
  97. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +5 -9
  98. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +4 -4
  99. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -2
  100. data/lib/new_relic/agent/instrumentation/excon.rb +0 -1
  101. data/lib/new_relic/agent/instrumentation/grape/chain.rb +1 -2
  102. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +6 -7
  103. data/lib/new_relic/agent/instrumentation/grape.rb +2 -3
  104. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +2 -3
  105. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +0 -1
  106. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +0 -2
  107. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +2 -2
  108. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +6 -6
  109. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -1
  110. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -3
  111. data/lib/new_relic/agent/instrumentation/logger/chain.rb +21 -0
  112. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +58 -0
  113. data/lib/new_relic/agent/instrumentation/logger/prepend.rb +13 -0
  114. data/lib/new_relic/agent/instrumentation/logger.rb +25 -0
  115. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +7 -2
  116. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +5 -1
  117. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +9 -2
  118. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +9 -10
  119. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +4 -5
  120. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +4 -4
  121. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +3 -4
  122. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -5
  123. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +4 -4
  124. data/lib/new_relic/agent/instrumentation/net_http.rb +1 -1
  125. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +2 -3
  126. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +23 -19
  127. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +3 -2
  128. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +2 -2
  129. data/lib/new_relic/agent/instrumentation/padrino.rb +2 -5
  130. data/lib/new_relic/agent/instrumentation/queue_time.rb +5 -5
  131. data/lib/new_relic/agent/instrumentation/rack/chain.rb +5 -5
  132. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +0 -1
  133. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +4 -5
  134. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +0 -1
  135. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  136. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -6
  137. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +2 -2
  138. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +0 -1
  139. data/lib/new_relic/agent/instrumentation/rake/chain.rb +0 -5
  140. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +6 -6
  141. data/lib/new_relic/agent/instrumentation/rake.rb +1 -1
  142. data/lib/new_relic/agent/instrumentation/redis/chain.rb +6 -6
  143. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +2 -2
  144. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +1 -1
  145. data/lib/new_relic/agent/instrumentation/redis.rb +1 -1
  146. data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -3
  147. data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
  148. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +4 -4
  149. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -2
  150. data/lib/new_relic/agent/instrumentation/resque.rb +7 -7
  151. data/lib/new_relic/agent/instrumentation/sequel.rb +7 -9
  152. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
  153. data/lib/new_relic/agent/instrumentation/sidekiq.rb +5 -4
  154. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +0 -1
  155. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +4 -3
  156. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  157. data/lib/new_relic/agent/instrumentation/tilt/chain.rb +24 -0
  158. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +40 -0
  159. data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +13 -0
  160. data/lib/new_relic/agent/instrumentation/tilt.rb +25 -0
  161. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +4 -4
  162. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +3 -5
  163. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +1 -1
  164. data/lib/new_relic/agent/internal_agent_error.rb +1 -1
  165. data/lib/new_relic/agent/javascript_instrumentor.rb +28 -28
  166. data/lib/new_relic/agent/logging.rb +11 -8
  167. data/lib/new_relic/agent/memory_logger.rb +1 -1
  168. data/lib/new_relic/agent/messaging.rb +42 -43
  169. data/lib/new_relic/agent/method_tracer.rb +17 -15
  170. data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
  171. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +19 -16
  172. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +2 -2
  173. data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +0 -1
  174. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +4 -7
  175. data/lib/new_relic/agent/monitors.rb +1 -2
  176. data/lib/new_relic/agent/new_relic_service/encoders.rb +4 -4
  177. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -1
  178. data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
  179. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +4 -3
  180. data/lib/new_relic/agent/new_relic_service.rb +26 -33
  181. data/lib/new_relic/agent/noticible_error.rb +0 -2
  182. data/lib/new_relic/agent/null_logger.rb +6 -2
  183. data/lib/new_relic/agent/obfuscator.rb +6 -8
  184. data/lib/new_relic/agent/parameter_filtering.rb +15 -7
  185. data/lib/new_relic/agent/payload_metric_mapping.rb +8 -9
  186. data/lib/new_relic/agent/pipe_channel_manager.rb +5 -6
  187. data/lib/new_relic/agent/pipe_service.rb +1 -1
  188. data/lib/new_relic/agent/priority_sampled_buffer.rb +4 -7
  189. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +9 -9
  190. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +12 -12
  191. data/lib/new_relic/agent/rules_engine.rb +2 -2
  192. data/lib/new_relic/agent/sampler.rb +2 -3
  193. data/lib/new_relic/agent/sampler_collection.rb +2 -3
  194. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +10 -7
  195. data/lib/new_relic/agent/samplers/memory_sampler.rb +4 -3
  196. data/lib/new_relic/agent/samplers/vm_sampler.rb +18 -18
  197. data/lib/new_relic/agent/span_event_aggregator.rb +8 -8
  198. data/lib/new_relic/agent/span_event_primitive.rb +39 -39
  199. data/lib/new_relic/agent/sql_sampler.rb +9 -9
  200. data/lib/new_relic/agent/stats.rb +16 -16
  201. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +7 -9
  202. data/lib/new_relic/agent/stats_engine/stats_hash.rb +8 -9
  203. data/lib/new_relic/agent/stats_engine.rb +6 -6
  204. data/lib/new_relic/agent/synthetics_event_aggregator.rb +0 -1
  205. data/lib/new_relic/agent/system_info.rb +22 -20
  206. data/lib/new_relic/agent/threading/agent_thread.rb +4 -5
  207. data/lib/new_relic/agent/threading/backtrace_node.rb +6 -9
  208. data/lib/new_relic/agent/threading/backtrace_service.rb +8 -8
  209. data/lib/new_relic/agent/threading/thread_profile.rb +15 -18
  210. data/lib/new_relic/agent/tracer.rb +37 -43
  211. data/lib/new_relic/agent/transaction/abstract_segment.rb +6 -6
  212. data/lib/new_relic/agent/transaction/datastore_segment.rb +7 -6
  213. data/lib/new_relic/agent/transaction/distributed_tracer.rb +8 -9
  214. data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -22
  215. data/lib/new_relic/agent/transaction/external_request_segment.rb +6 -5
  216. data/lib/new_relic/agent/transaction/message_broker_segment.rb +23 -23
  217. data/lib/new_relic/agent/transaction/request_attributes.rb +7 -7
  218. data/lib/new_relic/agent/transaction/segment.rb +6 -3
  219. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +0 -2
  220. data/lib/new_relic/agent/transaction/trace.rb +8 -8
  221. data/lib/new_relic/agent/transaction/trace_context.rb +13 -15
  222. data/lib/new_relic/agent/transaction/trace_node.rb +16 -16
  223. data/lib/new_relic/agent/transaction/tracing.rb +1 -3
  224. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -2
  225. data/lib/new_relic/agent/transaction.rb +79 -81
  226. data/lib/new_relic/agent/transaction_error_primitive.rb +16 -16
  227. data/lib/new_relic/agent/transaction_event_aggregator.rb +5 -6
  228. data/lib/new_relic/agent/transaction_event_primitive.rb +29 -29
  229. data/lib/new_relic/agent/transaction_metrics.rb +3 -3
  230. data/lib/new_relic/agent/transaction_sampler.rb +0 -1
  231. data/lib/new_relic/agent/transaction_time_aggregator.rb +6 -6
  232. data/lib/new_relic/agent/utilization/azure.rb +1 -1
  233. data/lib/new_relic/agent/utilization_data.rb +3 -4
  234. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  235. data/lib/new_relic/agent/vm/snapshot.rb +3 -3
  236. data/lib/new_relic/agent/worker_loop.rb +3 -5
  237. data/lib/new_relic/agent.rb +22 -22
  238. data/lib/new_relic/cli/command.rb +15 -17
  239. data/lib/new_relic/cli/commands/deployments.rb +20 -22
  240. data/lib/new_relic/cli/commands/install.rb +6 -10
  241. data/lib/new_relic/coerce.rb +5 -8
  242. data/lib/new_relic/collection_helper.rb +48 -47
  243. data/lib/new_relic/control/class_methods.rb +2 -2
  244. data/lib/new_relic/control/frameworks/external.rb +1 -1
  245. data/lib/new_relic/control/frameworks/rails.rb +5 -6
  246. data/lib/new_relic/control/frameworks/rails3.rb +2 -3
  247. data/lib/new_relic/control/frameworks/ruby.rb +2 -2
  248. data/lib/new_relic/control/frameworks/sinatra.rb +6 -0
  249. data/lib/new_relic/control/instance_methods.rb +4 -5
  250. data/lib/new_relic/control/instrumentation.rb +4 -5
  251. data/lib/new_relic/control/server_methods.rb +2 -3
  252. data/lib/new_relic/control.rb +0 -1
  253. data/lib/new_relic/dependency_detection.rb +6 -8
  254. data/lib/new_relic/environment_report.rb +16 -18
  255. data/lib/new_relic/helper.rb +5 -5
  256. data/lib/new_relic/language_support.rb +1 -1
  257. data/lib/new_relic/latest_changes.rb +2 -2
  258. data/lib/new_relic/local_environment.rb +7 -7
  259. data/lib/new_relic/metric_data.rb +6 -7
  260. data/lib/new_relic/metric_spec.rb +3 -3
  261. data/lib/new_relic/noticed_error.rb +14 -15
  262. data/lib/new_relic/rack/agent_middleware.rb +2 -2
  263. data/lib/new_relic/rack/browser_monitoring.rb +9 -9
  264. data/lib/new_relic/recipes/capistrano3.rb +11 -13
  265. data/lib/new_relic/recipes/capistrano_legacy.rb +11 -14
  266. data/lib/new_relic/supportability_helper.rb +1 -2
  267. data/lib/new_relic/version.rb +3 -4
  268. data/lib/sequel/extensions/newrelic_instrumentation.rb +4 -7
  269. data/lib/sequel/plugins/newrelic_instrumentation.rb +3 -9
  270. data/lib/tasks/all.rb +1 -1
  271. data/lib/tasks/config.rake +21 -21
  272. data/lib/tasks/multiverse.rb +4 -6
  273. data/lib/tasks/tests.rake +3 -7
  274. data/newrelic.yml +8 -21
  275. data/newrelic_rpm.gemspec +13 -12
  276. data/recipes/newrelic.rb +1 -1
  277. data/test/agent_helper.rb +55 -55
  278. metadata +43 -7
  279. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +0 -125
  280. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +0 -46
  281. data/lib/new_relic/agent/supported_versions.rb +0 -275
@@ -4,11 +4,9 @@
4
4
 
5
5
  module NewRelic
6
6
  module Agent
7
-
8
7
  # Handles loading of ignored and expected errors from the agent configuration, and
9
8
  # determining at runtime whether an exception is ignored or expected.
10
9
  class ErrorFilter
11
-
12
10
  def initialize
13
11
  reset
14
12
  end
@@ -20,16 +18,17 @@ module NewRelic
20
18
  end
21
19
 
22
20
  def load_all
23
- %i(
21
+ %i[
24
22
  ignore_errors ignore_classes ignore_messages ignore_status_codes
25
23
  expected_classes expected_messages expected_status_codes
26
- ).each { |setting| load_from_config(setting) }
24
+ ].each { |setting| load_from_config(setting) }
27
25
  end
28
26
 
29
27
  def load_from_config(setting, value = nil)
30
28
  errors = nil
31
29
  new_value = value || fetch_agent_config(setting.to_sym)
32
- return if new_value.nil? || new_value.empty?
30
+
31
+ return if new_value.nil? || (new_value.respond_to?(:empty?) && new_value.empty?)
33
32
 
34
33
  case setting.to_sym
35
34
  when :ignore_errors, :ignore_classes
@@ -50,7 +49,7 @@ module NewRelic
50
49
  end
51
50
 
52
51
  def ignore?(ex, status_code = nil)
53
- @ignore_classes.include?(ex.class.name) ||
52
+ @ignore_classes.include?(ex.class.name) ||
54
53
  (@ignore_messages.keys.include?(ex.class.name) &&
55
54
  @ignore_messages[ex.class.name].any? { |m| ex.message.include?(m) }) ||
56
55
  @ignore_status_codes.include?(status_code.to_i)
@@ -126,7 +125,7 @@ module NewRelic
126
125
  ::NewRelic::Agent.logger.debug("Ignoring errors of type '#{error}'")
127
126
  end
128
127
  when :ignore_messages
129
- errors.each do |error,messages|
128
+ errors.each do |error, messages|
130
129
  ::NewRelic::Agent.logger.debug("Ignoring errors of type '#{error}' with messages: #{messages.join(',')}")
131
130
  end
132
131
  when :ignore_status_codes
@@ -136,7 +135,7 @@ module NewRelic
136
135
  ::NewRelic::Agent.logger.debug("Expecting errors of type '#{error}'")
137
136
  end
138
137
  when :expected_messages
139
- errors.each do |error,messages|
138
+ errors.each do |error, messages|
140
139
  ::NewRelic::Agent.logger.debug("Expecting errors of type '#{error}' with messages: #{messages.join(',')}")
141
140
  end
142
141
  when :expected_status_codes
@@ -145,7 +144,14 @@ module NewRelic
145
144
  end
146
145
 
147
146
  def parse_status_codes(codes)
148
- code_list = codes.is_a?(String) ? codes.split(',') : codes
147
+ code_list = case codes
148
+ when String
149
+ codes.split(',')
150
+ when Integer
151
+ [codes]
152
+ else
153
+ codes
154
+ end
149
155
  result = []
150
156
  code_list.each do |code|
151
157
  result << code && next if code.is_a?(Integer)
@@ -164,4 +170,4 @@ module NewRelic
164
170
  end
165
171
  end
166
172
  end
167
- end
173
+ end
@@ -54,7 +54,7 @@ module NewRelic
54
54
  # checks the size of the error queue to make sure we are under
55
55
  # the maximum limit, and logs a warning if we are over the limit.
56
56
  def over_queue_limit?(message)
57
- over_limit = (@errors.reject{|err| err.is_internal}.length >= @capacity)
57
+ over_limit = (@errors.reject { |err| err.is_internal }.length >= @capacity)
58
58
  if over_limit
59
59
  ::NewRelic::Agent.logger.warn("The error reporting queue has reached #{@capacity}. The error detail for this and subsequent errors will not be transmitted to New Relic until the queued errors have been sent: #{message}")
60
60
  end
@@ -25,7 +25,7 @@ module NewRelic
25
25
  @enabled_keys ||= []
26
26
  else
27
27
  @enabled_keys = Array(keys)
28
- @enabled_fn = ->(){ @enabled_keys.all? { |k| Agent.config[k] } }
28
+ @enabled_fn = ->() { @enabled_keys.all? { |k| Agent.config[k] } }
29
29
  end
30
30
  end
31
31
 
@@ -22,22 +22,22 @@ module NewRelic
22
22
 
23
23
  def initialize(capacity)
24
24
  @capacity = capacity
25
- @items = []
26
- @seen = 0
25
+ @items = []
26
+ @seen = 0
27
27
  end
28
28
 
29
29
  def reset!
30
30
  @items = []
31
- @seen = 0
31
+ @seen = 0
32
32
  end
33
33
 
34
34
  def capacity=(new_capacity)
35
35
  @capacity = new_capacity
36
36
  old_items = @items
37
- @items = []
38
- old_seen = @seen
37
+ @items = []
38
+ old_seen = @seen
39
39
  old_items.each { |i| append(i) }
40
- @seen = old_seen
40
+ @seen = old_seen
41
41
  end
42
42
 
43
43
  def append(x)
@@ -88,4 +88,3 @@ module NewRelic
88
88
  end
89
89
  end
90
90
  end
91
-
@@ -9,7 +9,6 @@ module NewRelic::Agent
9
9
  # While an EventListener could be used elsewhere, it's strongly expected
10
10
  # your eventing needs should be met by the agent's instance.
11
11
  class EventListener
12
-
13
12
  attr_accessor :runaway_threshold
14
13
 
15
14
  def initialize
@@ -10,11 +10,11 @@ module NewRelic
10
10
  class Timer
11
11
  attr_reader :next_fire_time, :event, :interval, :last_fired_at
12
12
 
13
- def initialize(interval, event, repeat=false)
14
- @interval = interval
15
- @event = event
16
- @repeat = repeat
17
- @started_at = Process.clock_gettime(Process::CLOCK_REALTIME)
13
+ def initialize(interval, event, repeat = false)
14
+ @interval = interval
15
+ @event = event
16
+ @repeat = repeat
17
+ @started_at = Process.clock_gettime(Process::CLOCK_REALTIME)
18
18
  @last_fired_at = nil
19
19
  reschedule
20
20
  end
@@ -45,7 +45,7 @@ module NewRelic
45
45
  @last_fired_at = Process.clock_gettime(Process::CLOCK_REALTIME)
46
46
  end
47
47
 
48
- def due?(now=Process.clock_gettime(Process::CLOCK_REALTIME))
48
+ def due?(now = Process.clock_gettime(Process::CLOCK_REALTIME))
49
49
  now >= @next_fire_time
50
50
  end
51
51
 
@@ -57,10 +57,10 @@ module NewRelic
57
57
  def initialize
58
58
  @self_pipe_rd, @self_pipe_wr = IO.pipe
59
59
  @event_queue = Queue.new
60
- @stopped = false
61
- @timers = {}
60
+ @stopped = false
61
+ @timers = {}
62
62
 
63
- @subscriptions = Hash.new { |h,k| h[k] = [] }
63
+ @subscriptions = Hash.new { |h, k| h[k] = [] }
64
64
  @subscriptions[:__add_timer] << Proc.new { |t| set_timer(t) }
65
65
  @subscriptions[:__add_event] << Proc.new { |e, blk| @subscriptions[e] << blk }
66
66
  end
@@ -100,7 +100,7 @@ module NewRelic
100
100
  end
101
101
  end
102
102
 
103
- def run_once(nonblock=false)
103
+ def run_once(nonblock = false)
104
104
  wait_to_run(nonblock)
105
105
 
106
106
  prune_timers
@@ -18,7 +18,7 @@ module NewRelic
18
18
  module External
19
19
  extend self
20
20
 
21
- NON_HTTP_CAT_ID_HEADER = 'NewRelicID'.freeze
21
+ NON_HTTP_CAT_ID_HEADER = 'NewRelicID'.freeze
22
22
  NON_HTTP_CAT_TXN_HEADER = 'NewRelicTransaction'.freeze
23
23
  NON_HTTP_CAT_SYNTHETICS_HEADER = 'NewRelicSynthetics'.freeze
24
24
  NON_HTTP_CAT_CONTENT_LENGTH = -1
@@ -105,7 +105,6 @@ module NewRelic
105
105
  def obfuscator
106
106
  CrossAppTracing.obfuscator
107
107
  end
108
-
109
108
  end
110
109
  end
111
110
  end
@@ -5,9 +5,6 @@
5
5
  module NewRelic
6
6
  module Agent
7
7
  module GuidGenerator
8
-
9
- HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
10
-
11
8
  module_function
12
9
 
13
10
  # This method intentionally does not use SecureRandom, because it relies
@@ -16,13 +13,9 @@ module NewRelic
16
13
  # The guids generated by this method may not be _secure_, but they are
17
14
  # random enough for our purposes.
18
15
  def generate_guid length = 16
19
- guid = ''
20
- length.times do |a|
21
- guid << HEX_DIGITS[rand(16)]
22
- end
23
- guid
16
+ guid = rand(16**length).to_s(16)
17
+ guid.length < length ? guid.rjust(length, "0") : guid
24
18
  end
25
-
26
19
  end
27
20
  end
28
21
  end
@@ -5,11 +5,10 @@
5
5
  module NewRelic
6
6
  module Agent
7
7
  class Harvester
8
-
9
8
  attr_accessor :starting_pid
10
9
 
11
10
  # Inject target for after_fork call to avoid spawning thread in tests
12
- def initialize(events, after_forker=NewRelic::Agent)
11
+ def initialize(events, after_forker = NewRelic::Agent)
13
12
  # We intentionally don't set our pid as started at this point.
14
13
  # Startup routines must call mark_started when they consider us set!
15
14
  @starting_pid = nil
@@ -22,8 +21,8 @@ module NewRelic
22
21
 
23
22
  def on_transaction(*_)
24
23
  return unless restart_in_children_enabled? &&
25
- needs_restart? &&
26
- harvest_thread_enabled?
24
+ needs_restart? &&
25
+ harvest_thread_enabled?
27
26
 
28
27
  restart_harvest_thread
29
28
  end
@@ -18,7 +18,6 @@ module NewRelic
18
18
  #
19
19
 
20
20
  class Heap
21
-
22
21
  # @param [Array] items an optional array of items to intialize the heap
23
22
  #
24
23
  # @param [Callable] priority_fn an optional priority function used to
@@ -27,7 +26,7 @@ module NewRelic
27
26
  def initialize(items = nil, &priority_fn)
28
27
  @items = []
29
28
  @priority_fn = priority_fn || ->(x) { x }
30
- items.each{ |item| push(item) } if items
29
+ items.each { |item| push(item) } if items
31
30
  end
32
31
 
33
32
  def [](index)
@@ -135,6 +134,5 @@ module NewRelic
135
134
  @items[i], @items[j] = @items[j], @items[i]
136
135
  end
137
136
  end
138
-
139
137
  end
140
138
  end
@@ -19,11 +19,11 @@ module NewRelic
19
19
 
20
20
  # calling hostname with -f on some OS's (NetBSD, FreeBSD, Solaris)
21
21
  # produces invalid option error, but doesn't raise exception. Instead,
22
- # we get back empty string. So, solution here is to check for non-zero
22
+ # we get back empty string. So, solution here is to check for non-zero
23
23
  # exit status and retry the command without the -f flag.
24
24
  def self.get_fqdn
25
- fqdn = %x[hostname -f].chomp!
26
- fqdn = %x[hostname].chomp! unless $?.exitstatus.zero?
25
+ fqdn = %x(hostname -f).chomp!
26
+ fqdn = %x(hostname).chomp! unless $?.exitstatus.zero?
27
27
  fqdn
28
28
  rescue => e
29
29
  NewRelic::Agent.logger.debug "Unable to determine fqdn #{e}"
@@ -15,7 +15,6 @@ module NewRelic
15
15
  #
16
16
  # @api public
17
17
  class AbstractRequest
18
-
19
18
  def []
20
19
  raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
21
20
  end
@@ -41,13 +40,12 @@ module NewRelic
41
40
  end
42
41
  end
43
42
 
44
- # This class implements the adaptor pattern and is used internally provide
43
+ # This class implements the adaptor pattern and is used internally provide
45
44
  # uniform access to the underlying HTTP Client's response object
46
45
  # NOTE: response_object should be non-nil!
47
46
  class AbstractResponse # :nodoc:
48
-
49
47
  def initialize(wrapped_response)
50
- if wrapped_response.nil?
48
+ if wrapped_response.nil?
51
49
  raise ArgumentError, WHINY_NIL_ERROR % self.class
52
50
  end
53
51
  @wrapped_response = wrapped_response
@@ -57,13 +55,13 @@ module NewRelic
57
55
  !!status_code
58
56
  end
59
57
 
60
- # most HTTP client libraries report the HTTP status code as an integer, so
58
+ # most HTTP client libraries report the HTTP status code as an integer, so
61
59
  # we expect status_code to be set only if a non-zero value is present
62
60
  def status_code
63
61
  @status_code ||= get_status_code
64
62
  end
65
63
 
66
- private
64
+ private
67
65
 
68
66
  def get_status_code_using(method_name)
69
67
  return unless @wrapped_response.respond_to?(method_name)
@@ -71,7 +69,7 @@ module NewRelic
71
69
  code == 0 ? nil : code
72
70
  end
73
71
 
74
- # Override this method to memoize a non-zero Integer representation
72
+ # Override this method to memoize a non-zero Integer representation
75
73
  # of HTTP status code from the response object
76
74
  def get_status_code
77
75
  get_status_code_using :code
@@ -8,7 +8,6 @@ require_relative 'abstract'
8
8
  module NewRelic
9
9
  module Agent
10
10
  module HTTPClients
11
-
12
11
  class CurbRequest
13
12
  CURB = 'Curb'
14
13
  LHOST = 'host'
@@ -34,7 +33,7 @@ module NewRelic
34
33
  @curlobj._nr_http_verb
35
34
  end
36
35
 
37
- def []( key )
36
+ def [](key)
38
37
  @curlobj.headers[key]
39
38
  end
40
39
 
@@ -48,7 +47,6 @@ module NewRelic
48
47
  end
49
48
 
50
49
  class CurbResponse < AbstractResponse
51
-
52
50
  def initialize wrapped_response
53
51
  super wrapped_response
54
52
  @headers = {}
@@ -75,8 +73,6 @@ module NewRelic
75
73
  get_status_code_using :response_code
76
74
  end
77
75
  end
78
-
79
76
  end
80
-
81
77
  end
82
78
  end
@@ -31,8 +31,8 @@ module NewRelic
31
31
  private
32
32
 
33
33
  def get_attribute name
34
- if @wrapped_response.respond_to?(name)
35
- @wrapped_response.send(name)
34
+ if @wrapped_response.respond_to?(name)
35
+ @wrapped_response.send(name)
36
36
  else
37
37
  @wrapped_response[name]
38
38
  end
@@ -57,8 +57,8 @@ module NewRelic
57
57
 
58
58
  @method = @datum[:method].to_s.upcase
59
59
  @scheme = @datum[:scheme]
60
- @port = @datum[:port]
61
- @path = @datum[:path]
60
+ @port = @datum[:port]
61
+ @path = @datum[:path]
62
62
  end
63
63
 
64
64
  def type
@@ -10,7 +10,7 @@ module NewRelic
10
10
  module HTTPClients
11
11
  class HTTPResponse < AbstractResponse
12
12
  def [](key)
13
- _, value = @wrapped_response.headers.find{ |k, _| key.downcase == k.downcase }
13
+ _, value = @wrapped_response.headers.find { |k, _| key.downcase == k.downcase }
14
14
  value unless value.nil?
15
15
  end
16
16
 
@@ -21,8 +21,8 @@ module NewRelic
21
21
 
22
22
  class HTTPRequest < AbstractRequest
23
23
  HTTP_RB = 'http.rb'
24
- HOST = 'host'
25
- COLON = ':'
24
+ HOST = 'host'
25
+ COLON = ':'
26
26
 
27
27
  def initialize wrapped_request
28
28
  @wrapped_request = wrapped_request
@@ -9,9 +9,8 @@ module NewRelic
9
9
  module Agent
10
10
  module HTTPClients
11
11
  class HTTPClientResponse < AbstractResponse
12
-
13
12
  def [](key)
14
- @wrapped_response.headers.each do |k,v|
13
+ @wrapped_response.headers.each do |k, v|
15
14
  if key.downcase == k.downcase
16
15
  return v
17
16
  end
@@ -4,12 +4,12 @@
4
4
  # frozen_string_literal: true
5
5
 
6
6
  require_relative 'abstract'
7
+ require 'resolv'
7
8
 
8
9
  module NewRelic
9
10
  module Agent
10
11
  module HTTPClients
11
12
  class NetHTTPResponse < AbstractResponse
12
-
13
13
  def [](key)
14
14
  @wrapped_response[key]
15
15
  end
@@ -61,10 +61,15 @@ module NewRelic
61
61
  when /^https?:\/\//
62
62
  ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(@request.path)
63
63
  else
64
+ connection_address = @connection.address
65
+ if connection_address =~ Resolv::IPv6::Regex
66
+ connection_address = "[#{connection_address}]"
67
+ end
68
+
64
69
  scheme = @connection.use_ssl? ? 'https' : 'http'
65
70
  ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(
66
- "#{scheme}://#{@connection.address}:#{@connection.port}#{@request.path}"
67
- )
71
+ "#{scheme}://#{connection_address}:#{@connection.port}#{@request.path}"
72
+ )
68
73
  end
69
74
  end
70
75
  end
@@ -9,7 +9,6 @@ module NewRelic
9
9
  module Agent
10
10
  module HTTPClients
11
11
  class TyphoeusHTTPResponse < AbstractResponse
12
-
13
12
  def [](key)
14
13
  unless headers.nil?
15
14
  result = headers[key]
@@ -22,7 +21,7 @@ module NewRelic
22
21
 
23
22
  def to_hash
24
23
  hash = {}
25
- headers.each do |(k,v)|
24
+ headers.each do |(k, v)|
26
25
  hash[k] = v
27
26
  end
28
27
  hash
@@ -41,7 +40,7 @@ module NewRelic
41
40
  @uri = case request.url
42
41
  when ::URI then request.url
43
42
  else NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(request.url)
44
- end
43
+ end
45
44
  end
46
45
 
47
46
  TYPHOEUS = "Typhoeus".freeze
@@ -14,7 +14,6 @@ module NewRelic
14
14
  module Agent
15
15
  module HTTPClients
16
16
  module URIUtil
17
-
18
17
  def self.obfuscated_uri(url)
19
18
  parse_and_normalize_url(url).tap do |obfuscated|
20
19
  obfuscated.user = nil
@@ -7,10 +7,9 @@ module NewRelic
7
7
  module Agent
8
8
  module Instrumentation
9
9
  class ActionCableSubscriber < NotificationsSubscriber
10
-
11
10
  PERFORM_ACTION = 'perform_action.action_cable'.freeze
12
11
 
13
- def start(name, id, payload) #THREAD_LOCAL_ACCESS
12
+ def start(name, id, payload) # THREAD_LOCAL_ACCESS
14
13
  return unless state.is_execution_traced?
15
14
 
16
15
  finishable = if name == PERFORM_ACTION
@@ -26,7 +25,7 @@ module NewRelic
26
25
  log_notification_error e, name, 'start'
27
26
  end
28
27
 
29
- def finish(name, id, payload) #THREAD_LOCAL_ACCESS
28
+ def finish(name, id, payload) # THREAD_LOCAL_ACCESS
30
29
  return unless state.is_execution_traced?
31
30
 
32
31
  if exception = exception_object(payload)
@@ -9,8 +9,7 @@ module NewRelic
9
9
  module Agent
10
10
  module Instrumentation
11
11
  class ActionControllerSubscriber < NotificationsSubscriber
12
-
13
- def start(name, id, payload) #THREAD_LOCAL_ACCESS
12
+ def start(name, id, payload) # THREAD_LOCAL_ACCESS
14
13
  # @req is a historically stable but not guaranteed Rails header property
15
14
  request = payload[:headers].instance_variable_get(:@req)
16
15
 
@@ -29,7 +28,7 @@ module NewRelic
29
28
  log_notification_error(e, name, 'start')
30
29
  end
31
30
 
32
- def finish(name, id, payload) #THREAD_LOCAL_ACCESS
31
+ def finish(name, id, payload) # THREAD_LOCAL_ACCESS
33
32
  finishable = pop_segment(id)
34
33
 
35
34
  if state.is_execution_traced? \
@@ -49,21 +48,21 @@ module NewRelic
49
48
 
50
49
  def start_transaction_or_segment(payload, request, controller_class)
51
50
  Tracer.start_transaction_or_segment(
52
- name: format_metric_name(payload[:action], controller_class),
53
- category: :controller,
54
- options: {
55
- request: request,
56
- filtered_params: NewRelic::Agent::ParameterFiltering.filter_using_rails(
51
+ name: format_metric_name(payload[:action], controller_class),
52
+ category: :controller,
53
+ options: {
54
+ request: request,
55
+ filtered_params: NewRelic::Agent::ParameterFiltering.filter_using_rails(
57
56
  payload[:params],
58
57
  Rails.application.config.filter_parameters
59
58
  ),
60
59
  apdex_start_time: queue_start(request),
61
- ignore_apdex: NewRelic::Agent::Instrumentation::IgnoreActions.is_filtered?(
60
+ ignore_apdex: NewRelic::Agent::Instrumentation::IgnoreActions.is_filtered?(
62
61
  ControllerInstrumentation::NR_IGNORE_APDEX_KEY,
63
62
  controller_class,
64
63
  payload[:action]
65
64
  ),
66
- ignore_enduser: NewRelic::Agent::Instrumentation::IgnoreActions.is_filtered?(
65
+ ignore_enduser: NewRelic::Agent::Instrumentation::IgnoreActions.is_filtered?(
67
66
  ControllerInstrumentation::NR_IGNORE_ENDUSER_KEY,
68
67
  controller_class,
69
68
  payload[:action]
@@ -9,8 +9,7 @@ module NewRelic
9
9
  module Agent
10
10
  module Instrumentation
11
11
  class ActionViewSubscriber < NotificationsSubscriber
12
-
13
- def start(name, id, payload) #THREAD_LOCAL_ACCESS
12
+ def start(name, id, payload) # THREAD_LOCAL_ACCESS
14
13
  parent = segment_stack[id].last
15
14
  metric_name = format_metric_name(name, payload, parent)
16
15
 
@@ -58,15 +57,15 @@ module NewRelic
58
57
  || metric_name == "View/#{::NewRelic::Agent::UNKNOWN_METRIC}/Partial"
59
58
  end
60
59
 
61
- RENDER_TEMPLATE_EVENT_NAME = 'render_template.action_view'.freeze
62
- RENDER_PARTIAL_EVENT_NAME = 'render_partial.action_view'.freeze
60
+ RENDER_TEMPLATE_EVENT_NAME = 'render_template.action_view'.freeze
61
+ RENDER_PARTIAL_EVENT_NAME = 'render_partial.action_view'.freeze
63
62
  RENDER_COLLECTION_EVENT_NAME = 'render_collection.action_view'.freeze
64
63
 
65
64
  def metric_action(name)
66
65
  case name
67
66
  when /#{RENDER_TEMPLATE_EVENT_NAME}$/ then 'Rendering'
68
- when RENDER_PARTIAL_EVENT_NAME then 'Partial'
69
- when RENDER_COLLECTION_EVENT_NAME then 'Partial'
67
+ when RENDER_PARTIAL_EVENT_NAME then 'Partial'
68
+ when RENDER_COLLECTION_EVENT_NAME then 'Partial'
70
69
  end
71
70
  end
72
71
 
@@ -107,6 +106,5 @@ module NewRelic
107
106
  end
108
107
  end
109
108
  end
110
-
111
109
  end
112
110
  end
@@ -44,12 +44,13 @@ module NewRelic
44
44
 
45
45
  # Don't nest transactions if we're already in a web transaction.
46
46
  # Probably inline processing the job if that happens, so just trace.
47
- if txn && txn.recording_web_transaction?
47
+ if txn && txn.recording_web_transaction?
48
48
  run_in_trace(job, block, :Consume)
49
49
  elsif txn && !txn.recording_web_transaction?
50
50
  ::NewRelic::Agent::Transaction.set_default_transaction_name(
51
51
  transaction_name_suffix_for_job(job),
52
- transaction_category)
52
+ transaction_category
53
+ )
53
54
  block.call
54
55
  else
55
56
  run_in_transaction(job, block)
@@ -64,7 +65,7 @@ module NewRelic
64
65
 
65
66
  def self.run_in_transaction(job, block)
66
67
  ::NewRelic::Agent::Tracer.in_transaction(name: transaction_name_for_job(job),
67
- category: :other,
68
+ category: :other,
68
69
  &block)
69
70
  end
70
71
 
@@ -27,8 +27,8 @@ DependencyDetection.defer do
27
27
  [:authorize, :purchase, :credit, :void, :capture, :recurring, :store, :unstore, :update].each do |operation|
28
28
  if implemented_methods.include?(operation)
29
29
  add_method_tracer operation, [-> (*) { "ActiveMerchant/gateway/#{gateway_name}/#{operation}" },
30
- -> (*) { "ActiveMerchant/gateway/#{gateway_name}" },
31
- -> (*) { "ActiveMerchant/operation/#{operation}" }]
30
+ -> (*) { "ActiveMerchant/gateway/#{gateway_name}" },
31
+ -> (*) { "ActiveMerchant/operation/#{operation}" }]
32
32
  end
33
33
  end
34
34
  end