newrelic_rpm 7.2.0 → 8.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +1936 -0
  4. data/CHANGELOG.md +182 -9
  5. data/CONTRIBUTING.md +14 -2
  6. data/Guardfile +8 -8
  7. data/README.md +5 -1
  8. data/Rakefile +5 -7
  9. data/bin/mongrel_rpm +8 -9
  10. data/bin/newrelic +1 -1
  11. data/bin/nrdebug +14 -14
  12. data/init.rb +0 -2
  13. data/lefthook.yml +9 -0
  14. data/lib/new_relic/agent/adaptive_sampler.rb +9 -5
  15. data/lib/new_relic/agent/agent.rb +44 -46
  16. data/lib/new_relic/agent/agent_logger.rb +8 -9
  17. data/lib/new_relic/agent/attribute_filter.rb +31 -31
  18. data/lib/new_relic/agent/attributes.rb +2 -2
  19. data/lib/new_relic/agent/autostart.rb +6 -7
  20. data/lib/new_relic/agent/commands/agent_command.rb +2 -2
  21. data/lib/new_relic/agent/commands/agent_command_router.rb +6 -5
  22. data/lib/new_relic/agent/commands/thread_profiler_session.rb +7 -6
  23. data/lib/new_relic/agent/configuration/default_source.rb +352 -336
  24. data/lib/new_relic/agent/configuration/dotted_hash.rb +3 -3
  25. data/lib/new_relic/agent/configuration/environment_source.rb +3 -4
  26. data/lib/new_relic/agent/configuration/event_harvest_config.rb +30 -16
  27. data/lib/new_relic/agent/configuration/high_security_source.rb +7 -7
  28. data/lib/new_relic/agent/configuration/manager.rb +57 -58
  29. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
  30. data/lib/new_relic/agent/configuration/security_policy_source.rb +73 -73
  31. data/lib/new_relic/agent/configuration/server_source.rb +12 -11
  32. data/lib/new_relic/agent/configuration/yaml_source.rb +26 -5
  33. data/lib/new_relic/agent/connect/request_builder.rb +13 -16
  34. data/lib/new_relic/agent/connect/response_handler.rb +0 -3
  35. data/lib/new_relic/agent/custom_event_aggregator.rb +9 -9
  36. data/lib/new_relic/agent/database/explain_plan_helpers.rb +3 -4
  37. data/lib/new_relic/agent/database/obfuscation_helpers.rb +12 -12
  38. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +2 -2
  39. data/lib/new_relic/agent/database.rb +25 -26
  40. data/lib/new_relic/agent/datastores/metric_helper.rb +10 -10
  41. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -3
  42. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +3 -5
  43. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +1 -2
  44. data/lib/new_relic/agent/datastores/mongo.rb +5 -10
  45. data/lib/new_relic/agent/datastores/redis.rb +2 -4
  46. data/lib/new_relic/agent/datastores.rb +7 -9
  47. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +9 -9
  48. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +21 -16
  49. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +10 -12
  50. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +42 -43
  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 +25 -25
  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 +14 -14
  64. data/lib/new_relic/agent/external.rb +1 -34
  65. data/lib/new_relic/agent/guid_generator.rb +1 -3
  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 +7 -9
  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 +10 -11
  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 +3 -3
  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/acts_as_solr.rb +8 -9
  88. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +1 -1
  89. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +8 -9
  90. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +42 -42
  91. data/lib/new_relic/agent/instrumentation/curb/chain.rb +19 -20
  92. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +34 -38
  93. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +9 -10
  94. data/lib/new_relic/agent/instrumentation/data_mapper.rb +10 -10
  95. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +5 -7
  96. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +5 -9
  97. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +4 -4
  98. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -2
  99. data/lib/new_relic/agent/instrumentation/excon.rb +3 -23
  100. data/lib/new_relic/agent/instrumentation/grape/chain.rb +1 -2
  101. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +6 -7
  102. data/lib/new_relic/agent/instrumentation/grape.rb +2 -3
  103. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +2 -3
  104. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +0 -1
  105. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +0 -2
  106. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +2 -2
  107. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +6 -6
  108. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -1
  109. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -3
  110. data/lib/new_relic/agent/instrumentation/logger/chain.rb +21 -0
  111. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +58 -0
  112. data/lib/new_relic/agent/instrumentation/logger/prepend.rb +13 -0
  113. data/lib/new_relic/agent/instrumentation/logger.rb +25 -0
  114. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +7 -2
  115. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +5 -1
  116. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +9 -2
  117. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +9 -10
  118. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +4 -5
  119. data/lib/new_relic/agent/instrumentation/mongo.rb +3 -141
  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 +8 -8
  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 +11 -47
  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 +7 -1
  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 +30 -30
  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 +46 -61
  169. data/lib/new_relic/agent/method_tracer.rb +139 -143
  170. data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
  171. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +21 -13
  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 +34 -41
  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 +3 -5
  185. data/lib/new_relic/agent/payload_metric_mapping.rb +8 -9
  186. data/lib/new_relic/agent/pipe_channel_manager.rb +15 -12
  187. data/lib/new_relic/agent/pipe_service.rb +2 -2
  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/cpu_sampler.rb +1 -1
  195. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +10 -7
  196. data/lib/new_relic/agent/samplers/memory_sampler.rb +4 -3
  197. data/lib/new_relic/agent/samplers/vm_sampler.rb +18 -18
  198. data/lib/new_relic/agent/span_event_aggregator.rb +10 -10
  199. data/lib/new_relic/agent/span_event_primitive.rb +39 -39
  200. data/lib/new_relic/agent/sql_sampler.rb +9 -9
  201. data/lib/new_relic/agent/stats.rb +16 -16
  202. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +7 -9
  203. data/lib/new_relic/agent/stats_engine/stats_hash.rb +8 -9
  204. data/lib/new_relic/agent/stats_engine.rb +7 -7
  205. data/lib/new_relic/agent/synthetics_event_aggregator.rb +0 -1
  206. data/lib/new_relic/agent/system_info.rb +22 -20
  207. data/lib/new_relic/agent/threading/agent_thread.rb +4 -5
  208. data/lib/new_relic/agent/threading/backtrace_node.rb +6 -9
  209. data/lib/new_relic/agent/threading/backtrace_service.rb +12 -13
  210. data/lib/new_relic/agent/threading/thread_profile.rb +16 -19
  211. data/lib/new_relic/agent/tracer.rb +43 -71
  212. data/lib/new_relic/agent/transaction/abstract_segment.rb +9 -9
  213. data/lib/new_relic/agent/transaction/datastore_segment.rb +7 -6
  214. data/lib/new_relic/agent/transaction/distributed_tracer.rb +8 -9
  215. data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -22
  216. data/lib/new_relic/agent/transaction/external_request_segment.rb +6 -5
  217. data/lib/new_relic/agent/transaction/message_broker_segment.rb +24 -30
  218. data/lib/new_relic/agent/transaction/request_attributes.rb +7 -7
  219. data/lib/new_relic/agent/transaction/segment.rb +6 -3
  220. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +0 -2
  221. data/lib/new_relic/agent/transaction/trace.rb +8 -8
  222. data/lib/new_relic/agent/transaction/trace_context.rb +13 -15
  223. data/lib/new_relic/agent/transaction/trace_node.rb +16 -16
  224. data/lib/new_relic/agent/transaction/tracing.rb +1 -3
  225. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -2
  226. data/lib/new_relic/agent/transaction.rb +85 -108
  227. data/lib/new_relic/agent/transaction_error_primitive.rb +16 -16
  228. data/lib/new_relic/agent/transaction_event_aggregator.rb +5 -6
  229. data/lib/new_relic/agent/transaction_event_primitive.rb +29 -29
  230. data/lib/new_relic/agent/transaction_metrics.rb +3 -3
  231. data/lib/new_relic/agent/transaction_sampler.rb +0 -1
  232. data/lib/new_relic/agent/transaction_time_aggregator.rb +11 -11
  233. data/lib/new_relic/agent/utilization/azure.rb +1 -1
  234. data/lib/new_relic/agent/utilization_data.rb +3 -4
  235. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  236. data/lib/new_relic/agent/vm/snapshot.rb +4 -4
  237. data/lib/new_relic/agent/worker_loop.rb +8 -10
  238. data/lib/new_relic/agent.rb +27 -27
  239. data/lib/new_relic/cli/command.rb +15 -17
  240. data/lib/new_relic/cli/commands/deployments.rb +21 -23
  241. data/lib/new_relic/cli/commands/install.rb +6 -10
  242. data/lib/new_relic/coerce.rb +5 -8
  243. data/lib/new_relic/collection_helper.rb +48 -47
  244. data/lib/new_relic/constants.rb +0 -4
  245. data/lib/new_relic/control/class_methods.rb +2 -2
  246. data/lib/new_relic/control/frameworks/external.rb +1 -1
  247. data/lib/new_relic/control/frameworks/rails.rb +5 -6
  248. data/lib/new_relic/control/frameworks/rails3.rb +2 -3
  249. data/lib/new_relic/control/frameworks/ruby.rb +2 -2
  250. data/lib/new_relic/control/instance_methods.rb +4 -5
  251. data/lib/new_relic/control/instrumentation.rb +4 -5
  252. data/lib/new_relic/control/server_methods.rb +2 -3
  253. data/lib/new_relic/control.rb +0 -1
  254. data/lib/new_relic/dependency_detection.rb +6 -8
  255. data/lib/new_relic/environment_report.rb +16 -18
  256. data/lib/new_relic/helper.rb +5 -5
  257. data/lib/new_relic/language_support.rb +1 -1
  258. data/lib/new_relic/latest_changes.rb +2 -2
  259. data/lib/new_relic/local_environment.rb +7 -7
  260. data/lib/new_relic/metric_data.rb +6 -7
  261. data/lib/new_relic/metric_spec.rb +3 -3
  262. data/lib/new_relic/noticed_error.rb +16 -17
  263. data/lib/new_relic/rack/agent_middleware.rb +2 -2
  264. data/lib/new_relic/rack/browser_monitoring.rb +9 -9
  265. data/lib/new_relic/recipes/capistrano3.rb +11 -13
  266. data/lib/new_relic/recipes/capistrano_legacy.rb +11 -14
  267. data/lib/new_relic/supportability_helper.rb +1 -2
  268. data/lib/new_relic/version.rb +4 -5
  269. data/lib/newrelic_rpm.rb +10 -34
  270. data/lib/sequel/extensions/newrelic_instrumentation.rb +4 -7
  271. data/lib/sequel/plugins/newrelic_instrumentation.rb +3 -9
  272. data/lib/tasks/all.rb +2 -2
  273. data/lib/tasks/config.rake +21 -21
  274. data/lib/tasks/multiverse.rb +4 -6
  275. data/lib/tasks/tests.rake +3 -7
  276. data/newrelic.yml +580 -3
  277. data/newrelic_rpm.gemspec +13 -12
  278. data/recipes/newrelic.rb +1 -1
  279. data/test/agent_helper.rb +80 -55
  280. metadata +42 -13
  281. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +0 -53
  282. data/lib/new_relic/agent/instrumentation/excon/connection.rb +0 -49
  283. data/lib/new_relic/agent/instrumentation/merb/controller.rb +0 -44
  284. data/lib/new_relic/agent/instrumentation/merb/errors.rb +0 -33
  285. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +0 -125
  286. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +0 -46
  287. data/lib/new_relic/agent/supported_versions.rb +0 -275
  288. data/lib/new_relic/control/frameworks/merb.rb +0 -29
@@ -0,0 +1,40 @@
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 Tilt
9
+ def metric_name(klass, file)
10
+ "View/#{klass}/#{file}/Rendering"
11
+ end
12
+
13
+ # Sinatra uses #caller_locations for the file name in Tilt (unlike Rails/Rack)
14
+ # So here we are only grabbing the file name and name of directory it is in
15
+ def create_filename_for_metric(file)
16
+ return file unless defined?(::Sinatra) && defined?(::Sinatra::Base)
17
+ file.split('/')[-2..-1].join('/')
18
+ rescue NoMethodError
19
+ file
20
+ end
21
+
22
+ def render_with_tracing(*args, &block)
23
+ begin
24
+ finishable = Tracer.start_segment(
25
+ name: metric_name(self.class, create_filename_for_metric(self.file))
26
+ )
27
+ begin
28
+ yield
29
+ rescue => error
30
+ NewRelic::Agent.notice_error(error)
31
+ raise
32
+ end
33
+ ensure
34
+ finishable.finish if finishable
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ 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 Tilt::Prepend
7
+ include NewRelic::Agent::Instrumentation::Tilt
8
+
9
+ def render(*args, &block)
10
+ render_with_tracing { 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 'tilt/instrumentation'
6
+ require_relative 'tilt/chain'
7
+ require_relative 'tilt/prepend'
8
+
9
+ DependencyDetection.defer do
10
+ named :tilt
11
+
12
+ depends_on { defined?(::Tilt) }
13
+
14
+ executes do
15
+ ::NewRelic::Agent.logger.info('Installing Tilt instrumentation')
16
+ end
17
+
18
+ executes do
19
+ if use_prepend?
20
+ prepend_instrument ::Tilt::Template, NewRelic::Agent::Instrumentation::Tilt::Prepend
21
+ else
22
+ chain_instrument NewRelic::Agent::Instrumentation::Tilt::Chain
23
+ end
24
+ end
25
+ end
@@ -4,19 +4,19 @@
4
4
 
5
5
  module NewRelic::Agent::Instrumentation
6
6
  module Typhoeus
7
- module Chain
7
+ module Chain
8
8
  def self.instrument!
9
- ::Typhoeus::Hydra.class_eval do
9
+ ::Typhoeus::Hydra.class_eval do
10
10
  include NewRelic::Agent::Instrumentation::Typhoeus
11
11
 
12
12
  def run_with_newrelic(*args)
13
13
  with_tracing { run_without_newrelic(*args) }
14
14
  end
15
-
15
+
16
16
  alias run_without_newrelic run
17
17
  alias run run_with_newrelic
18
18
  end
19
19
  end
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -6,8 +6,7 @@ module NewRelic
6
6
  module Agent
7
7
  module Instrumentation
8
8
  module Typhoeus
9
-
10
- HYDRA_SEGMENT_NAME = "External/Multiple/Typhoeus::Hydra/run"
9
+ HYDRA_SEGMENT_NAME = "External/Multiple/Typhoeus::Hydra/run"
11
10
  NOTICIBLE_ERROR_CLASS = "Typhoeus::Errors::TyphoeusError"
12
11
 
13
12
  EARLIEST_VERSION = Gem::Version.new("0.5.3")
@@ -27,7 +26,7 @@ module NewRelic
27
26
  response.return_message
28
27
  else
29
28
  # 0.5.4 seems to have lost xxxx_message methods altogether.
30
- "timeout"
29
+ "timeout"
31
30
  end
32
31
  end
33
32
 
@@ -68,11 +67,10 @@ module NewRelic
68
67
  if request.response.code == 0
69
68
  segment.notice_error NoticibleError.new NOTICIBLE_ERROR_CLASS, response_message(request.response)
70
69
  end
71
-
70
+
72
71
  segment.finish if segment
73
72
  end
74
73
  request.on_complete.unshift(callback)
75
-
76
74
  rescue => e
77
75
  NewRelic::Agent.logger.error("Exception during trace setup for Typhoeus request", e)
78
76
  end
@@ -11,4 +11,4 @@ module NewRelic::Agent::Instrumentation
11
11
  end
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -10,7 +10,7 @@
10
10
  module NewRelic
11
11
  module Agent
12
12
  class InternalAgentError < StandardError
13
- def initialize(msg=nil)
13
+ def initialize(msg = nil)
14
14
  super("Ruby agent internal error. Please contact support referencing this error.\n #{msg}")
15
15
  end
16
16
  end
@@ -19,8 +19,8 @@ module NewRelic
19
19
 
20
20
  def log_configuration
21
21
  NewRelic::Agent.logger.debug("JS agent loader requested: #{NewRelic::Agent.config[:'browser_monitoring.loader']}",
22
- "JS agent loader debug: #{NewRelic::Agent.config[:'browser_monitoring.debug']}",
23
- "JS agent loader version: #{NewRelic::Agent.config[:'browser_monitoring.loader_version']}")
22
+ "JS agent loader debug: #{NewRelic::Agent.config[:'browser_monitoring.debug']}",
23
+ "JS agent loader version: #{NewRelic::Agent.config[:'browser_monitoring.loader_version']}")
24
24
 
25
25
  if !NewRelic::Agent.config[:'rum.enabled']
26
26
  NewRelic::Agent.logger.debug("Real User Monitoring is disabled for this agent. Edit your configuration to change this.")
@@ -38,19 +38,19 @@ module NewRelic
38
38
  def js_enabled_and_ready?
39
39
  if !enabled?
40
40
  ::NewRelic::Agent.logger.log_once(:debug, :js_agent_disabled,
41
- "JS agent instrumentation is disabled.")
41
+ "JS agent instrumentation is disabled.")
42
42
  false
43
43
  elsif missing_config?(:js_agent_loader)
44
44
  ::NewRelic::Agent.logger.log_once(:debug, :missing_js_agent_loader,
45
- "Missing :js_agent_loader. Skipping browser instrumentation.")
45
+ "Missing :js_agent_loader. Skipping browser instrumentation.")
46
46
  false
47
47
  elsif missing_config?(:beacon)
48
48
  ::NewRelic::Agent.logger.log_once(:debug, :missing_beacon,
49
- "Beacon configuration not received (yet?). Skipping browser instrumentation.")
49
+ "Beacon configuration not received (yet?). Skipping browser instrumentation.")
50
50
  false
51
51
  elsif missing_config?(:browser_key)
52
52
  ::NewRelic::Agent.logger.log_once(:debug, :missing_browser_key,
53
- "Browser key is not set. Skipping browser instrumentation.")
53
+ "Browser key is not set. Skipping browser instrumentation.")
54
54
  false
55
55
  else
56
56
  true
@@ -83,7 +83,7 @@ module NewRelic
83
83
  value.nil? || value.empty?
84
84
  end
85
85
 
86
- def browser_timing_header(nonce=nil) #THREAD_LOCAL_ACCESS
86
+ def browser_timing_header(nonce = nil) # THREAD_LOCAL_ACCESS
87
87
  return '' unless js_enabled_and_ready? # fast exit
88
88
 
89
89
  state = NewRelic::Agent::Tracer.state
@@ -99,11 +99,11 @@ module NewRelic
99
99
  ''
100
100
  end
101
101
 
102
- def browser_timing_loader(nonce=nil)
102
+ def browser_timing_loader(nonce = nil)
103
103
  html_safe_if_needed("\n<script type=\"text/javascript\"#{create_nonce(nonce)}>#{Agent.config[:js_agent_loader]}</script>")
104
104
  end
105
105
 
106
- def browser_timing_config(state, nonce=nil)
106
+ def browser_timing_config(state, nonce = nil)
107
107
  txn = state.current_transaction
108
108
  return '' if txn.nil?
109
109
 
@@ -116,44 +116,44 @@ module NewRelic
116
116
  ''
117
117
  end
118
118
 
119
- def create_nonce(nonce=nil)
119
+ def create_nonce(nonce = nil)
120
120
  return '' unless nonce
121
121
  " nonce=\"#{nonce.to_s}\""
122
122
  end
123
123
 
124
- BEACON_KEY = "beacon".freeze
125
- ERROR_BEACON_KEY = "errorBeacon".freeze
126
- LICENSE_KEY_KEY = "licenseKey".freeze
127
- APPLICATIONID_KEY = "applicationID".freeze
124
+ BEACON_KEY = "beacon".freeze
125
+ ERROR_BEACON_KEY = "errorBeacon".freeze
126
+ LICENSE_KEY_KEY = "licenseKey".freeze
127
+ APPLICATIONID_KEY = "applicationID".freeze
128
128
  TRANSACTION_NAME_KEY = "transactionName".freeze
129
- QUEUE_TIME_KEY = "queueTime".freeze
129
+ QUEUE_TIME_KEY = "queueTime".freeze
130
130
  APPLICATION_TIME_KEY = "applicationTime".freeze
131
- AGENT_KEY = "agent".freeze
132
- SSL_FOR_HTTP_KEY = "sslForHttp".freeze
133
- ATTS_KEY = "atts".freeze
134
- ATTS_USER_SUBKEY = "u".freeze
135
- ATTS_AGENT_SUBKEY = "a".freeze
131
+ AGENT_KEY = "agent".freeze
132
+ SSL_FOR_HTTP_KEY = "sslForHttp".freeze
133
+ ATTS_KEY = "atts".freeze
134
+ ATTS_USER_SUBKEY = "u".freeze
135
+ ATTS_AGENT_SUBKEY = "a".freeze
136
136
 
137
137
  # NOTE: Internal prototyping may override this, so leave name stable!
138
138
  def data_for_js_agent(transaction)
139
- queue_time_in_seconds = [transaction.queue_time.to_f, 0.0].max
140
- start_time_in_seconds = [transaction.start_time.to_f, 0.0].max
141
- app_time_in_seconds = Time.now.to_f - start_time_in_seconds
139
+ queue_time_in_seconds = [transaction.queue_time, 0.0].max
140
+ start_time_in_seconds = [transaction.start_time, 0.0].max
141
+ app_time_in_seconds = Process.clock_gettime(Process::CLOCK_REALTIME) - start_time_in_seconds
142
142
 
143
143
  queue_time_in_millis = (1000.0 * queue_time_in_seconds).round
144
- app_time_in_millis = (1000.0 * app_time_in_seconds).round
144
+ app_time_in_millis = (1000.0 * app_time_in_seconds).round
145
145
 
146
146
  transaction_name = transaction.best_name || ::NewRelic::Agent::UNKNOWN_METRIC
147
147
 
148
148
  data = {
149
- BEACON_KEY => NewRelic::Agent.config[:beacon],
150
- ERROR_BEACON_KEY => NewRelic::Agent.config[:error_beacon],
151
- LICENSE_KEY_KEY => NewRelic::Agent.config[:browser_key],
152
- APPLICATIONID_KEY => NewRelic::Agent.config[:application_id],
149
+ BEACON_KEY => NewRelic::Agent.config[:beacon],
150
+ ERROR_BEACON_KEY => NewRelic::Agent.config[:error_beacon],
151
+ LICENSE_KEY_KEY => NewRelic::Agent.config[:browser_key],
152
+ APPLICATIONID_KEY => NewRelic::Agent.config[:application_id],
153
153
  TRANSACTION_NAME_KEY => obfuscator.obfuscate(transaction_name),
154
- QUEUE_TIME_KEY => queue_time_in_millis,
154
+ QUEUE_TIME_KEY => queue_time_in_millis,
155
155
  APPLICATION_TIME_KEY => app_time_in_millis,
156
- AGENT_KEY => NewRelic::Agent.config[:js_agent_file]
156
+ AGENT_KEY => NewRelic::Agent.config[:js_agent_file]
157
157
  }
158
158
 
159
159
  add_ssl_for_http(data)
@@ -8,7 +8,6 @@ require 'new_relic/agent/hostname'
8
8
  module NewRelic
9
9
  module Agent
10
10
  module Logging
11
-
12
11
  # This class can be used as the formatter for an existing logger. It
13
12
  # decorates log messages with trace and entity metadata, and formats each
14
13
  # log messages as a JSON object.
@@ -33,6 +32,7 @@ module NewRelic
33
32
  COLON = ':'.freeze
34
33
  COMMA = ','.freeze
35
34
  CLOSING_BRACE = '}'.freeze
35
+ REPLACEMENT_CHAR = '�'
36
36
 
37
37
  def initialize
38
38
  Agent.config.register_callback :app_name do
@@ -86,12 +86,17 @@ module NewRelic
86
86
  message << QUOTE << key << QUOTE << COLON << QUOTE << value << QUOTE
87
87
  end
88
88
 
89
- def escape message
90
- if String === message
91
- message.to_json
92
- else
93
- message.inspect.to_json
89
+ def escape(message)
90
+ message = message.to_s unless message.is_a?(String)
91
+ unless message.encoding == Encoding::UTF_8 && message.valid_encoding?
92
+ message = message.encode(
93
+ Encoding::UTF_8,
94
+ invalid: :replace,
95
+ undef: :replace,
96
+ replace: REPLACEMENT_CHAR
97
+ )
94
98
  end
99
+ message.to_json
95
100
  end
96
101
 
97
102
  def clear_tags!
@@ -99,7 +104,6 @@ module NewRelic
99
104
  end
100
105
  end
101
106
 
102
-
103
107
  # This logger decorates logs with trace and entity metadata, and emits log
104
108
  # messages formatted as JSON objects. It extends the Logger class from
105
109
  # the Ruby standard library, and accepts the same constructor parameters.
@@ -116,7 +120,6 @@ module NewRelic
116
120
  #
117
121
  # @api public
118
122
  class DecoratingLogger < (defined?(::ActiveSupport) && defined?(::ActiveSupport::Logger) ? ::ActiveSupport::Logger : ::Logger)
119
-
120
123
  alias :write :info
121
124
 
122
125
  # Positional and Keyword arguments are separated beginning with Ruby 2.7
@@ -44,7 +44,7 @@ module NewRelic
44
44
  messages << [:debug, msgs, blk]
45
45
  end
46
46
 
47
- def log_exception(level, e, backtrace_level=level)
47
+ def log_exception(level, e, backtrace_level = level)
48
48
  messages << [:log_exception, [level, e, backtrace_level]]
49
49
  end
50
50
 
@@ -18,8 +18,8 @@ module NewRelic
18
18
  RABBITMQ_TRANSPORT_TYPE = "RabbitMQ"
19
19
 
20
20
  ATTR_DESTINATION = AttributeFilter::DST_TRANSACTION_EVENTS |
21
- AttributeFilter::DST_TRANSACTION_TRACER |
22
- AttributeFilter::DST_ERROR_COLLECTOR
21
+ AttributeFilter::DST_TRANSACTION_TRACER |
22
+ AttributeFilter::DST_ERROR_COLLECTOR
23
23
 
24
24
  # Start a MessageBroker segment configured to trace a messaging action.
25
25
  # Finishing this segment will handle timing and recording of the proper
@@ -53,12 +53,12 @@ module NewRelic
53
53
  # @api public
54
54
  #
55
55
  def start_message_broker_segment(action: nil,
56
- library: nil,
57
- destination_type: nil,
58
- destination_name: nil,
59
- headers: nil,
60
- parameters: nil,
61
- start_time: nil)
56
+ library: nil,
57
+ destination_type: nil,
58
+ destination_name: nil,
59
+ headers: nil,
60
+ parameters: nil,
61
+ start_time: nil)
62
62
 
63
63
  Tracer.start_message_broker_segment(
64
64
  action: action,
@@ -110,20 +110,15 @@ module NewRelic
110
110
  #
111
111
  # @api public
112
112
  #
113
- def wrap_message_broker_consume_transaction library: nil,
114
- destination_type: nil,
115
- destination_name: nil,
116
- headers: nil,
117
- routing_key: nil,
118
- queue_name: nil,
119
- exchange_type: nil,
120
- reply_to: nil,
121
- correlation_id: nil
122
-
123
- # ruby 2.0.0 does not support required kwargs
124
- raise ArgumentError, 'missing required argument: library' if library.nil?
125
- raise ArgumentError, 'missing required argument: destination_type' if destination_type.nil?
126
- raise ArgumentError, 'missing required argument: destination_name' if destination_name.nil?
113
+ def wrap_message_broker_consume_transaction(library:,
114
+ destination_type:,
115
+ destination_name:,
116
+ headers: nil,
117
+ routing_key: nil,
118
+ queue_name: nil,
119
+ exchange_type: nil,
120
+ reply_to: nil,
121
+ correlation_id: nil)
127
122
 
128
123
  state = Tracer.state
129
124
  return yield if state.current_transaction
@@ -185,17 +180,14 @@ module NewRelic
185
180
  #
186
181
  # @api public
187
182
  #
188
- def start_amqp_publish_segment(library: nil,
189
- destination_name: nil,
190
- headers: nil,
191
- routing_key: nil,
192
- reply_to: nil,
193
- correlation_id: nil,
194
- exchange_type: nil)
195
-
196
- # ruby 2.0.0 does not support required kwargs
197
- raise ArgumentError, 'missing required argument: library' if library.nil?
198
- raise ArgumentError, 'missing required argument: destination_name' if destination_name.nil?
183
+ def start_amqp_publish_segment(library:,
184
+ destination_name:,
185
+ headers: nil,
186
+ routing_key: nil,
187
+ reply_to: nil,
188
+ correlation_id: nil,
189
+ exchange_type: nil)
190
+
199
191
  raise ArgumentError, 'missing required argument: headers' if headers.nil? && CrossAppTracing.cross_app_enabled?
200
192
 
201
193
  original_headers = headers.nil? ? nil : headers.dup
@@ -247,19 +239,13 @@ module NewRelic
247
239
  #
248
240
  # @api public
249
241
  #
250
- def start_amqp_consume_segment(library: nil,
251
- destination_name: nil,
252
- delivery_info: nil,
253
- message_properties: nil,
254
- exchange_type: nil,
255
- queue_name: nil,
256
- start_time: nil)
257
-
258
- # ruby 2.0.0 does not support required kwargs
259
- raise ArgumentError, 'missing required argument: library' if library.nil?
260
- raise ArgumentError, 'missing required argument: destination_name' if destination_name.nil?
261
- raise ArgumentError, 'missing required argument: delivery_info' if delivery_info.nil?
262
- raise ArgumentError, 'missing required argument: message_properties' if message_properties.nil?
242
+ def start_amqp_consume_segment(library:,
243
+ destination_name:,
244
+ delivery_info:,
245
+ message_properties:,
246
+ exchange_type: nil,
247
+ queue_name: nil,
248
+ start_time: nil)
263
249
 
264
250
  segment = Tracer.start_message_broker_segment(
265
251
  action: :consume,
@@ -315,22 +301,22 @@ module NewRelic
315
301
  # @api public
316
302
  #
317
303
  def wrap_amqp_consume_transaction library: nil,
318
- destination_name: nil,
319
- delivery_info: nil,
320
- message_properties: nil,
321
- exchange_type: nil,
322
- queue_name: nil,
323
- &block
304
+ destination_name: nil,
305
+ delivery_info: nil,
306
+ message_properties: nil,
307
+ exchange_type: nil,
308
+ queue_name: nil,
309
+ &block
324
310
 
325
311
  wrap_message_broker_consume_transaction library: library,
326
- destination_type: :exchange,
327
- destination_name: Instrumentation::Bunny.exchange_name(destination_name),
328
- routing_key: delivery_info[:routing_key],
329
- reply_to: message_properties[:reply_to],
330
- queue_name: queue_name,
331
- exchange_type: exchange_type,
332
- headers: message_properties[:headers],
333
- correlation_id: message_properties[:correlation_id],
312
+ destination_type: :exchange,
313
+ destination_name: Instrumentation::Bunny.exchange_name(destination_name),
314
+ routing_key: delivery_info[:routing_key],
315
+ reply_to: message_properties[:reply_to],
316
+ queue_name: queue_name,
317
+ exchange_type: exchange_type,
318
+ headers: message_properties[:headers],
319
+ correlation_id: message_properties[:correlation_id],
334
320
  &block
335
321
  end
336
322
 
@@ -366,7 +352,6 @@ module NewRelic
366
352
 
367
353
  transaction_name
368
354
  end
369
-
370
355
  end
371
356
  end
372
357
  end