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
@@ -3,23 +3,22 @@
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
  # frozen_string_literal: true
5
5
 
6
-
7
6
  module NewRelic
8
7
  module Agent
9
8
  module Instrumentation
10
9
  module DelayedJob
11
-
12
10
  def initialize_with_tracing
13
11
  yield
14
12
  worker_name = case
15
13
  when self.respond_to?(:name) then self.name
16
14
  when self.class.respond_to?(:default_name) then self.class.default_name
17
- end
15
+ end
18
16
  NewRelic::DelayedJobInjection.worker_name = worker_name
19
-
17
+
18
+ # TODO: Refactor the last line of this condition so that it can be evaluated in both prepend and chain instrumentation
20
19
  if defined?(::Delayed::Job) && ::Delayed::Job.method_defined?(:invoke_job) &&
21
- !(::Delayed::Job.method_defined?(:invoke_job_without_new_relic) )
22
-
20
+ !(::Delayed::Job.method_defined?(:invoke_job_without_new_relic))
21
+
23
22
  ::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation [part 2/2]'
24
23
  install_newrelic_job_tracer
25
24
  NewRelic::Control.instance.init_plugin :dispatcher => :delayed_job
@@ -27,7 +26,6 @@ module NewRelic
27
26
  NewRelic::Agent.logger.warn("Did not find a Delayed::Job class responding to invoke_job, aborting DJ instrumentation")
28
27
  end
29
28
  end
30
-
31
29
  end
32
30
 
33
31
  module DelayedJobTracer
@@ -45,9 +43,7 @@ module NewRelic
45
43
  yield
46
44
  end
47
45
  end
48
-
49
46
  end
50
47
  end
51
48
  end
52
49
  end
53
-
@@ -14,11 +14,11 @@ module NewRelic
14
14
  module Naming
15
15
  module_function
16
16
 
17
- CLASS_METHOD_DELIMITER = '.'.freeze
18
- INSTANCE_METHOD_DELIMITER = '#'.freeze
17
+ CLASS_METHOD_DELIMITER = '.'.freeze
18
+ INSTANCE_METHOD_DELIMITER = '#'.freeze
19
19
  LEGACY_DJ_FORMAT_DELIMITER = ';'.freeze
20
- LEGACY_DJ_FORMAT_PREFIX = 'LOAD'.freeze
21
- LEGACY_DJ_DEFAULT_CLASS = '(unknown class)'.freeze
20
+ LEGACY_DJ_FORMAT_PREFIX = 'LOAD'.freeze
21
+ LEGACY_DJ_DEFAULT_CLASS = '(unknown class)'.freeze
22
22
 
23
23
  def name_from_payload(payload_object)
24
24
  if payload_object.is_a? ::Delayed::PerformableMethod
@@ -11,7 +11,7 @@ module ::Excon
11
11
  @stack = stack
12
12
  end
13
13
 
14
- def request_call(datum) #THREAD_LOCAL_ACCESS
14
+ def request_call(datum) # THREAD_LOCAL_ACCESS
15
15
  begin
16
16
  # Only instrument this request if we haven't already done so, because
17
17
  # we can get request_call multiple times for requests marked as
@@ -45,7 +45,7 @@ module ::Excon
45
45
  @stack.error_call(datum)
46
46
  end
47
47
 
48
- def finish_trace(datum) #THREAD_LOCAL_ACCESS
48
+ def finish_trace(datum) # THREAD_LOCAL_ACCESS
49
49
  segment = datum[:connection] && datum[:connection].instance_variable_get(TRACE_DATA_IVAR)
50
50
  if segment
51
51
  begin
@@ -51,4 +51,3 @@ DependencyDetection.defer do
51
51
  end
52
52
  end
53
53
  end
54
-
@@ -14,7 +14,7 @@ module NewRelic::Agent::Instrumentation
14
14
  Grape::Instrumentation.capture_transaction env, self
15
15
  end
16
16
  end
17
-
17
+
18
18
  alias_method :call_without_new_relic, :call
19
19
  alias_method :call, :call_with_new_relic
20
20
  end
@@ -22,4 +22,3 @@ module NewRelic::Agent::Instrumentation
22
22
  end
23
23
  end
24
24
  end
25
-
@@ -7,7 +7,6 @@ require 'new_relic/agent/parameter_filtering'
7
7
  module NewRelic::Agent::Instrumentation
8
8
  module Grape
9
9
  module Instrumentation
10
-
11
10
  extend self
12
11
 
13
12
  # Since 1.2.0, the class `Grape::API` no longer refers to an API instance, rather, what used to be `Grape::API` is `Grape::API::Instance`
@@ -37,12 +36,12 @@ module NewRelic::Agent::Instrumentation
37
36
  end
38
37
  end
39
38
 
40
- API_ENDPOINT = 'api.endpoint'.freeze
41
- API_VERSION = 'api.version'.freeze
42
- FORMAT_REGEX = /\(\/?\.[\:\w]*\)/.freeze # either :format (< 0.12.0) or .ext (>= 0.12.0)
43
- VERSION_REGEX = /:version(\/|$)/.freeze
44
- MIN_VERSION = Gem::Version.new("0.2.0")
45
- PIPE_STRING = '|'.freeze
39
+ API_ENDPOINT = 'api.endpoint'.freeze
40
+ API_VERSION = 'api.version'.freeze
41
+ FORMAT_REGEX = /\(\/?\.[\:\w]*\)/.freeze # either :format (< 0.12.0) or .ext (>= 0.12.0)
42
+ VERSION_REGEX = /:version(\/|$)/.freeze
43
+ MIN_VERSION = Gem::Version.new("0.2.0")
44
+ PIPE_STRING = '|'.freeze
46
45
 
47
46
  def handle_transaction(endpoint, class_name, version)
48
47
  return unless endpoint && route = endpoint.route
@@ -11,7 +11,7 @@ DependencyDetection.defer do
11
11
  # not shipping yet, overloading the name interferes with the plugin.
12
12
  named :grape_instrumentation
13
13
  configure_with :grape
14
-
14
+
15
15
  depends_on do
16
16
  defined?(::Grape::VERSION) &&
17
17
  Gem::Version.new(::Grape::VERSION) >= ::NewRelic::Agent::Instrumentation::Grape::Instrumentation::MIN_VERSION
@@ -37,9 +37,8 @@ DependencyDetection.defer do
37
37
  if use_prepend?
38
38
  instrumented_class = ::NewRelic::Agent::Instrumentation::Grape::Instrumentation.instrumented_class
39
39
  prepend_instrument instrumented_class, ::NewRelic::Agent::Instrumentation::Grape::Prepend
40
- else
40
+ else
41
41
  chain_instrument ::NewRelic::Agent::Instrumentation::Grape::Chain
42
42
  end
43
43
  end
44
-
45
44
  end
@@ -4,7 +4,7 @@
4
4
 
5
5
  module NewRelic::Agent::Instrumentation
6
6
  module HTTPClient
7
- module Chain
7
+ module Chain
8
8
  def self.instrument!
9
9
  ::HTTPClient.class_eval do
10
10
  include NewRelic::Agent::Instrumentation::HTTPClient::Instrumentation
@@ -14,7 +14,7 @@ module NewRelic::Agent::Instrumentation
14
14
  do_get_block_without_newrelic(req, proxy, conn, &block)
15
15
  end
16
16
  end
17
-
17
+
18
18
  alias :do_get_block_without_newrelic :do_get_block
19
19
  alias :do_get_block :do_get_block_with_newrelic
20
20
  end
@@ -22,4 +22,3 @@ module NewRelic::Agent::Instrumentation
22
22
  end
23
23
  end
24
24
  end
25
-
@@ -35,4 +35,3 @@ module NewRelic::Agent::Instrumentation
35
35
  end
36
36
  end
37
37
  end
38
-
@@ -2,7 +2,6 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
-
6
5
  module NewRelic::Agent::Instrumentation
7
6
  module HTTPClient
8
7
  module Prepend
@@ -14,4 +13,3 @@ module NewRelic::Agent::Instrumentation
14
13
  end
15
14
  end
16
15
  end
17
-
@@ -12,11 +12,11 @@ module NewRelic::Agent::Instrumentation
12
12
  def perform_with_newrelic_trace(request, options)
13
13
  with_tracing(request) { perform_without_newrelic_trace(request, options) }
14
14
  end
15
-
15
+
16
16
  alias perform_without_newrelic_trace perform
17
17
  alias perform perform_with_newrelic_trace
18
18
  end
19
19
  end
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -6,25 +6,25 @@ module NewRelic::Agent::Instrumentation
6
6
  module HTTPrb
7
7
  def with_tracing(request)
8
8
  wrapped_request = ::NewRelic::Agent::HTTPClients::HTTPRequest.new(request)
9
-
9
+
10
10
  begin
11
11
  segment = NewRelic::Agent::Tracer.start_external_request_segment(
12
12
  library: wrapped_request.type,
13
13
  uri: wrapped_request.uri,
14
14
  procedure: wrapped_request.method
15
15
  )
16
-
16
+
17
17
  segment.add_request_headers wrapped_request
18
-
18
+
19
19
  response = NewRelic::Agent::Tracer.capture_segment_error(segment) { yield }
20
-
20
+
21
21
  wrapped_response = ::NewRelic::Agent::HTTPClients::HTTPResponse.new response
22
22
  segment.process_response_headers wrapped_response
23
-
23
+
24
24
  response
25
25
  ensure
26
26
  segment.finish if segment
27
27
  end
28
28
  end
29
29
  end
30
- end
30
+ end
@@ -8,7 +8,7 @@ module NewRelic::Agent::Instrumentation
8
8
  include NewRelic::Agent::Instrumentation::HTTPrb
9
9
 
10
10
  def perform(request, options)
11
- with_tracing(request) { super }
11
+ with_tracing(request) { super }
12
12
  end
13
13
  end
14
14
  end
@@ -15,9 +15,9 @@ module NewRelic
15
15
 
16
16
  should_filter = case ignore_actions
17
17
  when Hash
18
- only_actions = Array(ignore_actions[:only])
18
+ only_actions = Array(ignore_actions[:only])
19
19
  except_actions = Array(ignore_actions[:except])
20
- action_name = action_name.to_sym
20
+ action_name = action_name.to_sym
21
21
 
22
22
  only_actions.include?(action_name) || (!except_actions.empty? && !except_actions.include?(action_name))
23
23
  else
@@ -38,4 +38,3 @@ module NewRelic
38
38
  end
39
39
  end
40
40
  end
41
-
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module Logger
7
+ def self.instrument!
8
+ ::Logger.class_eval do
9
+ include NewRelic::Agent::Instrumentation::Logger
10
+
11
+ alias_method :format_message_without_new_relic, :format_message
12
+
13
+ def format_message(severity, datetime, progname, msg)
14
+ format_message_with_tracing(severity, datetime, progname, msg) do
15
+ format_message_without_new_relic(severity, datetime, progname, msg)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+
5
+ module NewRelic
6
+ module Agent
7
+ module Instrumentation
8
+ module Logger
9
+ def skip_instrumenting?
10
+ defined?(@skip_instrumenting) && @skip_instrumenting
11
+ end
12
+
13
+ def mark_skip_instrumenting
14
+ @skip_instrumenting = true
15
+ end
16
+
17
+ def clear_skip_instrumenting
18
+ @skip_instrumenting = false
19
+ end
20
+
21
+ LINES = "Logging/lines".freeze
22
+ SIZE = "Logging/size".freeze
23
+
24
+ def line_metric_name_by_severity(severity)
25
+ @line_metrics ||= {}
26
+ @line_metrics[severity] ||= "Logging/lines/#{severity}".freeze
27
+ end
28
+
29
+ def size_metric_name_by_severity(severity)
30
+ @size_metrics ||= {}
31
+ @size_metrics[severity] ||= "Logging/size/#{severity}".freeze
32
+ end
33
+
34
+ def format_message_with_tracing(severity, datetime, progname, msg)
35
+ formatted_message = yield
36
+ return formatted_message if skip_instrumenting?
37
+
38
+ begin
39
+ # It's critical we don't instrument logging from metric recording
40
+ # methods within NewRelic::Agent, or we'll stack overflow!!
41
+ mark_skip_instrumenting
42
+
43
+ NewRelic::Agent.increment_metric(LINES)
44
+ NewRelic::Agent.increment_metric(line_metric_name_by_severity(severity))
45
+
46
+ size = formatted_message.nil? ? 0 : formatted_message.bytesize
47
+ NewRelic::Agent.record_metric(SIZE, size)
48
+ NewRelic::Agent.record_metric(size_metric_name_by_severity(severity), size)
49
+
50
+ return formatted_message
51
+ ensure
52
+ clear_skip_instrumenting
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module Logger::Prepend
7
+ include NewRelic::Agent::Instrumentation::Logger
8
+
9
+ def format_message(severity, datetime, progname, msg)
10
+ format_message_with_tracing(severity, datetime, progname, msg) { super }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+
5
+ require_relative 'logger/instrumentation'
6
+ require_relative 'logger/chain'
7
+ require_relative 'logger/prepend'
8
+
9
+ DependencyDetection.defer do
10
+ named :logger
11
+
12
+ depends_on { defined?(::Logger) }
13
+
14
+ executes do
15
+ ::NewRelic::Agent.logger.info "Installing Logger instrumentation"
16
+ end
17
+
18
+ executes do
19
+ if use_prepend?
20
+ prepend_instrument ::Logger, NewRelic::Agent::Instrumentation::Logger::Prepend
21
+ else
22
+ chain_instrument NewRelic::Agent::Instrumentation::Logger
23
+ end
24
+ end
25
+ end
@@ -9,6 +9,7 @@ module NewRelic
9
9
  module Memcache
10
10
  module Dalli
11
11
  extend Helper
12
+
12
13
  module_function
13
14
 
14
15
  def instrument!
@@ -51,7 +52,11 @@ module NewRelic
51
52
  end
52
53
 
53
54
  def instrument_send_multiget
54
- ::Dalli::Server.class_eval do
55
+ if supports_binary_protocol?
56
+ ::Dalli::Protocol::Binary
57
+ else
58
+ ::Dalli::Server
59
+ end.class_eval do
55
60
  include NewRelic::Agent::Instrumentation::Memcache::Tracer
56
61
  alias_method :send_multiget_without_newrelic_trace, :send_multiget
57
62
 
@@ -65,6 +70,7 @@ module NewRelic
65
70
  module DalliCAS
66
71
  extend Dalli
67
72
  extend Helper
73
+
68
74
  module_function
69
75
 
70
76
  def should_instrument?
@@ -80,4 +86,3 @@ module NewRelic
80
86
  end
81
87
  end
82
88
  end
83
-
@@ -7,11 +7,16 @@ module NewRelic::Agent::Instrumentation
7
7
  module Memcache
8
8
  module Helper
9
9
  DATASTORE_INSTANCES_SUPPORTED_VERSION = Gem::Version.new '2.6.4'
10
+ BINARY_PROTOCOL_SUPPORTED_VERSION = Gem::Version.new '3.0.2'
10
11
 
11
12
  def supports_datastore_instances?
12
13
  DATASTORE_INSTANCES_SUPPORTED_VERSION <= Gem::Version.new(::Dalli::VERSION)
13
14
  end
14
15
 
16
+ def supports_binary_protocol?
17
+ BINARY_PROTOCOL_SUPPORTED_VERSION <= Gem::Version.new(::Dalli::VERSION)
18
+ end
19
+
15
20
  def client_methods
16
21
  [:get, :get_multi, :set, :add, :incr, :decr, :delete, :replace, :append,
17
22
  :prepend, :cas, :single_get, :multi_get, :single_cas, :multi_cas]
@@ -53,4 +58,3 @@ module NewRelic::Agent::Instrumentation
53
58
  end
54
59
  end
55
60
  end
56
-
@@ -7,6 +7,7 @@ module NewRelic::Agent::Instrumentation
7
7
  module Memcache
8
8
  module Prepend
9
9
  extend Helper
10
+
10
11
  module_function
11
12
 
12
13
  def client_prepender client_class
@@ -31,7 +32,13 @@ module NewRelic::Agent::Instrumentation
31
32
  if supports_datastore_instances?
32
33
  yield ::Dalli::Client, dalli_client_prepender(dalli_methods)
33
34
  yield ::Dalli::Client, dalli_get_multi_prepender(:get_multi)
34
- yield ::Dalli::Server, dalli_server_prepender
35
+
36
+ if supports_binary_protocol?
37
+ yield ::Dalli::Protocol::Binary, dalli_server_prepender
38
+ else
39
+ yield ::Dalli::Server, dalli_server_prepender
40
+ end
41
+
35
42
  yield ::Dalli::Ring, dalli_ring_prepender
36
43
  else
37
44
  yield ::Dalli::Client, dalli_client_prepender(client_methods)
@@ -85,4 +92,4 @@ module NewRelic::Agent::Instrumentation
85
92
  end
86
93
  end
87
94
  end
88
- end
95
+ end
@@ -15,7 +15,7 @@ module NewRelic
15
15
  class MiddlewareProxy
16
16
  include MiddlewareTracing
17
17
 
18
- ANONYMOUS_CLASS = "AnonymousClass".freeze
18
+ ANONYMOUS_CLASS = "AnonymousClass".freeze
19
19
  OBJECT_CLASS_NAME = "Object".freeze
20
20
 
21
21
  # This class is used to wrap classes that are passed to
@@ -50,7 +50,7 @@ module NewRelic
50
50
  )
51
51
  end
52
52
 
53
- def self.wrap(target, is_app=false)
53
+ def self.wrap(target, is_app = false)
54
54
  if needs_wrapping?(target)
55
55
  self.new(target, is_app)
56
56
  else
@@ -60,13 +60,13 @@ module NewRelic
60
60
 
61
61
  attr_reader :target, :category, :transaction_options
62
62
 
63
- def initialize(target, is_app=false)
64
- @target = target
65
- @is_app = is_app
66
- @category = determine_category
63
+ def initialize(target, is_app = false)
64
+ @target = target
65
+ @is_app = is_app
66
+ @category = determine_category
67
67
  @target_class_name = determine_class_name
68
- @transaction_name = "#{determine_prefix}#{@target_class_name}/call"
69
- @transaction_options = {
68
+ @transaction_name = "#{determine_prefix}#{@target_class_name}/call"
69
+ @transaction_options = {
70
70
  :transaction_name => @transaction_name
71
71
  }
72
72
  end
@@ -93,7 +93,7 @@ module NewRelic
93
93
 
94
94
  name = clazz.name
95
95
  name = clazz.superclass.name if name.nil? || name == ""
96
- name = ANONYMOUS_CLASS if name.nil? || name == OBJECT_CLASS_NAME
96
+ name = ANONYMOUS_CLASS if name.nil? || name == OBJECT_CLASS_NAME
97
97
  name
98
98
  end
99
99
 
@@ -104,7 +104,6 @@ module NewRelic
104
104
  @target.class
105
105
  end
106
106
  end
107
-
108
107
  end
109
108
  end
110
109
  end
@@ -27,10 +27,9 @@ module NewRelic
27
27
  module Agent
28
28
  module Instrumentation
29
29
  module MiddlewareTracing
30
-
31
30
  TXN_STARTED_KEY = 'newrelic.transaction_started'
32
- CONTENT_TYPE = 'Content-Type'
33
- CONTENT_LENGTH = 'Content-Length'
31
+ CONTENT_TYPE = 'Content-Type'
32
+ CONTENT_LENGTH = 'Content-Length'
34
33
 
35
34
  def _nr_has_middleware_tracing
36
35
  true
@@ -71,7 +70,7 @@ module NewRelic
71
70
  if result.is_a?(Array) && state.current_transaction
72
71
  _, headers, _ = result
73
72
  length = headers[CONTENT_LENGTH]
74
- length = length.reduce(0){|sum, h| sum + h.to_i} if length.is_a?(Array)
73
+ length = length.reduce(0) { |sum, h| sum + h.to_i } if length.is_a?(Array)
75
74
  state.current_transaction.response_content_length = length
76
75
  end
77
76
  end
@@ -98,7 +97,7 @@ module NewRelic
98
97
 
99
98
  events.notify(:before_call, env) if first_middleware
100
99
 
101
- result = (target == self) ? traced_call(env) : target.call(env)
100
+ result = target == self ? traced_call(env) : target.call(env)
102
101
 
103
102
  if first_middleware
104
103
  capture_response_attributes(state, result)
@@ -19,11 +19,11 @@ module NewRelic
19
19
  end
20
20
  end
21
21
 
22
- ERROR_KEYS = %w{ writeErrors writeConcernError writeConcernErrors }.freeze
22
+ ERROR_KEYS = %w[ writeErrors writeConcernError writeConcernErrors ].freeze
23
23
 
24
24
  def error_key_present?(event)
25
25
  if reply = event.reply
26
- ERROR_KEYS.detect{ |key| reply[key] }
26
+ ERROR_KEYS.detect { |key| reply[key] }
27
27
  end
28
28
  rescue
29
29
  false
@@ -35,7 +35,7 @@ module NewRelic
35
35
  segment = segments.delete(event.operation_id)
36
36
  return unless segment
37
37
 
38
- # operations that succeed but have errors return CommandSucceeded
38
+ # operations that succeed but have errors return CommandSucceeded
39
39
  # with an error_key that is populated with error specfics
40
40
  if error_key = error_key_present?(event)
41
41
  # taking the last error as there can potentially be many
@@ -76,7 +76,7 @@ module NewRelic
76
76
  def operation(command_name)
77
77
  # from 2.0 to 2.5, :findandmodify was the command_name
78
78
  if command_name == :findandmodify
79
- :findAndModify
79
+ :findAndModify
80
80
  else
81
81
  command_name
82
82
  end
@@ -4,7 +4,6 @@
4
4
 
5
5
  require_relative 'instrumentation'
6
6
 
7
-
8
7
  module NewRelic::Agent::Instrumentation
9
8
  module NetHTTP
10
9
  module Chain
@@ -14,12 +13,12 @@ module NewRelic::Agent::Instrumentation
14
13
 
15
14
  def request_with_newrelic_trace(request, *args, &block)
16
15
  request_with_tracing(request) { request_without_newrelic_trace(request, *args, &block) }
17
- end
18
-
16
+ end
17
+
19
18
  alias request_without_newrelic_trace request
20
19
  alias request request_with_newrelic_trace
21
20
  end
22
21
  end
23
22
  end
24
23
  end
25
- end
24
+ end
@@ -2,8 +2,8 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
- module NewRelic
6
- module Agent
5
+ module NewRelic
6
+ module Agent
7
7
  module Instrumentation
8
8
  module NetHTTP
9
9
  def request_with_tracing(request)
@@ -14,11 +14,11 @@ module NewRelic
14
14
  uri: wrapped_request.uri,
15
15
  procedure: wrapped_request.method
16
16
  )
17
-
17
+
18
18
  begin
19
19
  response = nil
20
20
  segment.add_request_headers wrapped_request
21
-
21
+
22
22
  # RUBY-1244 Disable further tracing in request to avoid double
23
23
  # counting if connection wasn't started (which calls request again).
24
24
  NewRelic::Agent.disable_all_tracing do
@@ -26,7 +26,7 @@ module NewRelic
26
26
  yield
27
27
  end
28
28
  end
29
-
29
+
30
30
  wrapped_response = NewRelic::Agent::HTTPClients::NetHTTPResponse.new response
31
31
  segment.process_response_headers wrapped_response
32
32
  response