newrelic_rpm 8.7.0 → 8.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (398) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +68 -189
  4. data/.rubocop_todo.yml +52 -0
  5. data/.simplecov +15 -0
  6. data/.snyk +11 -0
  7. data/.yardopts +1 -0
  8. data/Brewfile +1 -0
  9. data/CHANGELOG.md +181 -23
  10. data/CONTRIBUTING.md +1 -1
  11. data/Gemfile +0 -1
  12. data/Guardfile +1 -0
  13. data/README.md +1 -1
  14. data/Rakefile +13 -20
  15. data/Thorfile +5 -0
  16. data/bin/newrelic +2 -1
  17. data/bin/newrelic_cmd +1 -0
  18. data/bin/nrdebug +66 -45
  19. data/config.dot +5 -5
  20. data/init.rb +4 -4
  21. data/install.rb +2 -2
  22. data/lib/new_relic/agent/adaptive_sampler.rb +4 -4
  23. data/lib/new_relic/agent/agent/shutdown.rb +34 -0
  24. data/lib/new_relic/agent/agent/special_startup.rb +70 -0
  25. data/lib/new_relic/agent/agent/start_worker_thread.rb +163 -0
  26. data/lib/new_relic/agent/agent/startup.rb +196 -0
  27. data/lib/new_relic/agent/agent.rb +134 -534
  28. data/lib/new_relic/agent/agent_logger.rb +8 -10
  29. data/lib/new_relic/agent/attribute_filter.rb +40 -21
  30. data/lib/new_relic/agent/attribute_processing.rb +7 -7
  31. data/lib/new_relic/agent/attributes.rb +2 -2
  32. data/lib/new_relic/agent/audit_logger.rb +3 -3
  33. data/lib/new_relic/agent/autostart.rb +2 -2
  34. data/lib/new_relic/agent/chained_call.rb +1 -1
  35. data/lib/new_relic/agent/commands/agent_command.rb +1 -1
  36. data/lib/new_relic/agent/commands/agent_command_router.rb +8 -8
  37. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
  38. data/lib/new_relic/agent/configuration/default_source.rb +105 -41
  39. data/lib/new_relic/agent/configuration/dotted_hash.rb +2 -2
  40. data/lib/new_relic/agent/configuration/environment_source.rb +5 -5
  41. data/lib/new_relic/agent/configuration/event_harvest_config.rb +1 -1
  42. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -1
  43. data/lib/new_relic/agent/configuration/manager.rb +5 -5
  44. data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
  45. data/lib/new_relic/agent/configuration/mask_defaults.rb +3 -3
  46. data/lib/new_relic/agent/configuration/security_policy_source.rb +7 -4
  47. data/lib/new_relic/agent/configuration/server_source.rb +7 -7
  48. data/lib/new_relic/agent/configuration/yaml_source.rb +6 -4
  49. data/lib/new_relic/agent/configuration.rb +1 -1
  50. data/lib/new_relic/agent/connect/request_builder.rb +3 -3
  51. data/lib/new_relic/agent/connect/response_handler.rb +5 -5
  52. data/lib/new_relic/agent/custom_event_aggregator.rb +5 -5
  53. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
  54. data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -1
  55. data/lib/new_relic/agent/database/obfuscator.rb +2 -2
  56. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
  57. data/lib/new_relic/agent/database.rb +21 -21
  58. data/lib/new_relic/agent/database_adapter.rb +1 -1
  59. data/lib/new_relic/agent/datastores/metric_helper.rb +12 -13
  60. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +4 -3
  61. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +2 -4
  62. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +2 -2
  63. data/lib/new_relic/agent/datastores/mongo.rb +1 -1
  64. data/lib/new_relic/agent/datastores/redis.rb +3 -3
  65. data/lib/new_relic/agent/datastores.rb +4 -4
  66. data/lib/new_relic/agent/deprecator.rb +1 -1
  67. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +1 -1
  68. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +16 -17
  69. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +9 -10
  70. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +18 -19
  71. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +8 -10
  72. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +2 -3
  73. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +40 -40
  74. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +16 -15
  75. data/lib/new_relic/agent/distributed_tracing.rb +17 -18
  76. data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
  77. data/lib/new_relic/agent/error_collector.rb +6 -5
  78. data/lib/new_relic/agent/error_event_aggregator.rb +3 -4
  79. data/lib/new_relic/agent/error_filter.rb +5 -5
  80. data/lib/new_relic/agent/error_trace_aggregator.rb +3 -3
  81. data/lib/new_relic/agent/event_aggregator.rb +20 -20
  82. data/lib/new_relic/agent/event_buffer.rb +1 -1
  83. data/lib/new_relic/agent/event_listener.rb +1 -1
  84. data/lib/new_relic/agent/event_loop.rb +9 -9
  85. data/lib/new_relic/agent/external.rb +10 -10
  86. data/lib/new_relic/agent/guid_generator.rb +2 -2
  87. data/lib/new_relic/agent/harvester.rb +1 -1
  88. data/lib/new_relic/agent/heap.rb +5 -5
  89. data/lib/new_relic/agent/hostname.rb +4 -3
  90. data/lib/new_relic/agent/http_clients/abstract.rb +1 -2
  91. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +5 -6
  92. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +4 -5
  93. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +2 -3
  94. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +1 -2
  95. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +0 -1
  96. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -2
  97. data/lib/new_relic/agent/http_clients/uri_util.rb +1 -2
  98. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +6 -5
  99. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +31 -23
  100. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +7 -6
  101. data/lib/new_relic/agent/instrumentation/active_job.rb +11 -4
  102. data/lib/new_relic/agent/instrumentation/active_merchant.rb +4 -3
  103. data/lib/new_relic/agent/instrumentation/active_record.rb +9 -9
  104. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +37 -21
  105. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +3 -3
  106. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +1 -1
  107. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +21 -11
  108. data/lib/new_relic/agent/instrumentation/active_storage.rb +2 -2
  109. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +16 -15
  110. data/lib/new_relic/agent/instrumentation/active_support_logger/chain.rb +1 -1
  111. data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +1 -1
  112. data/lib/new_relic/agent/instrumentation/active_support_logger/prepend.rb +1 -1
  113. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +2 -2
  114. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -2
  115. data/lib/new_relic/agent/instrumentation/authlogic.rb +2 -2
  116. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +10 -10
  117. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +10 -11
  118. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +4 -4
  119. data/lib/new_relic/agent/instrumentation/bunny.rb +1 -2
  120. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +25 -17
  121. data/lib/new_relic/agent/instrumentation/curb/chain.rb +21 -22
  122. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +19 -16
  123. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +2 -3
  124. data/lib/new_relic/agent/instrumentation/curb.rb +2 -2
  125. data/lib/new_relic/agent/instrumentation/data_mapper.rb +44 -44
  126. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +1 -2
  127. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +2 -3
  128. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +1 -2
  129. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +3 -3
  130. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -3
  131. data/lib/new_relic/agent/instrumentation/excon.rb +2 -2
  132. data/lib/new_relic/agent/instrumentation/grape/chain.rb +6 -6
  133. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +5 -5
  134. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +4 -4
  135. data/lib/new_relic/agent/instrumentation/grape.rb +1 -1
  136. data/lib/new_relic/agent/instrumentation/grpc/client/chain.rb +97 -0
  137. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +89 -0
  138. data/lib/new_relic/agent/instrumentation/grpc/client/prepend.rb +111 -0
  139. data/lib/new_relic/agent/instrumentation/grpc/client/request_wrapper.rb +30 -0
  140. data/lib/new_relic/agent/instrumentation/grpc/helper.rb +32 -0
  141. data/lib/new_relic/agent/instrumentation/grpc/server/chain.rb +69 -0
  142. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +134 -0
  143. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_desc_prepend.rb +35 -0
  144. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_server_prepend.rb +26 -0
  145. data/lib/new_relic/agent/instrumentation/grpc_client.rb +23 -0
  146. data/lib/new_relic/agent/instrumentation/grpc_server.rb +25 -0
  147. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +1 -1
  148. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +6 -6
  149. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +1 -1
  150. data/lib/new_relic/agent/instrumentation/httpclient.rb +2 -2
  151. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +1 -1
  152. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +4 -4
  153. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -1
  154. data/lib/new_relic/agent/instrumentation/httprb.rb +2 -2
  155. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -2
  156. data/lib/new_relic/agent/instrumentation/logger/chain.rb +2 -2
  157. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +5 -1
  158. data/lib/new_relic/agent/instrumentation/logger/prepend.rb +1 -1
  159. data/lib/new_relic/agent/instrumentation/logger.rb +2 -2
  160. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +2 -3
  161. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +24 -17
  162. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +8 -9
  163. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +17 -15
  164. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +21 -15
  165. data/lib/new_relic/agent/instrumentation/memcache.rb +5 -6
  166. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +2 -2
  167. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +0 -1
  168. data/lib/new_relic/agent/instrumentation/mongo.rb +2 -2
  169. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +15 -14
  170. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +1 -1
  171. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -5
  172. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +1 -1
  173. data/lib/new_relic/agent/instrumentation/net_http.rb +2 -2
  174. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +6 -6
  175. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +1 -1
  176. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +1 -1
  177. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +1 -1
  178. data/lib/new_relic/agent/instrumentation/padrino.rb +2 -2
  179. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +3 -3
  180. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -2
  181. data/lib/new_relic/agent/instrumentation/rack/chain.rb +12 -12
  182. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +1 -1
  183. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +7 -7
  184. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +4 -4
  185. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  186. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -6
  187. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
  188. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +3 -2
  189. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +3 -2
  190. data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +3 -2
  191. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +3 -3
  192. data/lib/new_relic/agent/instrumentation/rake/chain.rb +2 -2
  193. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +6 -2
  194. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +1 -1
  195. data/lib/new_relic/agent/instrumentation/rake.rb +3 -3
  196. data/lib/new_relic/agent/instrumentation/redis/chain.rb +3 -4
  197. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +5 -6
  198. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +3 -4
  199. data/lib/new_relic/agent/instrumentation/redis.rb +2 -2
  200. data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -2
  201. data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
  202. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +0 -1
  203. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -1
  204. data/lib/new_relic/agent/instrumentation/resque.rb +3 -3
  205. data/lib/new_relic/agent/instrumentation/sequel.rb +8 -8
  206. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
  207. data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -5
  208. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +1 -1
  209. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +2 -2
  210. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +1 -1
  211. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +1 -1
  212. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +2 -2
  213. data/lib/new_relic/agent/instrumentation/sinatra.rb +2 -2
  214. data/lib/new_relic/agent/instrumentation/sunspot.rb +4 -4
  215. data/lib/new_relic/agent/instrumentation/thread/chain.rb +2 -2
  216. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -1
  217. data/lib/new_relic/agent/instrumentation/thread/prepend.rb +1 -1
  218. data/lib/new_relic/agent/instrumentation/thread.rb +2 -2
  219. data/lib/new_relic/agent/instrumentation/tilt/chain.rb +1 -1
  220. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +1 -1
  221. data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +1 -1
  222. data/lib/new_relic/agent/instrumentation/tilt.rb +1 -1
  223. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +1 -1
  224. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +8 -8
  225. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +1 -1
  226. data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
  227. data/lib/new_relic/agent/instrumentation.rb +1 -1
  228. data/lib/new_relic/agent/internal_agent_error.rb +1 -1
  229. data/lib/new_relic/agent/javascript_instrumentor.rb +8 -8
  230. data/lib/new_relic/agent/linking_metadata.rb +2 -3
  231. data/lib/new_relic/agent/local_log_decorator.rb +0 -1
  232. data/lib/new_relic/agent/log_event_aggregator.rb +7 -7
  233. data/lib/new_relic/agent/log_once.rb +1 -1
  234. data/lib/new_relic/agent/log_priority.rb +1 -1
  235. data/lib/new_relic/agent/logging.rb +13 -13
  236. data/lib/new_relic/agent/memory_logger.rb +1 -1
  237. data/lib/new_relic/agent/messaging.rb +19 -20
  238. data/lib/new_relic/agent/method_tracer.rb +15 -10
  239. data/lib/new_relic/agent/method_tracer_helpers.rb +83 -1
  240. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +4 -4
  241. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +3 -3
  242. data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +1 -1
  243. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +2 -2
  244. data/lib/new_relic/agent/monitors.rb +5 -5
  245. data/lib/new_relic/agent/new_relic_service/encoders.rb +2 -2
  246. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +4 -4
  247. data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
  248. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -1
  249. data/lib/new_relic/agent/new_relic_service.rb +214 -166
  250. data/lib/new_relic/agent/{noticible_error.rb → noticeable_error.rb} +2 -3
  251. data/lib/new_relic/agent/null_logger.rb +1 -1
  252. data/lib/new_relic/agent/obfuscator.rb +3 -3
  253. data/lib/new_relic/agent/parameter_filtering.rb +1 -1
  254. data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
  255. data/lib/new_relic/agent/pipe_channel_manager.rb +10 -5
  256. data/lib/new_relic/agent/pipe_service.rb +2 -2
  257. data/lib/new_relic/agent/prepend_supportability.rb +2 -2
  258. data/lib/new_relic/agent/priority_sampled_buffer.rb +4 -4
  259. data/lib/new_relic/agent/range_extensions.rb +8 -28
  260. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +2 -2
  261. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
  262. data/lib/new_relic/agent/rules_engine.rb +2 -2
  263. data/lib/new_relic/agent/sampler.rb +1 -1
  264. data/lib/new_relic/agent/sampler_collection.rb +1 -1
  265. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  266. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -2
  267. data/lib/new_relic/agent/samplers/memory_sampler.rb +10 -10
  268. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  269. data/lib/new_relic/agent/samplers/vm_sampler.rb +3 -1
  270. data/lib/new_relic/agent/span_event_aggregator.rb +2 -2
  271. data/lib/new_relic/agent/span_event_primitive.rb +24 -19
  272. data/lib/new_relic/agent/sql_sampler.rb +8 -8
  273. data/lib/new_relic/agent/stats.rb +15 -4
  274. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -2
  275. data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -4
  276. data/lib/new_relic/agent/stats_engine.rb +1 -1
  277. data/lib/new_relic/agent/synthetics_event_aggregator.rb +6 -6
  278. data/lib/new_relic/agent/system_info.rb +68 -53
  279. data/lib/new_relic/agent/threading/agent_thread.rb +13 -9
  280. data/lib/new_relic/agent/threading/backtrace_node.rb +6 -4
  281. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
  282. data/lib/new_relic/agent/threading/thread_profile.rb +4 -4
  283. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
  284. data/lib/new_relic/agent/tracer.rb +19 -17
  285. data/lib/new_relic/agent/transaction/abstract_segment.rb +93 -34
  286. data/lib/new_relic/agent/transaction/datastore_segment.rb +12 -12
  287. data/lib/new_relic/agent/transaction/distributed_tracer.rb +52 -48
  288. data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -22
  289. data/lib/new_relic/agent/transaction/external_request_segment.rb +37 -29
  290. data/lib/new_relic/agent/transaction/message_broker_segment.rb +6 -6
  291. data/lib/new_relic/agent/transaction/request_attributes.rb +29 -29
  292. data/lib/new_relic/agent/transaction/segment.rb +8 -8
  293. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
  294. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  295. data/lib/new_relic/agent/transaction/trace.rb +3 -3
  296. data/lib/new_relic/agent/transaction/trace_builder.rb +10 -10
  297. data/lib/new_relic/agent/transaction/trace_context.rb +22 -20
  298. data/lib/new_relic/agent/transaction/trace_node.rb +9 -9
  299. data/lib/new_relic/agent/transaction/tracing.rb +7 -7
  300. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -2
  301. data/lib/new_relic/agent/transaction.rb +35 -31
  302. data/lib/new_relic/agent/transaction_error_primitive.rb +9 -9
  303. data/lib/new_relic/agent/transaction_event_aggregator.rb +5 -5
  304. data/lib/new_relic/agent/transaction_event_primitive.rb +3 -4
  305. data/lib/new_relic/agent/transaction_event_recorder.rb +15 -14
  306. data/lib/new_relic/agent/transaction_metrics.rb +4 -4
  307. data/lib/new_relic/agent/transaction_sampler.rb +5 -5
  308. data/lib/new_relic/agent/transaction_time_aggregator.rb +14 -14
  309. data/lib/new_relic/agent/utilization/aws.rb +4 -4
  310. data/lib/new_relic/agent/utilization/azure.rb +2 -2
  311. data/lib/new_relic/agent/utilization/gcp.rb +7 -7
  312. data/lib/new_relic/agent/utilization/pcf.rb +4 -4
  313. data/lib/new_relic/agent/utilization/vendor.rb +28 -28
  314. data/lib/new_relic/agent/utilization_data.rb +1 -1
  315. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
  316. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  317. data/lib/new_relic/agent/vm/mri_vm.rb +36 -23
  318. data/lib/new_relic/agent/vm/snapshot.rb +2 -2
  319. data/lib/new_relic/agent/vm.rb +1 -1
  320. data/lib/new_relic/agent/worker_loop.rb +2 -2
  321. data/lib/new_relic/agent.rb +27 -27
  322. data/lib/new_relic/cli/command.rb +6 -6
  323. data/lib/new_relic/cli/commands/deployments.rb +81 -29
  324. data/lib/new_relic/cli/commands/install.rb +6 -6
  325. data/lib/new_relic/coerce.rb +5 -6
  326. data/lib/new_relic/collection_helper.rb +4 -4
  327. data/lib/new_relic/constants.rb +0 -1
  328. data/lib/new_relic/control/class_methods.rb +1 -1
  329. data/lib/new_relic/control/frameworks/external.rb +1 -1
  330. data/lib/new_relic/control/frameworks/rails.rb +3 -3
  331. data/lib/new_relic/control/frameworks/rails3.rb +1 -1
  332. data/lib/new_relic/control/frameworks/rails4.rb +1 -1
  333. data/lib/new_relic/control/frameworks/rails_notifications.rb +1 -1
  334. data/lib/new_relic/control/frameworks/ruby.rb +1 -1
  335. data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
  336. data/lib/new_relic/control/frameworks.rb +1 -1
  337. data/lib/new_relic/control/instance_methods.rb +20 -42
  338. data/lib/new_relic/control/instrumentation.rb +7 -7
  339. data/lib/new_relic/control/private_instance_methods.rb +48 -0
  340. data/lib/new_relic/control/server_methods.rb +2 -2
  341. data/lib/new_relic/control.rb +1 -1
  342. data/lib/new_relic/delayed_job_injection.rb +1 -1
  343. data/lib/new_relic/dependency_detection.rb +23 -22
  344. data/lib/new_relic/environment_report.rb +24 -14
  345. data/lib/new_relic/helper.rb +5 -5
  346. data/lib/new_relic/language_support.rb +8 -3
  347. data/lib/new_relic/latest_changes.rb +4 -4
  348. data/lib/new_relic/local_environment.rb +9 -11
  349. data/lib/new_relic/metric_data.rb +30 -24
  350. data/lib/new_relic/metric_spec.rb +3 -3
  351. data/lib/new_relic/noticed_error.rb +3 -6
  352. data/lib/new_relic/rack/agent_hooks.rb +1 -1
  353. data/lib/new_relic/rack/agent_middleware.rb +1 -1
  354. data/lib/new_relic/rack/browser_monitoring.rb +132 -123
  355. data/lib/new_relic/rack.rb +1 -1
  356. data/lib/new_relic/recipes/capistrano3.rb +3 -59
  357. data/lib/new_relic/recipes/capistrano_legacy.rb +13 -13
  358. data/lib/new_relic/recipes/helpers/send_deployment.rb +69 -0
  359. data/lib/new_relic/recipes.rb +1 -1
  360. data/lib/new_relic/supportability_helper.rb +6 -6
  361. data/lib/new_relic/traced_thread.rb +5 -7
  362. data/lib/new_relic/version.rb +2 -2
  363. data/lib/newrelic_rpm.rb +1 -1
  364. data/lib/sequel/extensions/newrelic_instrumentation.rb +8 -8
  365. data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
  366. data/lib/tasks/all.rb +1 -1
  367. data/lib/tasks/config.rake +8 -112
  368. data/lib/tasks/coverage_report.rake +28 -0
  369. data/lib/tasks/{config.html.erb → helpers/config.html.erb} +0 -0
  370. data/lib/tasks/{config.text.erb → helpers/config.text.erb} +0 -0
  371. data/lib/tasks/helpers/format.rb +120 -0
  372. data/lib/tasks/helpers/matches.rb +12 -0
  373. data/lib/tasks/helpers/prompt.rb +24 -0
  374. data/lib/tasks/helpers/removers.rb +33 -0
  375. data/lib/tasks/install.rake +4 -0
  376. data/lib/tasks/instrumentation_generator/README.md +63 -0
  377. data/lib/tasks/instrumentation_generator/TODO.md +33 -0
  378. data/lib/tasks/instrumentation_generator/instrumentation.thor +102 -0
  379. data/lib/tasks/instrumentation_generator/templates/Envfile.tt +9 -0
  380. data/lib/tasks/instrumentation_generator/templates/chain.tt +21 -0
  381. data/lib/tasks/instrumentation_generator/templates/chain_method.tt +7 -0
  382. data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +29 -0
  383. data/lib/tasks/instrumentation_generator/templates/instrumentation.tt +12 -0
  384. data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +3 -0
  385. data/lib/tasks/instrumentation_generator/templates/newrelic.yml.tt +19 -0
  386. data/lib/tasks/instrumentation_generator/templates/prepend.tt +13 -0
  387. data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +3 -0
  388. data/lib/tasks/instrumentation_generator/templates/test.tt +15 -0
  389. data/lib/tasks/multiverse.rake +4 -0
  390. data/lib/tasks/multiverse.rb +5 -30
  391. data/lib/tasks/newrelic.rb +1 -1
  392. data/lib/tasks/tests.rake +7 -8
  393. data/newrelic.yml +514 -483
  394. data/newrelic_rpm.gemspec +16 -21
  395. data/recipes/newrelic.rb +1 -1
  396. data/test/agent_helper.rb +125 -147
  397. metadata +82 -90
  398. data/bin/mongrel_rpm +0 -32
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'new_relic/coerce'
6
6
 
@@ -8,9 +8,11 @@ module NewRelic
8
8
  class MetricData
9
9
  # a NewRelic::MetricSpec object
10
10
  attr_reader :metric_spec
11
- # the actual statistics object
11
+ # a NewRelic::Agent::Stats object
12
12
  attr_accessor :stats
13
13
 
14
+ include NewRelic::Coerce
15
+
14
16
  def initialize(metric_spec, stats)
15
17
  @original_spec = nil
16
18
  @metric_spec = metric_spec
@@ -18,22 +20,31 @@ module NewRelic
18
20
  end
19
21
 
20
22
  def eql?(o)
21
- (metric_spec.eql? o.metric_spec) && (stats.eql? o.stats)
23
+ (metric_spec.eql?(o.metric_spec)) && (stats.eql?(o.stats))
22
24
  end
23
25
 
24
- def original_spec
25
- @original_spec || @metric_spec
26
+ def hash
27
+ [metric_spec, stats].hash
28
+ end
29
+
30
+ def inspect
31
+ "#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}>"
26
32
  end
27
33
 
28
34
  # assigns a new metric spec, and retains the old metric spec as
29
35
  # @original_spec if it exists currently
30
- def metric_spec= new_spec
36
+ def metric_spec=(new_spec)
31
37
  @original_spec = @metric_spec if @metric_spec
32
38
  @metric_spec = new_spec
33
39
  end
34
40
 
35
- def hash
36
- metric_spec.hash ^ stats.hash
41
+ def original_spec
42
+ @original_spec || @metric_spec
43
+ end
44
+
45
+ def to_collector_array(encoder = nil)
46
+ stat_key = {'name' => metric_spec.name, 'scope' => metric_spec.scope}
47
+ [stat_key, stats_collector_array(stat_key)]
37
48
  end
38
49
 
39
50
  def to_json(*a)
@@ -44,23 +55,18 @@ module NewRelic
44
55
  "#{metric_spec.name}(#{metric_spec.scope}): #{stats}"
45
56
  end
46
57
 
47
- def inspect
48
- "#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}>"
49
- end
50
-
51
- include NewRelic::Coerce
58
+ private
52
59
 
53
- def to_collector_array(encoder = nil)
54
- stat_key = {'name' => metric_spec.name, 'scope' => metric_spec.scope}
55
- [stat_key,
56
- [
57
- int(stats.call_count, stat_key),
58
- float(stats.total_call_time, stat_key),
59
- float(stats.total_exclusive_time, stat_key),
60
- float(stats.min_call_time, stat_key),
61
- float(stats.max_call_time, stat_key),
62
- float(stats.sum_of_squares, stat_key)
63
- ]]
60
+ def stats_collector_array(stat_key)
61
+ [[:call_count, Integer], [:total_call_time, Float],
62
+ [:total_exclusive_time, Float], [:min_call_time, Float],
63
+ [:max_call_time, Float], [:sum_of_squares, Float]].map do |attr_types|
64
+ if attr_types[1].eql?(Integer)
65
+ int(stats.send(attr_types[0]), stat_key)
66
+ elsif attr_types[1].eql?(Float)
67
+ float(stats.send(attr_types[0]), stat_key)
68
+ end
69
+ end
64
70
  end
65
71
  end
66
72
  end
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  # this struct uniquely defines a metric, optionally inside
6
6
  # the call scope of another metric
@@ -34,12 +34,12 @@ class NewRelic::MetricSpec
34
34
  self.eql?(o)
35
35
  end
36
36
 
37
- def eql? o
37
+ def eql?(o)
38
38
  @name == o.name && @scope == o.scope
39
39
  end
40
40
 
41
41
  def hash
42
- @name.hash ^ @scope.hash
42
+ [@name, @scope].hash
43
43
  end
44
44
 
45
45
  def to_s
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
3
  # frozen_string_literal: true
@@ -135,10 +134,8 @@ class NewRelic::NoticedError
135
134
 
136
135
  def build_error_attributes
137
136
  @attributes_from_notice_error ||= {}
138
- @attributes_from_notice_error.merge!({
139
- ERROR_MESSAGE_KEY => string(message),
140
- ERROR_CLASS_KEY => string(exception_class_name)
141
- })
137
+ @attributes_from_notice_error[ERROR_MESSAGE_KEY] = string(message)
138
+ @attributes_from_notice_error[ERROR_CLASS_KEY] = string(exception_class_name)
142
139
 
143
140
  @attributes_from_notice_error[ERROR_EXPECTED_KEY] = true if expected
144
141
  end
@@ -189,7 +186,7 @@ class NewRelic::NoticedError
189
186
  if exception.nil?
190
187
  @exception_class_name = UNKNOWN_ERROR_CLASS_NAME
191
188
  @message = NIL_ERROR_MESSAGE
192
- elsif exception.is_a? NewRelic::Agent::NoticibleError
189
+ elsif exception.is_a?(NewRelic::Agent::NoticeableError)
193
190
  @exception_class_name = exception.class_name
194
191
  @message = exception.message
195
192
  else
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'new_relic/agent/event_listener'
6
6
  require 'new_relic/rack/agent_middleware'
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'new_relic/agent/tracer'
6
6
  require 'new_relic/agent/instrumentation/controller_instrumentation'
@@ -1,157 +1,166 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'rack'
6
6
  require 'new_relic/rack/agent_middleware'
7
7
  require 'new_relic/agent/instrumentation/middleware_proxy'
8
8
 
9
- module NewRelic::Rack
10
- # This middleware is used by the agent for the Real user monitoring (RUM)
11
- # feature, and will usually be automatically injected in the middleware chain.
12
- # If automatic injection is not working, you may manually use it in your
13
- # middleware chain instead.
14
- #
15
- # @api public
16
- #
17
- class BrowserMonitoring < AgentMiddleware
18
- # The maximum number of bytes of the response body that we will
19
- # examine in order to look for a RUM insertion point.
20
- SCAN_LIMIT = 50_000
21
-
22
- CONTENT_TYPE = 'Content-Type'.freeze
23
- CONTENT_DISPOSITION = 'Content-Disposition'.freeze
24
- CONTENT_LENGTH = 'Content-Length'.freeze
25
- ATTACHMENT = 'attachment'.freeze
26
- TEXT_HTML = 'text/html'.freeze
27
-
28
- BODY_START = "<body".freeze
29
- HEAD_START = "<head".freeze
30
- GT = ">".freeze
31
-
32
- def traced_call(env)
33
- result = @app.call(env)
34
- (status, headers, response) = result
35
-
36
- js_to_inject = NewRelic::Agent.browser_timing_header
37
- if (js_to_inject != "") && should_instrument?(env, status, headers)
38
- response_string = autoinstrument_source(response, headers, js_to_inject)
39
- if headers.key?(CONTENT_LENGTH)
40
- content_length = response_string ? response_string.bytesize : 0
41
- headers[CONTENT_LENGTH] = content_length.to_s
42
- end
43
-
44
- env[ALREADY_INSTRUMENTED_KEY] = true
45
- if response_string
46
- response = Rack::Response.new(response_string, status, headers)
47
- response.finish
9
+ module NewRelic
10
+ module Rack
11
+ # This middleware is used by the agent for the Real user monitoring (RUM)
12
+ # feature, and will usually be automatically injected in the middleware chain.
13
+ # If automatic injection is not working, you may manually use it in your
14
+ # middleware chain instead.
15
+ #
16
+ # @api public
17
+ #
18
+ class BrowserMonitoring < AgentMiddleware
19
+ # The maximum number of bytes of the response body that we will
20
+ # examine in order to look for a RUM insertion point.
21
+ SCAN_LIMIT = 50_000
22
+
23
+ CONTENT_TYPE = 'Content-Type'.freeze
24
+ CONTENT_DISPOSITION = 'Content-Disposition'.freeze
25
+ CONTENT_LENGTH = 'Content-Length'.freeze
26
+ ATTACHMENT = 'attachment'.freeze
27
+ TEXT_HTML = 'text/html'.freeze
28
+
29
+ BODY_START = "<body".freeze
30
+ HEAD_START = "<head".freeze
31
+ GT = ">".freeze
32
+
33
+ ALREADY_INSTRUMENTED_KEY = "newrelic.browser_monitoring_already_instrumented"
34
+ CHARSET_RE = /<\s*meta[^>]+charset\s*=[^>]*>/im.freeze
35
+ X_UA_COMPATIBLE_RE = /<\s*meta[^>]+http-equiv\s*=\s*['"]x-ua-compatible['"][^>]*>/im.freeze
36
+
37
+ def traced_call(env)
38
+ result = @app.call(env)
39
+ (status, headers, response) = result
40
+
41
+ js_to_inject = NewRelic::Agent.browser_timing_header
42
+ if (js_to_inject != NewRelic::EMPTY_STR) && should_instrument?(env, status, headers)
43
+ response_string = autoinstrument_source(response, headers, js_to_inject)
44
+ if headers.key?(CONTENT_LENGTH)
45
+ content_length = response_string ? response_string.bytesize : 0
46
+ headers[CONTENT_LENGTH] = content_length.to_s
47
+ end
48
+
49
+ env[ALREADY_INSTRUMENTED_KEY] = true
50
+ if response_string
51
+ response = ::Rack::Response.new(response_string, status, headers)
52
+ response.finish
53
+ else
54
+ result
55
+ end
48
56
  else
49
57
  result
50
58
  end
51
- else
52
- result
53
59
  end
54
- end
55
60
 
56
- ALREADY_INSTRUMENTED_KEY = "newrelic.browser_monitoring_already_instrumented"
57
-
58
- def should_instrument?(env, status, headers)
59
- NewRelic::Agent.config[:'browser_monitoring.auto_instrument'] &&
60
- status == 200 &&
61
- !env[ALREADY_INSTRUMENTED_KEY] &&
62
- is_html?(headers) &&
63
- !is_attachment?(headers) &&
64
- !is_streaming?(env, headers)
65
- end
66
-
67
- def is_html?(headers)
68
- headers[CONTENT_TYPE] && headers[CONTENT_TYPE].include?(TEXT_HTML)
69
- end
70
-
71
- def is_attachment?(headers)
72
- headers[CONTENT_DISPOSITION] && headers[CONTENT_DISPOSITION].include?(ATTACHMENT)
73
- end
61
+ def should_instrument?(env, status, headers)
62
+ NewRelic::Agent.config[:'browser_monitoring.auto_instrument'] &&
63
+ status == 200 &&
64
+ !env[ALREADY_INSTRUMENTED_KEY] &&
65
+ html?(headers) &&
66
+ !attachment?(headers) &&
67
+ !streaming?(env, headers)
68
+ end
74
69
 
75
- def is_streaming?(env, headers)
76
- return true if headers && headers['Transfer-Encoding'] == 'chunked'
70
+ private
71
+
72
+ def autoinstrument_source(response, headers, js_to_inject)
73
+ source = gather_source(response)
74
+ close_old_response(response)
75
+ return nil unless source
76
+
77
+ # Only scan the first 50k (roughly) then give up.
78
+ beginning_of_source = source[0..SCAN_LIMIT]
79
+ meta_tag_positions = find_meta_tag_positions(beginning_of_source)
80
+ if body_start = find_body_start(beginning_of_source)
81
+ if insertion_index = find_insertion_index(meta_tag_positions, beginning_of_source, body_start)
82
+ source = source_injection(source, insertion_index, js_to_inject)
83
+ else
84
+ NewRelic::Agent.logger.debug("Skipping RUM instrumentation. Could not properly determine location to inject script.")
85
+ end
86
+ else
87
+ msg = "Skipping RUM instrumentation. Unable to find <body> tag in first #{SCAN_LIMIT} bytes of document."
88
+ NewRelic::Agent.logger.log_once(:warn, :rum_insertion_failure, msg)
89
+ NewRelic::Agent.logger.debug(msg)
90
+ end
77
91
 
78
- defined?(ActionController::Live) &&
79
- env['action_controller.instance'].class.included_modules.include?(ActionController::Live)
80
- end
92
+ source
93
+ rescue => e
94
+ NewRelic::Agent.logger.debug("Skipping RUM instrumentation on exception.", e)
95
+ nil
96
+ end
81
97
 
82
- CHARSET_RE = /<\s*meta[^>]+charset\s*=[^>]*>/im.freeze
83
- X_UA_COMPATIBLE_RE = /<\s*meta[^>]+http-equiv\s*=\s*['"]x-ua-compatible['"][^>]*>/im.freeze
98
+ def html?(headers)
99
+ headers[CONTENT_TYPE] && headers[CONTENT_TYPE].include?(TEXT_HTML)
100
+ end
84
101
 
85
- def autoinstrument_source(response, headers, js_to_inject)
86
- source = gather_source(response)
87
- close_old_response(response)
88
- return nil unless source
102
+ def attachment?(headers)
103
+ headers[CONTENT_DISPOSITION] && headers[CONTENT_DISPOSITION].include?(ATTACHMENT)
104
+ end
89
105
 
90
- # Only scan the first 50k (roughly) then give up.
91
- beginning_of_source = source[0..SCAN_LIMIT]
106
+ def streaming?(env, headers)
107
+ return true if headers && headers['Transfer-Encoding'] == 'chunked'
92
108
 
93
- if body_start = find_body_start(beginning_of_source)
94
- meta_tag_positions = [
95
- find_x_ua_compatible_position(beginning_of_source),
96
- find_charset_position(beginning_of_source)
97
- ].compact
109
+ defined?(ActionController::Live) &&
110
+ env['action_controller.instance'].class.included_modules.include?(ActionController::Live)
111
+ end
98
112
 
99
- if !meta_tag_positions.empty?
100
- insertion_index = meta_tag_positions.max
101
- else
102
- insertion_index = find_end_of_head_open(beginning_of_source) || body_start
103
- end
113
+ def source_injection(source, insertion_index, js_to_inject)
114
+ source[0...insertion_index] <<
115
+ js_to_inject <<
116
+ source[insertion_index..-1]
117
+ end
104
118
 
105
- if insertion_index
106
- source = source[0...insertion_index] <<
107
- js_to_inject <<
108
- source[insertion_index..-1]
119
+ def find_insertion_index(tag_positions, source_beginning, body_start)
120
+ if !tag_positions.empty?
121
+ tag_positions.max
109
122
  else
110
- NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Could not properly determine location to inject script."
123
+ find_end_of_head_open(source_beginning) || body_start
111
124
  end
112
- else
113
- msg = "Skipping RUM instrumentation. Unable to find <body> tag in first #{SCAN_LIMIT} bytes of document."
114
- NewRelic::Agent.logger.log_once(:warn, :rum_insertion_failure, msg)
115
- NewRelic::Agent.logger.debug(msg)
116
125
  end
117
126
 
118
- source
119
- rescue => e
120
- NewRelic::Agent.logger.debug "Skipping RUM instrumentation on exception.", e
121
- nil
122
- end
127
+ def find_meta_tag_positions(source_beginning)
128
+ [
129
+ find_x_ua_compatible_position(source_beginning),
130
+ find_charset_position(source_beginning)
131
+ ].compact
132
+ end
123
133
 
124
- def gather_source(response)
125
- source = nil
126
- response.each { |fragment| source ? (source << fragment.to_s) : (source = fragment.to_s) }
127
- source
128
- end
134
+ def gather_source(response)
135
+ source = nil
136
+ response.each { |fragment| source ? (source << fragment.to_s) : (source = fragment.to_s) }
137
+ source
138
+ end
129
139
 
130
- # Per "The Response > The Body" section of Rack spec, we should close
131
- # if our response is able. http://rack.rubyforge.org/doc/SPEC.html
132
- def close_old_response(response)
133
- if response.respond_to?(:close)
134
- response.close
140
+ # Per "The Response > The Body" section of Rack spec, we should close
141
+ # if our response is able. http://rack.rubyforge.org/doc/SPEC.html
142
+ def close_old_response(response)
143
+ response.close if response.respond_to?(:close)
135
144
  end
136
- end
137
145
 
138
- def find_body_start(beginning_of_source)
139
- beginning_of_source.index(BODY_START)
140
- end
146
+ def find_body_start(beginning_of_source)
147
+ beginning_of_source.index(BODY_START)
148
+ end
141
149
 
142
- def find_x_ua_compatible_position(beginning_of_source)
143
- match = X_UA_COMPATIBLE_RE.match(beginning_of_source)
144
- match.end(0) if match
145
- end
150
+ def find_x_ua_compatible_position(beginning_of_source)
151
+ match = X_UA_COMPATIBLE_RE.match(beginning_of_source)
152
+ match.end(0) if match
153
+ end
146
154
 
147
- def find_charset_position(beginning_of_source)
148
- match = CHARSET_RE.match(beginning_of_source)
149
- match.end(0) if match
150
- end
155
+ def find_charset_position(beginning_of_source)
156
+ match = CHARSET_RE.match(beginning_of_source)
157
+ match.end(0) if match
158
+ end
151
159
 
152
- def find_end_of_head_open(beginning_of_source)
153
- head_open = beginning_of_source.index(HEAD_START)
154
- beginning_of_source.index(GT, head_open) + 1 if head_open
160
+ def find_end_of_head_open(beginning_of_source)
161
+ head_open = beginning_of_source.index(HEAD_START)
162
+ beginning_of_source.index(GT, head_open) + 1 if head_open
163
+ end
155
164
  end
156
165
  end
157
166
  end
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  # @api public
6
6
  module NewRelic
@@ -1,10 +1,12 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'capistrano/framework'
6
+ require_relative 'helpers/send_deployment'
6
7
 
7
8
  namespace :newrelic do
9
+ include SendDeployment
8
10
  # notifies New Relic of a deployment
9
11
  desc "Record a deployment in New Relic (newrelic.com)"
10
12
  task :notice_deployment do
@@ -18,62 +20,4 @@ namespace :newrelic do
18
20
  end
19
21
  end
20
22
  end
21
-
22
- def send_deployment_notification_to_newrelic
23
- environment = fetch(:newrelic_rails_env, fetch(:rack_env, fetch(:rails_env, fetch(:stage, "production"))))
24
-
25
- require 'new_relic/cli/command'
26
-
27
- begin
28
- # allow overrides to be defined for revision, description, changelog, appname, and user
29
- rev = fetch(:newrelic_revision)
30
- description = fetch(:newrelic_desc)
31
- changelog = fetch(:newrelic_changelog)
32
- appname = fetch(:newrelic_appname)
33
- user = fetch(:newrelic_user)
34
- license_key = fetch(:newrelic_license_key)
35
-
36
- has_scm_from_plugin = respond_to?(:scm_plugin_installed?) && scm_plugin_installed?
37
- has_scm_from_config = defined?(scm) && !scm.nil? && scm != :none
38
-
39
- if has_scm_from_plugin || has_scm_from_config
40
- changelog ||= lookup_changelog
41
- rev ||= fetch(:current_revision)
42
- end
43
-
44
- new_revision = rev
45
- deploy_options = {
46
- :environment => environment,
47
- :revision => new_revision,
48
- :changelog => changelog,
49
- :description => description,
50
- :appname => appname,
51
- :user => user,
52
- :license_key => license_key
53
- }
54
-
55
- debug "Uploading deployment to New Relic"
56
- deployment = NewRelic::Cli::Deployments.new deploy_options
57
- deployment.run
58
- info "Uploaded deployment information to New Relic"
59
- rescue NewRelic::Cli::Command::CommandFailure => e
60
- info e.message
61
- rescue => e
62
- info "Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}"
63
- end
64
- end
65
-
66
- def lookup_changelog
67
- previous_revision = fetch(:previous_revision)
68
- current_revision = fetch(:current_revision)
69
- return unless current_revision && previous_revision
70
-
71
- debug "Retrieving changelog for New Relic Deployment details"
72
-
73
- if Rake::Task.task_defined?("git:check")
74
- log_command = "git --no-pager log --no-color --pretty=format:' * %an: %s' " +
75
- "--abbrev-commit --no-merges #{previous_revision}..#{current_revision}"
76
- `#{log_command}`
77
- end
78
- end
79
23
  end
@@ -1,12 +1,12 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
- make_notify_task = Proc.new do
6
- namespace :newrelic do
5
+ make_notify_task = proc do
6
+ namespace(:newrelic) do
7
7
  # on all deployments, notify New Relic
8
- desc "Record a deployment in New Relic (newrelic.com)"
9
- task :notice_deployment, :roles => :app, :except => {:no_release => true} do
8
+ desc("Record a deployment in New Relic (newrelic.com)")
9
+ task(:notice_deployment, :roles => :app, :except => {:no_release => true}) do
10
10
  rails_env = fetch(:newrelic_rails_env, fetch(:rails_env, "production"))
11
11
 
12
12
  require 'new_relic/cli/command'
@@ -36,22 +36,22 @@ make_notify_task = Proc.new do
36
36
  :license_key => license_key
37
37
  }
38
38
 
39
- logger.debug "Uploading deployment to New Relic"
40
- deployment = NewRelic::Cli::Deployments.new deploy_options
39
+ logger.debug("Uploading deployment to New Relic")
40
+ deployment = NewRelic::Cli::Deployments.new(deploy_options)
41
41
  deployment.run
42
- logger.info "Uploaded deployment information to New Relic"
42
+ logger.info("Uploaded deployment information to New Relic")
43
43
  rescue NewRelic::Cli::Command::CommandFailure => e
44
- logger.info e.message
44
+ logger.info(e.message)
45
45
  rescue Capistrano::CommandError
46
- logger.info "Unable to notify New Relic of the deployment... skipping"
46
+ logger.info("Unable to notify New Relic of the deployment... skipping")
47
47
  rescue => e
48
- logger.info "Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}"
48
+ logger.info("Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}")
49
49
  end
50
50
  end
51
51
 
52
52
  def lookup_changelog(changelog)
53
53
  if !changelog
54
- logger.debug "Getting log of changes for New Relic Deployment details"
54
+ logger.debug("Getting log of changes for New Relic Deployment details")
55
55
  from_revision = source.next_revision(current_revision)
56
56
 
57
57
  if scm == :git
@@ -69,7 +69,7 @@ make_notify_task = Proc.new do
69
69
  def lookup_rev(rev)
70
70
  if rev.nil?
71
71
  rev = source.query_revision(source.head()) do |cmd|
72
- logger.debug "executing locally: '#{cmd}'"
72
+ logger.debug("executing locally: '#{cmd}'")
73
73
  `#{cmd}`
74
74
  end
75
75
 
@@ -0,0 +1,69 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module SendDeployment
6
+ def send_deployment_notification_to_newrelic
7
+ require 'new_relic/cli/command'
8
+ debug("Uploading deployment to New Relic")
9
+ NewRelic::Cli::Deployments.new(deploy_options).run
10
+ info("Uploaded deployment information to New Relic")
11
+ rescue NewRelic::Cli::Command::CommandFailure => e
12
+ info(e.message)
13
+ rescue => e
14
+ info("Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}")
15
+ end
16
+
17
+ private
18
+
19
+ def deploy_options
20
+ {
21
+ :environment => fetch_environment,
22
+ :revision => fetch_rev,
23
+ :changelog => fetch_changelog,
24
+ :description => fetch(:newrelic_desc),
25
+ :appname => fetch(:newrelic_appname),
26
+ :user => fetch(:newrelic_user),
27
+ :license_key => fetch(:newrelic_license_key)
28
+ }
29
+ end
30
+
31
+ def fetch_changelog
32
+ has_scm? ? fetch(:newrelic_changelog) : lookup_changelog
33
+ end
34
+
35
+ def fetch_environment
36
+ fetch(:newrelic_rails_env, fetch(:rack_env, fetch(:rails_env, fetch(:stage, "production"))))
37
+ end
38
+
39
+ def fetch_rev
40
+ newrelic_rev = fetch(:newrelic_revision)
41
+ has_scm? && !newrelic_rev ? fetch(:current_revision) : newrelic_rev
42
+ end
43
+
44
+ def has_scm?
45
+ has_scm_from_plugin? || has_scm_from_config?
46
+ end
47
+
48
+ def has_scm_from_config?
49
+ defined?(scm) && !scm.nil? && scm != :none
50
+ end
51
+
52
+ def has_scm_from_plugin?
53
+ respond_to?(:scm_plugin_installed?) && scm_plugin_installed?
54
+ end
55
+
56
+ def lookup_changelog
57
+ previous_revision = fetch(:previous_revision)
58
+ current_revision = fetch(:current_revision)
59
+ return unless current_revision && previous_revision
60
+
61
+ debug("Retrieving changelog for New Relic Deployment details")
62
+
63
+ if Rake::Task.task_defined?("git:check")
64
+ log_command = "git --no-pager log --no-color --pretty=format:' * %an: %s' " +
65
+ "--abbrev-commit --no-merges #{previous_revision}..#{current_revision}"
66
+ `#{log_command}`
67
+ end
68
+ end
69
+ end