newrelic_rpm 8.2.0 → 8.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +1938 -0
  4. data/Brewfile +10 -0
  5. data/CHANGELOG.md +80 -2
  6. data/CONTRIBUTING.md +19 -3
  7. data/DOCKER.md +167 -0
  8. data/Dockerfile +10 -0
  9. data/Guardfile +8 -8
  10. data/Rakefile +14 -9
  11. data/bin/mongrel_rpm +8 -9
  12. data/bin/newrelic +1 -1
  13. data/bin/nrdebug +14 -14
  14. data/docker-compose.yml +85 -0
  15. data/init.rb +0 -2
  16. data/lefthook.yml +9 -0
  17. data/lib/new_relic/agent/adaptive_sampler.rb +7 -3
  18. data/lib/new_relic/agent/agent.rb +38 -40
  19. data/lib/new_relic/agent/agent_logger.rb +8 -9
  20. data/lib/new_relic/agent/attribute_filter.rb +31 -31
  21. data/lib/new_relic/agent/attributes.rb +2 -2
  22. data/lib/new_relic/agent/autostart.rb +6 -7
  23. data/lib/new_relic/agent/commands/agent_command.rb +2 -2
  24. data/lib/new_relic/agent/commands/agent_command_router.rb +6 -5
  25. data/lib/new_relic/agent/commands/thread_profiler_session.rb +0 -3
  26. data/lib/new_relic/agent/configuration/default_source.rb +347 -330
  27. data/lib/new_relic/agent/configuration/dotted_hash.rb +3 -3
  28. data/lib/new_relic/agent/configuration/environment_source.rb +3 -4
  29. data/lib/new_relic/agent/configuration/event_harvest_config.rb +11 -6
  30. data/lib/new_relic/agent/configuration/high_security_source.rb +7 -7
  31. data/lib/new_relic/agent/configuration/manager.rb +74 -63
  32. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
  33. data/lib/new_relic/agent/configuration/security_policy_source.rb +73 -73
  34. data/lib/new_relic/agent/configuration/server_source.rb +11 -11
  35. data/lib/new_relic/agent/configuration/yaml_source.rb +9 -9
  36. data/lib/new_relic/agent/connect/request_builder.rb +13 -16
  37. data/lib/new_relic/agent/connect/response_handler.rb +0 -3
  38. data/lib/new_relic/agent/custom_event_aggregator.rb +9 -10
  39. data/lib/new_relic/agent/database/explain_plan_helpers.rb +3 -4
  40. data/lib/new_relic/agent/database/obfuscation_helpers.rb +12 -12
  41. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +2 -2
  42. data/lib/new_relic/agent/database.rb +20 -24
  43. data/lib/new_relic/agent/datastores/metric_helper.rb +10 -10
  44. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -3
  45. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +3 -5
  46. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +1 -2
  47. data/lib/new_relic/agent/datastores/redis.rb +2 -4
  48. data/lib/new_relic/agent/datastores.rb +1 -3
  49. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +5 -5
  50. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +11 -10
  51. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +10 -11
  52. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +41 -42
  53. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +3 -3
  54. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +41 -43
  55. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +23 -23
  56. data/lib/new_relic/agent/distributed_tracing.rb +17 -18
  57. data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
  58. data/lib/new_relic/agent/error_collector.rb +17 -17
  59. data/lib/new_relic/agent/error_event_aggregator.rb +1 -1
  60. data/lib/new_relic/agent/error_filter.rb +6 -8
  61. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -1
  62. data/lib/new_relic/agent/event_aggregator.rb +1 -1
  63. data/lib/new_relic/agent/event_buffer.rb +6 -7
  64. data/lib/new_relic/agent/event_listener.rb +0 -1
  65. data/lib/new_relic/agent/event_loop.rb +10 -10
  66. data/lib/new_relic/agent/external.rb +1 -2
  67. data/lib/new_relic/agent/guid_generator.rb +2 -9
  68. data/lib/new_relic/agent/harvester.rb +3 -4
  69. data/lib/new_relic/agent/heap.rb +1 -3
  70. data/lib/new_relic/agent/hostname.rb +3 -3
  71. data/lib/new_relic/agent/http_clients/abstract.rb +5 -7
  72. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -5
  73. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +4 -4
  74. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +3 -3
  75. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +1 -2
  76. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +2 -3
  77. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +2 -3
  78. data/lib/new_relic/agent/http_clients/uri_util.rb +0 -1
  79. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +2 -3
  80. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +9 -10
  81. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +5 -7
  82. data/lib/new_relic/agent/instrumentation/active_job.rb +4 -4
  83. data/lib/new_relic/agent/instrumentation/active_merchant.rb +2 -2
  84. data/lib/new_relic/agent/instrumentation/active_record.rb +20 -18
  85. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +36 -42
  86. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +28 -25
  87. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +3 -3
  88. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +5 -6
  89. data/lib/new_relic/agent/instrumentation/active_storage.rb +1 -1
  90. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +8 -9
  91. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +1 -1
  92. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +7 -8
  93. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +41 -41
  94. data/lib/new_relic/agent/instrumentation/curb/chain.rb +19 -20
  95. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +34 -38
  96. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +9 -10
  97. data/lib/new_relic/agent/instrumentation/data_mapper.rb +10 -10
  98. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +5 -7
  99. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +2 -6
  100. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +4 -4
  101. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -2
  102. data/lib/new_relic/agent/instrumentation/excon.rb +0 -1
  103. data/lib/new_relic/agent/instrumentation/grape/chain.rb +1 -2
  104. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +6 -7
  105. data/lib/new_relic/agent/instrumentation/grape.rb +2 -3
  106. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +2 -3
  107. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +0 -1
  108. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +0 -2
  109. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +2 -2
  110. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +6 -6
  111. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -1
  112. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -3
  113. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +0 -1
  114. data/lib/new_relic/agent/instrumentation/logger.rb +1 -1
  115. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +2 -1
  116. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +0 -1
  117. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +1 -0
  118. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +9 -10
  119. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +5 -6
  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/instrumentation.rb +3 -2
  127. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +1 -1
  128. data/lib/new_relic/agent/instrumentation/padrino.rb +0 -5
  129. data/lib/new_relic/agent/instrumentation/queue_time.rb +5 -5
  130. data/lib/new_relic/agent/instrumentation/rack/chain.rb +5 -5
  131. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +0 -1
  132. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +4 -5
  133. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +0 -1
  134. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  135. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -6
  136. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +2 -2
  137. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +0 -1
  138. data/lib/new_relic/agent/instrumentation/rake/chain.rb +0 -5
  139. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +6 -6
  140. data/lib/new_relic/agent/instrumentation/rake.rb +1 -1
  141. data/lib/new_relic/agent/instrumentation/redis/chain.rb +6 -6
  142. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +2 -2
  143. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +1 -1
  144. data/lib/new_relic/agent/instrumentation/redis.rb +1 -1
  145. data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -3
  146. data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
  147. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +4 -4
  148. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -2
  149. data/lib/new_relic/agent/instrumentation/resque.rb +7 -7
  150. data/lib/new_relic/agent/instrumentation/sequel.rb +7 -9
  151. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
  152. data/lib/new_relic/agent/instrumentation/sidekiq.rb +5 -4
  153. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +0 -1
  154. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +4 -3
  155. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  156. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +0 -1
  157. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +4 -4
  158. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +3 -5
  159. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +1 -1
  160. data/lib/new_relic/agent/internal_agent_error.rb +1 -1
  161. data/lib/new_relic/agent/javascript_instrumentor.rb +28 -28
  162. data/lib/new_relic/agent/logging.rb +8 -4
  163. data/lib/new_relic/agent/memory_logger.rb +1 -1
  164. data/lib/new_relic/agent/messaging.rb +42 -44
  165. data/lib/new_relic/agent/method_tracer.rb +11 -14
  166. data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
  167. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +13 -12
  168. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +2 -2
  169. data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +0 -1
  170. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +4 -7
  171. data/lib/new_relic/agent/monitors.rb +1 -2
  172. data/lib/new_relic/agent/new_relic_service/encoders.rb +4 -4
  173. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -1
  174. data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
  175. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +4 -3
  176. data/lib/new_relic/agent/new_relic_service.rb +20 -20
  177. data/lib/new_relic/agent/noticible_error.rb +0 -2
  178. data/lib/new_relic/agent/null_logger.rb +6 -2
  179. data/lib/new_relic/agent/obfuscator.rb +6 -8
  180. data/lib/new_relic/agent/parameter_filtering.rb +16 -8
  181. data/lib/new_relic/agent/payload_metric_mapping.rb +8 -9
  182. data/lib/new_relic/agent/pipe_channel_manager.rb +5 -6
  183. data/lib/new_relic/agent/pipe_service.rb +1 -1
  184. data/lib/new_relic/agent/priority_sampled_buffer.rb +4 -7
  185. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +9 -9
  186. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +12 -12
  187. data/lib/new_relic/agent/rules_engine.rb +2 -2
  188. data/lib/new_relic/agent/sampler.rb +2 -3
  189. data/lib/new_relic/agent/sampler_collection.rb +2 -3
  190. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +3 -3
  191. data/lib/new_relic/agent/samplers/memory_sampler.rb +4 -3
  192. data/lib/new_relic/agent/samplers/vm_sampler.rb +18 -18
  193. data/lib/new_relic/agent/span_event_aggregator.rb +8 -8
  194. data/lib/new_relic/agent/span_event_primitive.rb +39 -39
  195. data/lib/new_relic/agent/sql_sampler.rb +9 -9
  196. data/lib/new_relic/agent/stats.rb +16 -16
  197. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +7 -9
  198. data/lib/new_relic/agent/stats_engine/stats_hash.rb +8 -9
  199. data/lib/new_relic/agent/stats_engine.rb +6 -6
  200. data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -2
  201. data/lib/new_relic/agent/system_info.rb +22 -20
  202. data/lib/new_relic/agent/threading/agent_thread.rb +4 -5
  203. data/lib/new_relic/agent/threading/backtrace_node.rb +6 -9
  204. data/lib/new_relic/agent/threading/backtrace_service.rb +8 -8
  205. data/lib/new_relic/agent/threading/thread_profile.rb +15 -18
  206. data/lib/new_relic/agent/tracer.rb +37 -43
  207. data/lib/new_relic/agent/transaction/abstract_segment.rb +6 -6
  208. data/lib/new_relic/agent/transaction/datastore_segment.rb +5 -7
  209. data/lib/new_relic/agent/transaction/distributed_tracer.rb +7 -9
  210. data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -22
  211. data/lib/new_relic/agent/transaction/external_request_segment.rb +3 -5
  212. data/lib/new_relic/agent/transaction/message_broker_segment.rb +23 -23
  213. data/lib/new_relic/agent/transaction/request_attributes.rb +7 -7
  214. data/lib/new_relic/agent/transaction/segment.rb +3 -3
  215. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +0 -2
  216. data/lib/new_relic/agent/transaction/trace.rb +8 -8
  217. data/lib/new_relic/agent/transaction/trace_context.rb +14 -16
  218. data/lib/new_relic/agent/transaction/trace_node.rb +16 -16
  219. data/lib/new_relic/agent/transaction/tracing.rb +1 -3
  220. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -2
  221. data/lib/new_relic/agent/transaction.rb +79 -81
  222. data/lib/new_relic/agent/transaction_error_primitive.rb +16 -16
  223. data/lib/new_relic/agent/transaction_event_aggregator.rb +7 -8
  224. data/lib/new_relic/agent/transaction_event_primitive.rb +29 -29
  225. data/lib/new_relic/agent/transaction_event_recorder.rb +1 -1
  226. data/lib/new_relic/agent/transaction_metrics.rb +3 -3
  227. data/lib/new_relic/agent/transaction_sampler.rb +0 -1
  228. data/lib/new_relic/agent/transaction_time_aggregator.rb +6 -6
  229. data/lib/new_relic/agent/utilization/aws.rb +32 -2
  230. data/lib/new_relic/agent/utilization/azure.rb +1 -1
  231. data/lib/new_relic/agent/utilization/vendor.rb +15 -2
  232. data/lib/new_relic/agent/utilization_data.rb +3 -4
  233. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  234. data/lib/new_relic/agent/vm/snapshot.rb +3 -3
  235. data/lib/new_relic/agent/worker_loop.rb +3 -5
  236. data/lib/new_relic/agent.rb +22 -22
  237. data/lib/new_relic/cli/command.rb +15 -17
  238. data/lib/new_relic/cli/commands/deployments.rb +20 -22
  239. data/lib/new_relic/cli/commands/install.rb +6 -10
  240. data/lib/new_relic/coerce.rb +5 -8
  241. data/lib/new_relic/collection_helper.rb +48 -47
  242. data/lib/new_relic/control/class_methods.rb +2 -2
  243. data/lib/new_relic/control/frameworks/external.rb +1 -1
  244. data/lib/new_relic/control/frameworks/rails.rb +5 -6
  245. data/lib/new_relic/control/frameworks/rails3.rb +2 -3
  246. data/lib/new_relic/control/frameworks/ruby.rb +2 -2
  247. data/lib/new_relic/control/frameworks/sinatra.rb +6 -0
  248. data/lib/new_relic/control/instance_methods.rb +4 -5
  249. data/lib/new_relic/control/instrumentation.rb +4 -5
  250. data/lib/new_relic/control/server_methods.rb +2 -3
  251. data/lib/new_relic/control.rb +0 -1
  252. data/lib/new_relic/dependency_detection.rb +6 -8
  253. data/lib/new_relic/environment_report.rb +16 -18
  254. data/lib/new_relic/helper.rb +5 -5
  255. data/lib/new_relic/language_support.rb +3 -2
  256. data/lib/new_relic/latest_changes.rb +2 -2
  257. data/lib/new_relic/local_environment.rb +7 -7
  258. data/lib/new_relic/metric_data.rb +6 -7
  259. data/lib/new_relic/metric_spec.rb +3 -3
  260. data/lib/new_relic/noticed_error.rb +14 -15
  261. data/lib/new_relic/rack/agent_middleware.rb +2 -2
  262. data/lib/new_relic/rack/browser_monitoring.rb +9 -9
  263. data/lib/new_relic/recipes/capistrano3.rb +11 -13
  264. data/lib/new_relic/recipes/capistrano_legacy.rb +11 -14
  265. data/lib/new_relic/supportability_helper.rb +1 -2
  266. data/lib/new_relic/version.rb +4 -15
  267. data/lib/sequel/extensions/newrelic_instrumentation.rb +4 -7
  268. data/lib/sequel/plugins/newrelic_instrumentation.rb +3 -9
  269. data/lib/tasks/all.rb +1 -1
  270. data/lib/tasks/config.rake +21 -21
  271. data/lib/tasks/multiverse.rb +4 -6
  272. data/lib/tasks/tests.rake +3 -7
  273. data/newrelic.yml +3 -3
  274. data/newrelic_rpm.gemspec +13 -12
  275. data/recipes/newrelic.rb +1 -1
  276. data/test/agent_helper.rb +55 -55
  277. metadata +38 -4
@@ -7,7 +7,6 @@ require 'new_relic/version'
7
7
  require 'erb'
8
8
 
9
9
  class NewRelic::Cli::Install < NewRelic::Cli::Command
10
-
11
10
  NO_LICENSE_KEY = "<PASTE LICENSE KEY HERE>"
12
11
 
13
12
  def self.command; "install"; end
@@ -21,7 +20,7 @@ class NewRelic::Cli::Install < NewRelic::Cli::Command
21
20
  # Will throw CommandFailed exception if there's any error.
22
21
  #
23
22
  attr_reader :dest_dir, :license_key, :generated_for_user, :quiet, :src_file, :app_name
24
- def initialize command_line_args={}
23
+ def initialize command_line_args = {}
25
24
  @dest_dir = nil
26
25
  super command_line_args
27
26
  if @dest_dir.nil?
@@ -43,7 +42,7 @@ class NewRelic::Cli::Install < NewRelic::Cli::Command
43
42
  if File.exist?(dest_file) && !@force
44
43
  raise NewRelic::Cli::Command::CommandFailure, "newrelic.yml file already exists. Use --force flag to overwrite."
45
44
  end
46
- File.open(dest_file, 'w') { | out | out.puts(content) }
45
+ File.open(dest_file, 'w') { |out| out.puts(content) }
47
46
 
48
47
  puts <<-EOF unless quiet
49
48
 
@@ -60,11 +59,10 @@ you receive upon registration.
60
59
 
61
60
  Visit support.newrelic.com if you are experiencing installation issues.
62
61
  EOF
63
-
64
62
  end
65
63
 
66
64
  def content
67
- @src_file ||= File.expand_path(File.join(File.dirname(__FILE__),"..","..","..","..","newrelic.yml"))
65
+ @src_file ||= File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", "newrelic.yml"))
68
66
  template = File.read(@src_file)
69
67
  ERB.new(template).result(binding)
70
68
  end
@@ -73,14 +71,12 @@ Visit support.newrelic.com if you are experiencing installation issues.
73
71
 
74
72
  def options
75
73
  OptionParser.new "Usage: #{$0} #{self.class.command} [ OPTIONS] 'application name'", 40 do |o|
76
- o.on("-f", "--force", "Overwrite newrelic.yml if it exists") { | e | @force = true }
74
+ o.on("-f", "--force", "Overwrite newrelic.yml if it exists") { |e| @force = true }
77
75
  o.on("-l", "--license_key=NAME", String,
78
- "Use the given license key") { | e | @license_key = e }
76
+ "Use the given license key") { |e| @license_key = e }
79
77
  o.on("-d", "--destdir=name", String,
80
- "Write the newrelic.yml to the given directory, default is '.'") { | e | @dest_dir = e }
78
+ "Write the newrelic.yml to the given directory, default is '.'") { |e| @dest_dir = e }
81
79
  yield o if block_given?
82
80
  end
83
81
  end
84
-
85
-
86
82
  end
@@ -5,7 +5,6 @@
5
5
 
6
6
  module NewRelic
7
7
  module Coerce
8
-
9
8
  module_function
10
9
 
11
10
  # We really don't want to send bad values to the collector, and it doesn't
@@ -15,14 +14,14 @@ module NewRelic
15
14
  # to provide documentation of expected types on to_collector_array methods,
16
15
  # and to log failures if totally invalid data gets into outgoing data
17
16
 
18
- def int(value, context=nil)
17
+ def int(value, context = nil)
19
18
  Integer(value)
20
19
  rescue => error
21
20
  log_failure(value, Integer, context, error)
22
21
  0
23
22
  end
24
23
 
25
- def int_or_nil(value, context=nil)
24
+ def int_or_nil(value, context = nil)
26
25
  return nil if value.nil?
27
26
  Integer(value)
28
27
  rescue => error
@@ -30,7 +29,7 @@ module NewRelic
30
29
  nil
31
30
  end
32
31
 
33
- def float(value, context=nil)
32
+ def float(value, context = nil)
34
33
  result = Float(value)
35
34
  raise "Value #{result.inspect} is not finite." unless result.finite?
36
35
  result
@@ -39,7 +38,7 @@ module NewRelic
39
38
  0.0
40
39
  end
41
40
 
42
- def string(value, context=nil)
41
+ def string(value, context = nil)
43
42
  return value if value.nil?
44
43
  String(value)
45
44
  rescue => error
@@ -54,8 +53,6 @@ module NewRelic
54
53
  when Float
55
54
  if val.finite?
56
55
  val
57
- else
58
- nil
59
56
  end
60
57
  when Symbol
61
58
  val.to_s
@@ -76,7 +73,7 @@ module NewRelic
76
73
  value.to_i
77
74
  end
78
75
 
79
- def float! value, precision=NewRelic::PRIORITY_PRECISION
76
+ def float! value, precision = NewRelic::PRIORITY_PRECISION
80
77
  return nil unless value_or_nil(value)
81
78
  value.to_f.round(precision)
82
79
  end
@@ -4,58 +4,59 @@
4
4
 
5
5
  module NewRelic
6
6
  module CollectionHelper
7
- DEFAULT_TRUNCATION_SIZE=16 * 1024
8
- DEFAULT_ARRAY_TRUNCATION_SIZE=128
9
- # Transform parameter hash into a hash whose values are strictly
10
- # strings
11
- def normalize_params(params)
12
- case params
13
- when Hash
14
- # optimize for empty hash since that is often what this is called with.
15
- return params if params.empty?
16
- new_params = {}
17
- params.each do | key, value |
18
- new_params[truncate(normalize_params(key),64)] = normalize_params(value)
19
- end
20
- new_params
21
- when Symbol, FalseClass, TrueClass, nil
22
- params
23
- when Numeric
24
- truncate(params.to_s)
25
- when String
26
- truncate(params)
27
- when Array
28
- params.first(DEFAULT_ARRAY_TRUNCATION_SIZE).map{|item| normalize_params(item)}
29
- else
30
- truncate(flatten(params))
7
+ DEFAULT_TRUNCATION_SIZE = 16 * 1024
8
+ DEFAULT_ARRAY_TRUNCATION_SIZE = 128
9
+ # Transform parameter hash into a hash whose values are strictly
10
+ # strings
11
+ def normalize_params(params)
12
+ case params
13
+ when Hash
14
+ # optimize for empty hash since that is often what this is called with.
15
+ return params if params.empty?
16
+ new_params = {}
17
+ params.each do |key, value|
18
+ new_params[truncate(normalize_params(key), 64)] = normalize_params(value)
19
+ end
20
+ new_params
21
+ when Symbol, FalseClass, TrueClass, nil
22
+ params
23
+ when Numeric
24
+ truncate(params.to_s)
25
+ when String
26
+ truncate(params)
27
+ when Array
28
+ params.first(DEFAULT_ARRAY_TRUNCATION_SIZE).map { |item| normalize_params(item) }
29
+ else
30
+ truncate(flatten(params))
31
+ end
31
32
  end
32
- end
33
33
 
34
- private
34
+ private
35
35
 
36
- # Convert any kind of object to a short string.
37
- def flatten(object)
38
- case object
39
- when nil then ''
40
- when object.instance_of?(String) then object
41
- when String then String.new(object) # convert string subclasses to strings
42
- else "#<#{object.class.to_s}>"
36
+ # Convert any kind of object to a short string.
37
+ def flatten(object)
38
+ case object
39
+ when nil then ''
40
+ when object.instance_of?(String) then object
41
+ when String then String.new(object) # convert string subclasses to strings
42
+ else "#<#{object.class.to_s}>"
43
+ end
43
44
  end
44
- end
45
- def truncate(string, len=DEFAULT_TRUNCATION_SIZE)
46
- case string
47
- when Symbol then string
48
- when nil then ""
49
- when String
50
- real_string = flatten(string)
51
- if real_string.size > len
52
- real_string = real_string.slice(0...len)
53
- real_string << "..."
45
+
46
+ def truncate(string, len = DEFAULT_TRUNCATION_SIZE)
47
+ case string
48
+ when Symbol then string
49
+ when nil then ""
50
+ when String
51
+ real_string = flatten(string)
52
+ if real_string.size > len
53
+ real_string = real_string.slice(0...len)
54
+ real_string << "..."
55
+ end
56
+ real_string
57
+ else
58
+ truncate(flatten(string), len)
54
59
  end
55
- real_string
56
- else
57
- truncate(flatten(string), len)
58
60
  end
59
61
  end
60
- end
61
62
  end
@@ -9,7 +9,7 @@ module NewRelic
9
9
  module ClassMethods
10
10
  # Access the Control singleton, lazy initialized. Default will instantiate a new
11
11
  # instance or pass false to defer
12
- def instance(create=true)
12
+ def instance(create = true)
13
13
  @instance ||= create && new_instance
14
14
  end
15
15
 
@@ -35,7 +35,7 @@ module NewRelic
35
35
 
36
36
  # nb this does not 'load test' the framework, it loads the 'test framework'
37
37
  def load_test_framework
38
- config = File.expand_path(File.join('..','..','..','..', "test","config","newrelic.yml"), __FILE__)
38
+ config = File.expand_path(File.join('..', '..', '..', '..', "test", "config", "newrelic.yml"), __FILE__)
39
39
  require "config/test_control"
40
40
  NewRelic::Control::Frameworks::Test.new(local_env, config)
41
41
  end
@@ -11,7 +11,7 @@ module NewRelic
11
11
  # out specifically because in this context we are not monitoring
12
12
  # the running process, but actually external things.
13
13
  class External < NewRelic::Control::Frameworks::Ruby
14
- def init_config(options={})
14
+ def init_config(options = {})
15
15
  super
16
16
  end
17
17
  end
@@ -10,9 +10,8 @@ module NewRelic
10
10
  # Rails specific configuration, instrumentation, environment values,
11
11
  # etc.
12
12
  class Rails < NewRelic::Control::Frameworks::Ruby
13
-
14
13
  def env
15
- @env ||= ( ENV['NEW_RELIC_ENV'] || RAILS_ENV.dup )
14
+ @env ||= (ENV['NEW_RELIC_ENV'] || RAILS_ENV.dup)
16
15
  end
17
16
 
18
17
  # Rails can return an empty string from this method, causing
@@ -43,7 +42,7 @@ module NewRelic
43
42
  # In versions of Rails prior to 2.0, the rails config was only available to
44
43
  # the init.rb, so it had to be passed on from there. This is a best effort to
45
44
  # find a config and use that.
46
- def init_config(options={})
45
+ def init_config(options = {})
47
46
  @config = options[:config]
48
47
  # Install the dependency detection,
49
48
  if rails_config && ::Rails.configuration.respond_to?(:after_initialize)
@@ -63,8 +62,8 @@ module NewRelic
63
62
  end
64
63
  rescue => e
65
64
  ::NewRelic::Agent.logger.error("Failure during init_config for Rails. Is Rails required in a non-Rails app? Set NEW_RELIC_FRAMEWORK=ruby to avoid this message.",
66
- "The Ruby agent will continue running, but Rails-specific features may be missing.",
67
- e)
65
+ "The Ruby agent will continue running, but Rails-specific features may be missing.",
66
+ e)
68
67
  end
69
68
 
70
69
  def install_agent_hooks(config)
@@ -103,7 +102,7 @@ module NewRelic
103
102
  protected
104
103
 
105
104
  def rails_vendor_root
106
- File.join(root,'vendor','rails')
105
+ File.join(root, 'vendor', 'rails')
107
106
  end
108
107
 
109
108
  def install_shim
@@ -13,9 +13,8 @@ module NewRelic
13
13
  # NewRelic::Control::Frameworks::Rails class, where the two do
14
14
  # not differ
15
15
  class Rails3 < NewRelic::Control::Frameworks::Rails
16
-
17
16
  def env
18
- @env ||= ( ENV['NEW_RELIC_ENV'] || ::Rails.env.to_s )
17
+ @env ||= (ENV['NEW_RELIC_ENV'] || ::Rails.env.to_s)
19
18
  end
20
19
 
21
20
  def rails_root
@@ -23,7 +22,7 @@ module NewRelic
23
22
  end
24
23
 
25
24
  def vendor_root
26
- @vendor_root ||= File.join(root,'vendor','rails')
25
+ @vendor_root ||= File.join(root, 'vendor', 'rails')
27
26
  end
28
27
 
29
28
  def version
@@ -9,14 +9,14 @@ module NewRelic
9
9
  class Ruby < NewRelic::Control
10
10
  def env
11
11
  @env ||= ENV['NEW_RELIC_ENV'] || ENV['RUBY_ENV'] || ENV['RAILS_ENV'] ||
12
- ENV['APP_ENV'] || ENV['RACK_ENV'] || 'development'
12
+ ENV['APP_ENV'] || ENV['RACK_ENV'] || 'development'
13
13
  end
14
14
 
15
15
  def root
16
16
  @root ||= ENV['APP_ROOT'] || '.'
17
17
  end
18
18
 
19
- def init_config(options={})
19
+ def init_config(options = {})
20
20
  end
21
21
  end
22
22
  end
@@ -8,6 +8,12 @@ module NewRelic
8
8
  module Frameworks
9
9
  # Contains basic control logic for Sinatra
10
10
  class Sinatra < NewRelic::Control::Frameworks::Ruby
11
+ protected
12
+
13
+ def install_shim
14
+ super
15
+ ::Sinatra::Base.class_eval { include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim }
16
+ end
11
17
  end
12
18
  end
13
19
  end
@@ -8,7 +8,6 @@ require 'new_relic/agent/agent_logger'
8
8
 
9
9
  module NewRelic
10
10
  class Control
11
-
12
11
  # Contains methods that relate to the runtime usage of the control
13
12
  # object. Note that these are subject to override in the
14
13
  # NewRelic::Control::Framework classes that are actually instantiated
@@ -47,7 +46,7 @@ module NewRelic
47
46
  # Subclasses are not allowed to override, but must implement
48
47
  # init_config({}) which is called one or more times.
49
48
  #
50
- def init_plugin(options={})
49
+ def init_plugin(options = {})
51
50
  env = determine_env(options)
52
51
 
53
52
  configure_agent(env, options)
@@ -87,10 +86,10 @@ module NewRelic
87
86
 
88
87
  if @started_in_env && @started_in_env != env
89
88
  Agent.logger.error("Attempted to start agent in #{env.inspect} environment, but agent was already running in #{@started_in_env.inspect}",
90
- "The agent will continue running in #{@started_in_env.inspect}. To alter this, ensure the desired environment is set before the agent starts.")
89
+ "The agent will continue running in #{@started_in_env.inspect}. To alter this, ensure the desired environment is set before the agent starts.")
91
90
  else
92
91
  Agent.logger.info("Starting the New Relic agent version #{NewRelic::VERSION::STRING} in #{env.inspect} environment.",
93
- "To prevent agent startup add a NEW_RELIC_AGENT_ENABLED=false environment variable or modify the #{env.inspect} section of your newrelic.yml.")
92
+ "To prevent agent startup add a NEW_RELIC_AGENT_ENABLED=false environment variable or modify the #{env.inspect} section of your newrelic.yml.")
94
93
  end
95
94
 
96
95
  env
@@ -164,7 +163,7 @@ module NewRelic
164
163
 
165
164
  protected
166
165
 
167
- def initialize(local_env, config_file_override=nil)
166
+ def initialize(local_env, config_file_override = nil)
168
167
  @install_lock = Mutex.new
169
168
  @local_env = local_env
170
169
  @started_in_env = nil
@@ -7,7 +7,6 @@ module NewRelic
7
7
  # Contains methods that relate to adding and executing files that
8
8
  # contain instrumentation for the Ruby Agent
9
9
  module Instrumentation
10
-
11
10
  # Adds a list of files in Dir.glob format
12
11
  # (e.g. '/app/foo/**/*_instrumentation.rb')
13
12
  # This requires the files within a rescue block, so that any
@@ -57,11 +56,11 @@ module NewRelic
57
56
 
58
57
  # Instrumentation for the key code points inside rails for monitoring by NewRelic.
59
58
  # note this file is loaded only if the newrelic agent is enabled (through config/newrelic.yml)
60
- instrumentation_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'agent','instrumentation'))
59
+ instrumentation_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'agent', 'instrumentation'))
61
60
  @instrumentation_files <<
62
- File.join(instrumentation_path, '*.rb') <<
63
- File.join(instrumentation_path, app.to_s, '*.rb')
64
- @instrumentation_files.each { | pattern | load_instrumentation_files pattern }
61
+ File.join(instrumentation_path, '*.rb') <<
62
+ File.join(instrumentation_path, app.to_s, '*.rb')
63
+ @instrumentation_files.each { |pattern| load_instrumentation_files pattern }
65
64
  DependencyDetection.detect!
66
65
  ::NewRelic::Agent.logger.info "Finished instrumentation"
67
66
  end
@@ -4,9 +4,8 @@
4
4
 
5
5
  module NewRelic
6
6
  class Control
7
-
8
7
  # Structs holding info for the remote server and proxy server
9
- class Server < Struct.new :name, :port #:nodoc:
8
+ class Server < Struct.new :name, :port # :nodoc:
10
9
  def to_s; "#{name}:#{port}"; end
11
10
  end
12
11
 
@@ -22,7 +21,7 @@ module NewRelic
22
21
  @api_server ||= NewRelic::Control::Server.new(Agent.config[:api_host], Agent.config[:api_port])
23
22
  end
24
23
 
25
- def server_from_host(hostname=nil)
24
+ def server_from_host(hostname = nil)
26
25
  NewRelic::Control::Server.new(hostname || Agent.config[:host], Agent.config[:port])
27
26
  end
28
27
  end
@@ -23,7 +23,6 @@ require 'new_relic/agent'
23
23
  require 'new_relic/delayed_job_injection'
24
24
 
25
25
  module NewRelic
26
-
27
26
  # The Control is a singleton responsible for the startup and
28
27
  # initialization sequence. The initializer uses a LocalEnvironment to
29
28
  # detect the framework and instantiates the framework specific
@@ -3,7 +3,6 @@
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  module DependencyDetection
6
-
7
6
  module_function
8
7
 
9
8
  @items = []
@@ -33,7 +32,7 @@ module DependencyDetection
33
32
  end
34
33
 
35
34
  def dependency_by_name(name)
36
- @items.find {|i| i.name == name }
35
+ @items.find { |i| i.name == name }
37
36
  end
38
37
 
39
38
  def installed?(name)
@@ -56,7 +55,6 @@ module DependencyDetection
56
55
  attr_reader :dependencies
57
56
  attr_reader :prepend_conflicts
58
57
 
59
-
60
58
  def executed!
61
59
  @executed = true
62
60
  end
@@ -95,19 +93,19 @@ module DependencyDetection
95
93
  yield
96
94
  end
97
95
 
98
- def prepend_instrument target_class, instrumenting_module, supportability_name=nil
96
+ def prepend_instrument target_class, instrumenting_module, supportability_name = nil
99
97
  log_and_instrument("Prepend", instrumenting_module, supportability_name) do
100
98
  target_class.send :prepend, instrumenting_module
101
99
  end
102
100
  end
103
101
 
104
- def chain_instrument instrumenting_module, supportability_name=nil
102
+ def chain_instrument instrumenting_module, supportability_name = nil
105
103
  log_and_instrument("MethodChaining", instrumenting_module, supportability_name) do
106
104
  instrumenting_module.instrument!
107
105
  end
108
106
  end
109
107
 
110
- def chain_instrument_target target, instrumenting_module, supportability_name=nil
108
+ def chain_instrument_target target, instrumenting_module, supportability_name = nil
111
109
  NewRelic::Agent.logger.info "Installing deferred #{target} instrumentation"
112
110
  log_and_instrument("MethodChaining", instrumenting_module, supportability_name) do
113
111
  instrumenting_module.instrument! target
@@ -134,7 +132,7 @@ module DependencyDetection
134
132
  begin
135
133
  dep.call
136
134
  rescue => err
137
- NewRelic::Agent.logger.error( "Error while detecting #{self.name}:", err )
135
+ NewRelic::Agent.logger.error("Error while detecting #{self.name}:", err)
138
136
  false
139
137
  end
140
138
  end
@@ -222,7 +220,7 @@ module DependencyDetection
222
220
  begin
223
221
  conflict.call
224
222
  rescue => err
225
- NewRelic::Agent.logger.error( "Error while checking prepend conflicts #{self.name}:", err )
223
+ NewRelic::Agent.logger.error("Error while checking prepend conflicts #{self.name}:", err)
226
224
  false # assumes no conflicts exist since `prepend` is preferred method of instrumenting
227
225
  end
228
226
  end
@@ -13,7 +13,6 @@ module NewRelic
13
13
  # Additional logic can be registered by using the EnvironmentReport.report_on
14
14
  # hook.
15
15
  class EnvironmentReport
16
-
17
16
  # This is the main interface for registering logic that should be included
18
17
  # in the Environment Report. For example:
19
18
  #
@@ -57,23 +56,23 @@ module NewRelic
57
56
  end
58
57
  end
59
58
  end
60
- report_on('Plugin List' ) { ::Rails.configuration.plugins.to_a }
61
- report_on('Ruby version' ) { RUBY_VERSION }
62
- report_on('Ruby description' ) { RUBY_DESCRIPTION }
63
- report_on('Ruby platform' ) { RUBY_PLATFORM }
64
- report_on('Ruby patchlevel' ) { RUBY_PATCHLEVEL.to_s }
65
- report_on('JRuby version' ) { JRUBY_VERSION }
66
- report_on('Java VM version' ) { ENV_JAVA['java.vm.version'] }
59
+ report_on('Plugin List') { ::Rails.configuration.plugins.to_a }
60
+ report_on('Ruby version') { RUBY_VERSION }
61
+ report_on('Ruby description') { RUBY_DESCRIPTION }
62
+ report_on('Ruby platform') { RUBY_PLATFORM }
63
+ report_on('Ruby patchlevel') { RUBY_PATCHLEVEL.to_s }
64
+ report_on('JRuby version') { JRUBY_VERSION }
65
+ report_on('Java VM version') { ENV_JAVA['java.vm.version'] }
67
66
  report_on('Logical Processors') { ::NewRelic::Agent::SystemInfo.num_logical_processors }
68
- report_on('Physical Cores' ) { ::NewRelic::Agent::SystemInfo.num_physical_cores }
69
- report_on('Arch' ) { ::NewRelic::Agent::SystemInfo.processor_arch }
70
- report_on('OS version' ) { ::NewRelic::Agent::SystemInfo.os_version }
71
- report_on('OS' ) { ::NewRelic::Agent::SystemInfo.ruby_os_identifier }
72
- report_on('Database adapter' ) { ::NewRelic::Agent::DatabaseAdapter.value }
73
- report_on('Framework' ) { Agent.config[:framework].to_s }
74
- report_on('Dispatcher' ) { Agent.config[:dispatcher].to_s }
75
- report_on('Environment' ) { NewRelic::Control.instance.env }
76
- report_on('Rails version' ) { ::Rails::VERSION::STRING }
67
+ report_on('Physical Cores') { ::NewRelic::Agent::SystemInfo.num_physical_cores }
68
+ report_on('Arch') { ::NewRelic::Agent::SystemInfo.processor_arch }
69
+ report_on('OS version') { ::NewRelic::Agent::SystemInfo.os_version }
70
+ report_on('OS') { ::NewRelic::Agent::SystemInfo.ruby_os_identifier }
71
+ report_on('Database adapter') { ::NewRelic::Agent::DatabaseAdapter.value }
72
+ report_on('Framework') { Agent.config[:framework].to_s }
73
+ report_on('Dispatcher') { Agent.config[:dispatcher].to_s }
74
+ report_on('Environment') { NewRelic::Control.instance.env }
75
+ report_on('Rails version') { ::Rails::VERSION::STRING }
77
76
  report_on('Rails threadsafe') do
78
77
  ::Rails.configuration.action_controller.allow_concurrency
79
78
  end
@@ -88,7 +87,6 @@ module NewRelic
88
87
  # end reporting logic
89
88
  ####################################
90
89
 
91
-
92
90
  attr_reader :data
93
91
  # Generate the report based on the class level logic.
94
92
  def initialize
@@ -19,9 +19,9 @@ module NewRelic
19
19
  end
20
20
 
21
21
  def instance_method_visibility(klass, method_name)
22
- if klass.private_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym
22
+ if klass.private_instance_methods.map { |s| s.to_sym }.include? method_name.to_sym
23
23
  :private
24
- elsif klass.protected_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym
24
+ elsif klass.protected_instance_methods.map { |s| s.to_sym }.include? method_name.to_sym
25
25
  :protected
26
26
  else
27
27
  :public
@@ -31,9 +31,9 @@ module NewRelic
31
31
  def instance_methods_include?(klass, method_name)
32
32
  method_name_sym = method_name.to_sym
33
33
  (
34
- klass.instance_methods.map{ |s| s.to_sym }.include?(method_name_sym) ||
35
- klass.protected_instance_methods.map{ |s|s.to_sym }.include?(method_name_sym) ||
36
- klass.private_instance_methods.map{ |s|s.to_sym }.include?(method_name_sym)
34
+ klass.instance_methods.map { |s| s.to_sym }.include?(method_name_sym) ||
35
+ klass.protected_instance_methods.map { |s| s.to_sym }.include?(method_name_sym) ||
36
+ klass.private_instance_methods.map { |s| s.to_sym }.include?(method_name_sym)
37
37
  )
38
38
  end
39
39
 
@@ -22,7 +22,8 @@ module NewRelic
22
22
  end
23
23
 
24
24
  def object_space_usable?
25
- if defined?(::JRuby) && JRuby.respond_to?(:runtime)
25
+ if jruby?
26
+ require 'jruby'
26
27
  JRuby.runtime.is_object_space_enabled
27
28
  else
28
29
  defined?(::ObjectSpace)
@@ -34,7 +35,7 @@ module NewRelic
34
35
  end
35
36
 
36
37
  def constantize(const_name)
37
- const_name.to_s.sub(/\A::/,'').split('::').inject(Object) do |namespace, name|
38
+ const_name.to_s.sub(/\A::/, '').split('::').inject(Object) do |namespace, name|
38
39
  begin
39
40
  result = namespace.const_get(name)
40
41
 
@@ -13,7 +13,7 @@ module NewRelic
13
13
  changes.
14
14
  EOS
15
15
 
16
- def self.read(changelog=default_changelog)
16
+ def self.read(changelog = default_changelog)
17
17
  changes = extract_latest_changes(File.read(changelog))
18
18
  changes << FOOTER
19
19
 
@@ -24,7 +24,7 @@ EOS
24
24
  # precise version number included in the line in parens. For example:
25
25
  #
26
26
  # * This is a patch item (3.7.1.188)
27
- def self.read_patch(patch_level, changelog=default_changelog)
27
+ def self.read_patch(patch_level, changelog = default_changelog)
28
28
  latest = extract_latest_changes(File.read(changelog))
29
29
  changes = ["## v#{patch_level}", ""]
30
30