newrelic_rpm 8.15.0 → 9.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (342) hide show
  1. checksums.yaml +4 -4
  2. data/.build_ignore +26 -0
  3. data/CHANGELOG.md +538 -44
  4. data/CONTRIBUTING.md +1 -1
  5. data/Gemfile +1 -1
  6. data/README.md +11 -6
  7. data/Rakefile +9 -9
  8. data/Thorfile +1 -1
  9. data/bin/newrelic +1 -0
  10. data/bin/newrelic_cmd +1 -0
  11. data/bin/nrdebug +36 -36
  12. data/init.rb +1 -1
  13. data/lib/new_relic/agent/agent.rb +3 -16
  14. data/lib/new_relic/agent/agent_helpers/connect.rb +5 -10
  15. data/lib/new_relic/agent/agent_helpers/harvest.rb +4 -4
  16. data/lib/new_relic/agent/agent_helpers/shutdown.rb +5 -5
  17. data/lib/new_relic/agent/agent_helpers/special_startup.rb +3 -4
  18. data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +47 -39
  19. data/lib/new_relic/agent/agent_helpers/startup.rb +13 -13
  20. data/lib/new_relic/agent/agent_helpers/transmit.rb +6 -6
  21. data/lib/new_relic/agent/agent_logger.rb +9 -9
  22. data/lib/new_relic/agent/attribute_filter.rb +2 -4
  23. data/lib/new_relic/agent/attribute_pre_filtering.rb +109 -0
  24. data/lib/new_relic/agent/attribute_processing.rb +2 -2
  25. data/lib/new_relic/agent/audit_logger.rb +5 -5
  26. data/lib/new_relic/agent/autostart.rb +1 -1
  27. data/lib/new_relic/agent/commands/agent_command.rb +2 -2
  28. data/lib/new_relic/agent/commands/agent_command_router.rb +5 -4
  29. data/lib/new_relic/agent/commands/thread_profiler_session.rb +8 -8
  30. data/lib/new_relic/agent/configuration/default_source.rb +428 -586
  31. data/lib/new_relic/agent/configuration/environment_source.rb +2 -2
  32. data/lib/new_relic/agent/configuration/high_security_source.rb +3 -5
  33. data/lib/new_relic/agent/configuration/manager.rb +16 -2
  34. data/lib/new_relic/agent/configuration/security_policy_source.rb +10 -26
  35. data/lib/new_relic/agent/configuration/server_source.rb +24 -24
  36. data/lib/new_relic/agent/configuration/yaml_source.rb +17 -4
  37. data/lib/new_relic/agent/connect/request_builder.rb +1 -1
  38. data/lib/new_relic/agent/connect/response_handler.rb +1 -1
  39. data/lib/new_relic/agent/custom_event_aggregator.rb +4 -4
  40. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
  41. data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
  42. data/lib/new_relic/agent/database/obfuscator.rb +2 -2
  43. data/lib/new_relic/agent/database.rb +4 -18
  44. data/lib/new_relic/agent/datastores/metric_helper.rb +5 -5
  45. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +11 -11
  46. data/lib/new_relic/agent/datastores/redis.rb +6 -6
  47. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +8 -10
  48. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +10 -10
  49. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +7 -7
  50. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +1 -1
  51. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +6 -6
  52. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +7 -7
  53. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +4 -4
  54. data/lib/new_relic/agent/distributed_tracing.rb +6 -6
  55. data/lib/new_relic/agent/error_collector.rb +36 -8
  56. data/lib/new_relic/agent/error_filter.rb +5 -5
  57. data/lib/new_relic/agent/error_trace_aggregator.rb +5 -4
  58. data/lib/new_relic/agent/event_loop.rb +3 -3
  59. data/lib/new_relic/agent/external.rb +1 -1
  60. data/lib/new_relic/agent/harvester.rb +1 -3
  61. data/lib/new_relic/agent/heap.rb +2 -1
  62. data/lib/new_relic/agent/hostname.rb +1 -1
  63. data/lib/new_relic/agent/http_clients/abstract.rb +9 -21
  64. data/lib/new_relic/agent/http_clients/async_http_wrappers.rb +83 -0
  65. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +7 -3
  66. data/lib/new_relic/agent/http_clients/ethon_wrappers.rb +111 -0
  67. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +7 -5
  68. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +4 -0
  69. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +6 -2
  70. data/lib/new_relic/agent/http_clients/httpx_wrappers.rb +93 -0
  71. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
  72. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +8 -5
  73. data/lib/new_relic/agent/http_clients/uri_util.rb +2 -2
  74. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +6 -19
  75. data/lib/new_relic/agent/instrumentation/action_controller_other_subscriber.rb +42 -0
  76. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +3 -2
  77. data/lib/new_relic/agent/instrumentation/action_dispatch.rb +31 -0
  78. data/lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb +64 -0
  79. data/lib/new_relic/agent/instrumentation/action_mailbox.rb +30 -0
  80. data/lib/new_relic/agent/instrumentation/action_mailbox_subscriber.rb +33 -0
  81. data/lib/new_relic/agent/instrumentation/action_mailer.rb +30 -0
  82. data/lib/new_relic/agent/instrumentation/action_mailer_subscriber.rb +85 -0
  83. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +10 -10
  84. data/lib/new_relic/agent/instrumentation/active_job.rb +16 -3
  85. data/lib/new_relic/agent/instrumentation/active_job_subscriber.rb +41 -0
  86. data/lib/new_relic/agent/instrumentation/active_merchant.rb +3 -3
  87. data/lib/new_relic/agent/instrumentation/active_record.rb +4 -3
  88. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +38 -36
  89. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +5 -4
  90. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +2 -2
  91. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +3 -2
  92. data/lib/new_relic/agent/instrumentation/active_storage.rb +4 -0
  93. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +2 -30
  94. data/lib/new_relic/agent/instrumentation/active_support.rb +21 -6
  95. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/chain.rb +69 -0
  96. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/instrumentation.rb +13 -0
  97. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/prepend.rb +37 -0
  98. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger.rb +23 -0
  99. data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +4 -0
  100. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +3 -1
  101. data/lib/new_relic/agent/instrumentation/active_support_subscriber.rb +41 -0
  102. data/lib/new_relic/agent/instrumentation/async_http/chain.rb +23 -0
  103. data/lib/new_relic/agent/instrumentation/async_http/instrumentation.rb +37 -0
  104. data/lib/new_relic/agent/instrumentation/async_http/prepend.rb +15 -0
  105. data/lib/new_relic/agent/instrumentation/async_http.rb +26 -0
  106. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +1 -1
  107. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +12 -3
  108. data/lib/new_relic/agent/instrumentation/bunny.rb +1 -1
  109. data/lib/new_relic/agent/instrumentation/concurrent_ruby/chain.rb +1 -1
  110. data/lib/new_relic/agent/instrumentation/concurrent_ruby/instrumentation.rb +3 -4
  111. data/lib/new_relic/agent/instrumentation/concurrent_ruby/prepend.rb +1 -1
  112. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +7 -6
  113. data/lib/new_relic/agent/instrumentation/curb/chain.rb +1 -1
  114. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +9 -5
  115. data/lib/new_relic/agent/instrumentation/curb.rb +1 -1
  116. data/lib/new_relic/agent/instrumentation/custom_events.rb +12 -0
  117. data/lib/new_relic/agent/instrumentation/custom_events_subscriber.rb +2 -1
  118. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +1 -0
  119. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +4 -1
  120. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -1
  121. data/lib/new_relic/agent/instrumentation/elasticsearch/chain.rb +2 -2
  122. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +8 -4
  123. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +2 -2
  124. data/lib/new_relic/agent/instrumentation/ethon/chain.rb +39 -0
  125. data/lib/new_relic/agent/instrumentation/ethon/instrumentation.rb +105 -0
  126. data/lib/new_relic/agent/instrumentation/ethon/prepend.rb +35 -0
  127. data/lib/new_relic/agent/instrumentation/ethon.rb +39 -0
  128. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +5 -1
  129. data/lib/new_relic/agent/instrumentation/excon.rb +3 -3
  130. data/lib/new_relic/agent/instrumentation/fiber/chain.rb +27 -0
  131. data/lib/new_relic/agent/instrumentation/fiber/instrumentation.rb +23 -0
  132. data/lib/new_relic/agent/instrumentation/fiber/prepend.rb +25 -0
  133. data/lib/new_relic/agent/instrumentation/fiber.rb +25 -0
  134. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +8 -4
  135. data/lib/new_relic/agent/instrumentation/grape.rb +4 -4
  136. data/lib/new_relic/agent/instrumentation/grpc/client/chain.rb +1 -1
  137. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +7 -2
  138. data/lib/new_relic/agent/instrumentation/grpc/client/prepend.rb +1 -1
  139. data/lib/new_relic/agent/instrumentation/grpc/client/request_wrapper.rb +1 -1
  140. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +8 -4
  141. data/lib/new_relic/agent/instrumentation/grpc_client.rb +2 -2
  142. data/lib/new_relic/agent/instrumentation/grpc_server.rb +2 -2
  143. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +4 -0
  144. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +4 -0
  145. data/lib/new_relic/agent/instrumentation/httprb.rb +1 -1
  146. data/lib/new_relic/agent/instrumentation/httpx/chain.rb +20 -0
  147. data/lib/new_relic/agent/instrumentation/httpx/instrumentation.rb +51 -0
  148. data/lib/new_relic/agent/instrumentation/httpx/prepend.rb +15 -0
  149. data/lib/new_relic/agent/instrumentation/httpx.rb +27 -0
  150. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
  151. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +3 -0
  152. data/lib/new_relic/agent/instrumentation/logger.rb +1 -1
  153. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +3 -1
  154. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +14 -5
  155. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +3 -1
  156. data/lib/new_relic/agent/instrumentation/memcache.rb +12 -12
  157. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +3 -3
  158. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +1 -1
  159. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +6 -8
  160. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -1
  161. data/lib/new_relic/agent/instrumentation/net_http.rb +2 -2
  162. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +46 -1
  163. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +7 -3
  164. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -2
  165. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
  166. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +7 -1
  167. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +7 -2
  168. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
  169. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +4 -4
  170. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +14 -1
  171. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +12 -15
  172. data/lib/new_relic/agent/instrumentation/rake.rb +3 -3
  173. data/lib/new_relic/agent/instrumentation/redis/constants.rb +1 -1
  174. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +6 -1
  175. data/lib/new_relic/agent/instrumentation/redis.rb +1 -1
  176. data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
  177. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +4 -0
  178. data/lib/new_relic/agent/instrumentation/resque.rb +1 -1
  179. data/lib/new_relic/agent/instrumentation/roda/chain.rb +43 -0
  180. data/lib/new_relic/agent/instrumentation/roda/ignorer.rb +45 -0
  181. data/lib/new_relic/agent/instrumentation/roda/instrumentation.rb +68 -0
  182. data/lib/new_relic/agent/instrumentation/roda/prepend.rb +24 -0
  183. data/lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb +29 -0
  184. data/lib/new_relic/agent/instrumentation/roda.rb +36 -0
  185. data/lib/new_relic/agent/instrumentation/sequel.rb +8 -9
  186. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +10 -10
  187. data/lib/new_relic/agent/instrumentation/sidekiq/client.rb +4 -0
  188. data/lib/new_relic/agent/instrumentation/sidekiq/extensions/delayed_class.rb +1 -1
  189. data/lib/new_relic/agent/instrumentation/sidekiq/server.rb +26 -3
  190. data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -3
  191. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
  192. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +10 -5
  193. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +2 -4
  194. data/lib/new_relic/agent/instrumentation/stripe.rb +28 -0
  195. data/lib/new_relic/agent/instrumentation/stripe_subscriber.rb +77 -0
  196. data/lib/new_relic/agent/instrumentation/thread/chain.rb +1 -1
  197. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +3 -8
  198. data/lib/new_relic/agent/instrumentation/thread/prepend.rb +1 -1
  199. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +6 -1
  200. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +10 -6
  201. data/lib/new_relic/agent/javascript_instrumentor.rb +29 -24
  202. data/lib/new_relic/agent/linking_metadata.rb +2 -2
  203. data/lib/new_relic/agent/log_event_aggregator.rb +64 -17
  204. data/lib/new_relic/agent/log_event_attributes.rb +115 -0
  205. data/lib/new_relic/agent/logging.rb +77 -37
  206. data/lib/new_relic/agent/messaging.rb +9 -7
  207. data/lib/new_relic/agent/method_tracer.rb +7 -7
  208. data/lib/new_relic/agent/method_tracer_helpers.rb +27 -6
  209. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +4 -5
  210. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +1 -1
  211. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +12 -1
  212. data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
  213. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +2 -2
  214. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +0 -1
  215. data/lib/new_relic/agent/new_relic_service.rb +47 -32
  216. data/lib/new_relic/agent/obfuscator.rb +1 -1
  217. data/lib/new_relic/agent/parameter_filtering.rb +6 -6
  218. data/lib/new_relic/agent/pipe_channel_manager.rb +7 -6
  219. data/lib/new_relic/agent/pipe_service.rb +5 -3
  220. data/lib/new_relic/agent/priority_sampled_buffer.rb +1 -1
  221. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +0 -1
  222. data/lib/new_relic/agent/rules_engine.rb +1 -1
  223. data/lib/new_relic/agent/sampler.rb +2 -1
  224. data/lib/new_relic/agent/sampler_collection.rb +1 -1
  225. data/lib/new_relic/agent/samplers/cpu_sampler.rb +5 -5
  226. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +9 -9
  227. data/lib/new_relic/agent/samplers/memory_sampler.rb +9 -9
  228. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  229. data/lib/new_relic/agent/span_event_aggregator.rb +4 -4
  230. data/lib/new_relic/agent/span_event_primitive.rb +18 -6
  231. data/lib/new_relic/agent/sql_sampler.rb +2 -2
  232. data/lib/new_relic/agent/stats.rb +1 -1
  233. data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -1
  234. data/lib/new_relic/agent/system_info.rb +36 -10
  235. data/lib/new_relic/agent/threading/agent_thread.rb +1 -1
  236. data/lib/new_relic/agent/threading/backtrace_node.rb +3 -3
  237. data/lib/new_relic/agent/threading/backtrace_service.rb +3 -7
  238. data/lib/new_relic/agent/threading/thread_profile.rb +5 -5
  239. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
  240. data/lib/new_relic/agent/tracer.rb +25 -16
  241. data/lib/new_relic/agent/transaction/abstract_segment.rb +109 -48
  242. data/lib/new_relic/agent/transaction/datastore_segment.rb +1 -1
  243. data/lib/new_relic/agent/transaction/distributed_tracer.rb +7 -6
  244. data/lib/new_relic/agent/transaction/distributed_tracing.rb +13 -14
  245. data/lib/new_relic/agent/transaction/external_request_segment.rb +16 -13
  246. data/lib/new_relic/agent/transaction/message_broker_segment.rb +2 -3
  247. data/lib/new_relic/agent/transaction/request_attributes.rb +47 -11
  248. data/lib/new_relic/agent/transaction/segment.rb +1 -1
  249. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  250. data/lib/new_relic/agent/transaction/trace.rb +1 -1
  251. data/lib/new_relic/agent/transaction/trace_context.rb +4 -4
  252. data/lib/new_relic/agent/transaction/trace_node.rb +8 -7
  253. data/lib/new_relic/agent/transaction/tracing.rb +10 -4
  254. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
  255. data/lib/new_relic/agent/transaction.rb +90 -58
  256. data/lib/new_relic/agent/transaction_error_primitive.rb +21 -5
  257. data/lib/new_relic/agent/transaction_event_aggregator.rb +4 -4
  258. data/lib/new_relic/agent/transaction_event_primitive.rb +22 -3
  259. data/lib/new_relic/agent/transaction_sampler.rb +3 -3
  260. data/lib/new_relic/agent/transaction_time_aggregator.rb +7 -3
  261. data/lib/new_relic/agent/utilization/aws.rb +1 -1
  262. data/lib/new_relic/agent/utilization/azure.rb +3 -3
  263. data/lib/new_relic/agent/utilization/gcp.rb +4 -6
  264. data/lib/new_relic/agent/utilization/pcf.rb +1 -1
  265. data/lib/new_relic/agent/utilization/vendor.rb +6 -8
  266. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  267. data/lib/new_relic/agent/vm/mri_vm.rb +9 -8
  268. data/lib/new_relic/agent/worker_loop.rb +1 -1
  269. data/lib/new_relic/agent.rb +133 -36
  270. data/lib/new_relic/cli/command.rb +4 -3
  271. data/lib/new_relic/cli/commands/deployments.rb +26 -25
  272. data/lib/new_relic/cli/commands/install.rb +23 -23
  273. data/lib/new_relic/collection_helper.rb +2 -2
  274. data/lib/new_relic/constants.rb +10 -8
  275. data/lib/new_relic/control/class_methods.rb +4 -10
  276. data/lib/new_relic/control/frameworks/rails.rb +44 -20
  277. data/lib/new_relic/control/frameworks/roda.rb +20 -0
  278. data/lib/new_relic/control/instance_methods.rb +6 -6
  279. data/lib/new_relic/control/instrumentation.rb +1 -15
  280. data/lib/new_relic/control/private_instance_methods.rb +1 -1
  281. data/lib/new_relic/dependency_detection.rb +20 -18
  282. data/lib/new_relic/environment_report.rb +4 -4
  283. data/lib/new_relic/helper.rb +2 -1
  284. data/lib/new_relic/language_support.rb +10 -1
  285. data/lib/new_relic/latest_changes.rb +6 -6
  286. data/lib/new_relic/local_environment.rb +0 -10
  287. data/lib/new_relic/noticed_error.rb +25 -20
  288. data/lib/new_relic/rack/agent_hooks.rb +1 -1
  289. data/lib/new_relic/rack/agent_middleware.rb +0 -16
  290. data/lib/new_relic/rack/browser_monitoring.rb +21 -17
  291. data/lib/new_relic/recipes/capistrano3.rb +1 -1
  292. data/lib/new_relic/recipes/capistrano_legacy.rb +6 -6
  293. data/lib/new_relic/recipes/helpers/send_deployment.rb +5 -5
  294. data/lib/new_relic/supportability_helper.rb +4 -1
  295. data/lib/new_relic/traced_thread.rb +2 -3
  296. data/lib/new_relic/version.rb +2 -2
  297. data/lib/newrelic_rpm.rb +4 -4
  298. data/lib/sequel/extensions/{newrelic_instrumentation.rb → new_relic_instrumentation.rb} +6 -6
  299. data/lib/sequel/plugins/{newrelic_instrumentation.rb → new_relic_instrumentation.rb} +4 -4
  300. data/lib/tasks/bump_version.rake +21 -0
  301. data/lib/tasks/config.rake +13 -12
  302. data/lib/tasks/coverage_report.rake +4 -4
  303. data/lib/tasks/helpers/config.html.erb +93 -0
  304. data/lib/tasks/helpers/format.rb +19 -15
  305. data/lib/tasks/helpers/newrelicyml.rb +144 -0
  306. data/lib/tasks/helpers/version_bump.rb +62 -0
  307. data/lib/tasks/install.rake +4 -4
  308. data/lib/tasks/instrumentation_generator/instrumentation.thor +16 -19
  309. data/lib/tasks/instrumentation_generator/templates/Envfile.tt +1 -1
  310. data/lib/tasks/instrumentation_generator/templates/chain.tt +1 -1
  311. data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +1 -1
  312. data/lib/tasks/newrelic.rb +1 -0
  313. data/lib/tasks/newrelicyml.rake +13 -0
  314. data/lib/tasks/tests.rake +77 -6
  315. data/newrelic.yml +393 -274
  316. data/newrelic_rpm.gemspec +41 -30
  317. data/test/agent_helper.rb +25 -24
  318. metadata +172 -35
  319. data/.gitignore +0 -42
  320. data/.project +0 -23
  321. data/.rubocop.yml +0 -1946
  322. data/.rubocop_todo.yml +0 -62
  323. data/.simplecov +0 -15
  324. data/.snyk +0 -11
  325. data/.yardopts +0 -27
  326. data/Brewfile +0 -12
  327. data/DOCKER.md +0 -167
  328. data/Dockerfile +0 -10
  329. data/Guardfile +0 -26
  330. data/config/database.yml +0 -5
  331. data/config.dot +0 -278
  332. data/docker-compose.yml +0 -107
  333. data/lefthook.yml +0 -9
  334. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +0 -83
  335. data/lib/new_relic/agent/instrumentation/authlogic.rb +0 -33
  336. data/lib/new_relic/agent/instrumentation/data_mapper.rb +0 -215
  337. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +0 -36
  338. data/lib/new_relic/agent/instrumentation/sunspot.rb +0 -41
  339. data/lib/new_relic/agent/range_extensions.rb +0 -27
  340. data/lib/tasks/helpers/removers.rb +0 -33
  341. data/lib/tasks/multiverse.rake +0 -6
  342. data/lib/tasks/multiverse.rb +0 -77
@@ -9,16 +9,16 @@ module NewRelic
9
9
 
10
10
  # Intrinsic Keys
11
11
  INTRINSIC_KEYS = [
12
- PARENT_TYPE_KEY = "parent.type",
13
- PARENT_APP_KEY = "parent.app",
14
- PARENT_ACCOUNT_ID_KEY = "parent.account",
15
- PARENT_TRANSPORT_TYPE_KEY = "parent.transportType",
16
- PARENT_TRANSPORT_DURATION_KEY = "parent.transportDuration",
17
- GUID_KEY = "guid",
18
- TRACE_ID_KEY = "traceId",
19
- PARENT_TRANSACTION_ID_KEY = "parentId",
20
- PARENT_SPAN_ID_KEY = "parentSpanId",
21
- SAMPLED_KEY = "sampled"
12
+ PARENT_TYPE_KEY = 'parent.type',
13
+ PARENT_APP_KEY = 'parent.app',
14
+ PARENT_ACCOUNT_ID_KEY = 'parent.account',
15
+ PARENT_TRANSPORT_TYPE_KEY = 'parent.transportType',
16
+ PARENT_TRANSPORT_DURATION_KEY = 'parent.transportDuration',
17
+ GUID_KEY = 'guid',
18
+ TRACE_ID_KEY = 'traceId',
19
+ PARENT_TRANSACTION_ID_KEY = 'parentId',
20
+ PARENT_SPAN_ID_KEY = 'parentSpanId',
21
+ SAMPLED_KEY = 'sampled'
22
22
  ].freeze
23
23
 
24
24
  # This method extracts intrinsics from the transaction_payload and
@@ -7,11 +7,11 @@ module NewRelic
7
7
  module DistributedTraceMetrics
8
8
  extend self
9
9
 
10
- ALL_SUFFIX = "all"
11
- ALL_WEB_SUFFIX = "allWeb"
12
- ALL_OTHER_SUFFIX = "allOther"
10
+ ALL_SUFFIX = 'all'
11
+ ALL_WEB_SUFFIX = 'allWeb'
12
+ ALL_OTHER_SUFFIX = 'allOther'
13
13
 
14
- UNKNOWN_CALLER_PREFIX = "%s/Unknown/Unknown/Unknown/%s"
14
+ UNKNOWN_CALLER_PREFIX = '%s/Unknown/Unknown/Unknown/%s'
15
15
 
16
16
  def transaction_type_suffix
17
17
  if Transaction.recording_web_transaction?
@@ -45,14 +45,14 @@ module NewRelic
45
45
  end
46
46
 
47
47
  def record_caller_by_duration_metrics(transaction, payload)
48
- prefix = prefix_for_metric("DurationByCaller", transaction, payload)
48
+ prefix = prefix_for_metric('DurationByCaller', transaction, payload)
49
49
  record_unscoped_metric(transaction, prefix, transaction.duration)
50
50
  end
51
51
 
52
52
  def record_transport_duration_metrics(transaction, payload)
53
53
  return unless payload
54
54
 
55
- prefix = prefix_for_metric("TransportDuration", transaction, payload)
55
+ prefix = prefix_for_metric('TransportDuration', transaction, payload)
56
56
  duration = transaction.calculate_transport_duration(payload)
57
57
  record_unscoped_metric(transaction, prefix, duration)
58
58
  end
@@ -60,7 +60,7 @@ module NewRelic
60
60
  def record_errors_by_caller_metrics(transaction, payload)
61
61
  return unless transaction.exceptions.size > 0
62
62
 
63
- prefix = prefix_for_metric("ErrorsByCaller", transaction, payload)
63
+ prefix = prefix_for_metric('ErrorsByCaller', transaction, payload)
64
64
  record_unscoped_metric(transaction, prefix, 1)
65
65
  end
66
66
 
@@ -17,7 +17,7 @@ module NewRelic
17
17
  extend Coerce
18
18
 
19
19
  VERSION = [0, 1].freeze
20
- PARENT_TYPE = "App"
20
+ PARENT_TYPE = 'App'
21
21
 
22
22
  # Key names for serialization
23
23
  VERSION_KEY = 'v'
@@ -11,12 +11,12 @@ module NewRelic
11
11
  NewRelic::UNKNOWN,
12
12
  NewRelic::HTTP,
13
13
  NewRelic::HTTPS,
14
- "Kafka",
15
- "JMS",
16
- "IronMQ",
17
- "AMQP",
18
- "Queue",
19
- "Other"
14
+ 'Kafka',
15
+ 'JMS',
16
+ 'IronMQ',
17
+ 'AMQP',
18
+ 'Queue',
19
+ 'Other'
20
20
  ].freeze
21
21
 
22
22
  URL_SCHEMES = {
@@ -29,14 +29,14 @@ module NewRelic
29
29
  TP_UNDEFINED_FIELDS = "(?<#{UNDEFINED_FIELDS_KEY}>-[a-zA-Z\\d-]*)"
30
30
  TRACE_PARENT_REGEX = /\A#{TP_VERSION}-#{TP_TRACE_ID}-#{TP_PARENT_ID}-#{TP_TRACE_FLAGS}#{TP_UNDEFINED_FIELDS}?\z/
31
31
 
32
- TRACE_PARENT_FORMAT_STRING = "%02x-%s-%s-%02x"
32
+ TRACE_PARENT_FORMAT_STRING = '%02x-%s-%s-%02x'
33
33
 
34
34
  MAX_TRACE_STATE_SIZE = 512 # bytes
35
35
  MAX_TRACE_STATE_ENTRY_SIZE = 128 # bytes
36
36
 
37
- SUPPORTABILITY_TRACE_PARENT_PARSE_EXCEPTION = "Supportability/TraceContext/TraceParent/Parse/Exception"
38
- SUPPORTABILITY_TRACE_STATE_PARSE_EXCEPTION = "Supportability/TraceContext/TraceState/Parse/Exception"
39
- SUPPORTABILITY_TRACE_STATE_INVALID_NR_ENTRY = "Supportability/TraceContext/TraceState/InvalidNrEntry"
37
+ SUPPORTABILITY_TRACE_PARENT_PARSE_EXCEPTION = 'Supportability/TraceContext/TraceParent/Parse/Exception'
38
+ SUPPORTABILITY_TRACE_STATE_PARSE_EXCEPTION = 'Supportability/TraceContext/TraceState/Parse/Exception'
39
+ SUPPORTABILITY_TRACE_STATE_INVALID_NR_ENTRY = 'Supportability/TraceContext/TraceState/InvalidNrEntry'
40
40
 
41
41
  class << self
42
42
  def insert(format: NewRelic::FORMAT_NON_RACK,
@@ -78,7 +78,7 @@ module NewRelic
78
78
  end
79
79
 
80
80
  def create_trace_state_entry(entry_key, payload)
81
- "#{entry_key}=#{payload}".dup
81
+ +"#{entry_key}=#{payload}"
82
82
  end
83
83
 
84
84
  private
@@ -138,7 +138,7 @@ module NewRelic
138
138
 
139
139
  payload = nil
140
140
  trace_state_size = 0
141
- trace_state_vendors = String.new
141
+ trace_state_vendors = +''
142
142
  trace_state = header.split(COMMA).map(&:strip)
143
143
  trace_state.reject! do |entry|
144
144
  if entry == NewRelic::EMPTY_STR
@@ -223,7 +223,7 @@ module NewRelic
223
223
  max_size = MAX_TRACE_STATE_SIZE - trace_state_entry_size
224
224
  return @trace_state_entries.join(COMMA).prepend(COMMA) if @trace_state_size < max_size
225
225
 
226
- joined_trace_state = ''.dup
226
+ joined_trace_state = +''
227
227
 
228
228
  used_size = 0
229
229
 
@@ -9,8 +9,8 @@ module NewRelic
9
9
  class TraceContextPayload
10
10
  VERSION = 0
11
11
  PARENT_TYPE = 0
12
- DELIMITER = "-".freeze
13
- SUPPORTABILITY_PARSE_EXCEPTION = "Supportability/TraceContext/Parse/Exception".freeze
12
+ DELIMITER = '-'.freeze
13
+ SUPPORTABILITY_PARSE_EXCEPTION = 'Supportability/TraceContext/Parse/Exception'.freeze
14
14
 
15
15
  TRUE_CHAR = '1'.freeze
16
16
  FALSE_CHAR = '0'.freeze
@@ -64,7 +64,7 @@ module NewRelic
64
64
  def handle_invalid_payload(error: nil, message: nil)
65
65
  NewRelic::Agent.increment_metric(SUPPORTABILITY_PARSE_EXCEPTION)
66
66
  if error
67
- NewRelic::Agent.logger.warn("Error parsing trace context payload", error)
67
+ NewRelic::Agent.logger.warn('Error parsing trace context payload', error)
68
68
  elsif message
69
69
  NewRelic::Agent.logger.warn("Error parsing trace context payload: #{message}")
70
70
  end
@@ -118,7 +118,7 @@ module NewRelic
118
118
  result << DELIMITER << (id || NewRelic::EMPTY_STR)
119
119
  result << DELIMITER << (transaction_id || NewRelic::EMPTY_STR)
120
120
  result << DELIMITER << (sampled ? TRUE_CHAR : FALSE_CHAR)
121
- result << DELIMITER << sprintf("%.6f", priority)
121
+ result << DELIMITER << sprintf('%.6f', priority)
122
122
  result << DELIMITER << timestamp.to_s # required
123
123
  result
124
124
  end
@@ -45,11 +45,11 @@ module NewRelic
45
45
  record_api_supportability_metric(:insert_distributed_trace_headers)
46
46
 
47
47
  unless Agent.config[:'distributed_tracing.enabled']
48
- NewRelic::Agent.logger.warn("Not configured to insert distributed trace headers")
48
+ NewRelic::Agent.logger.warn('Not configured to insert distributed trace headers')
49
49
  return nil
50
50
  end
51
51
 
52
- return unless valid_api_argument_class?(headers, "headers", Hash)
52
+ return unless valid_api_argument_class?(headers, 'headers', Hash)
53
53
 
54
54
  return unless transaction = Transaction.tl_current
55
55
 
@@ -87,7 +87,7 @@ module NewRelic
87
87
  # header-friendly string returned from
88
88
  # {DistributedTracePayload#http_safe}
89
89
  #
90
- # @param transport_Type [String] May be one of: +HTTP+, +HTTPS+, +Kafka+, +JMS+,
90
+ # @param transport_type [String] May be one of: +HTTP+, +HTTPS+, +Kafka+, +JMS+,
91
91
  # +IronMQ+, +AMQP+, +Queue+, +Other+. Values are
92
92
  # case sensitive. All other values result in +Unknown+
93
93
  #
@@ -99,12 +99,12 @@ module NewRelic
99
99
  record_api_supportability_metric(:accept_distributed_trace_headers)
100
100
 
101
101
  unless Agent.config[:'distributed_tracing.enabled']
102
- NewRelic::Agent.logger.warn("Not configured to accept distributed trace headers")
102
+ NewRelic::Agent.logger.warn('Not configured to accept distributed trace headers')
103
103
  return nil
104
104
  end
105
105
 
106
- return unless valid_api_argument_class?(headers, "headers", Hash)
107
- return unless valid_api_argument_class?(transport_type, "transport_type", String)
106
+ return unless valid_api_argument_class?(headers, 'headers', Hash)
107
+ return unless valid_api_argument_class?(transport_type, 'transport_type', String)
108
108
 
109
109
  return unless transaction = Transaction.tl_current
110
110
 
@@ -26,7 +26,7 @@ module NewRelic
26
26
  @error_filter = NewRelic::Agent::ErrorFilter.new
27
27
 
28
28
  %w[
29
- ignore_errors ignore_classes ignore_messages ignore_status_codes
29
+ ignore_classes ignore_messages ignore_status_codes
30
30
  expected_classes expected_messages expected_status_codes
31
31
  ].each do |w|
32
32
  Agent.config.register_callback(:"error_collector.#{w}") do |value|
@@ -156,13 +156,13 @@ module NewRelic
156
156
  end
157
157
 
158
158
  def aggregated_metric_names(txn)
159
- metric_names = ["Errors/all"]
159
+ metric_names = ['Errors/all']
160
160
  return metric_names unless txn
161
161
 
162
162
  if txn.recording_web_transaction?
163
- metric_names << "Errors/allWeb"
163
+ metric_names << 'Errors/allWeb'
164
164
  else
165
- metric_names << "Errors/allOther"
165
+ metric_names << 'Errors/allOther'
166
166
  end
167
167
 
168
168
  metric_names
@@ -227,7 +227,7 @@ module NewRelic
227
227
  def notice_error(exception, options = {}, span_id = nil)
228
228
  state = ::NewRelic::Agent::Tracer.state
229
229
  transaction = state.current_transaction
230
- status_code = transaction ? transaction.http_response_code : nil
230
+ status_code = transaction&.http_response_code
231
231
 
232
232
  return if skip_notice_error?(exception, status_code)
233
233
 
@@ -242,8 +242,8 @@ module NewRelic
242
242
  noticed_error = create_noticed_error(exception, options)
243
243
  error_trace_aggregator.add_to_error_queue(noticed_error)
244
244
  transaction = state.current_transaction
245
- payload = transaction ? transaction.payload : nil
246
- span_id ||= transaction && transaction.current_segment ? transaction.current_segment.guid : nil
245
+ payload = transaction&.payload
246
+ span_id ||= transaction&.current_segment ? transaction.current_segment.guid : nil
247
247
  error_event_aggregator.record(noticed_error, payload, span_id)
248
248
  exception
249
249
  rescue => e
@@ -277,7 +277,7 @@ module NewRelic
277
277
  noticed_error.line_number = sense_method(exception, :line_number)
278
278
  noticed_error.stack_trace = truncate_trace(extract_stack_trace(exception))
279
279
 
280
- noticed_error.expected = !!options.delete(:expected) || expected?(exception)
280
+ noticed_error.expected = !!options.delete(:expected) || expected?(exception) # rubocop:disable Style/DoubleNegation
281
281
 
282
282
  noticed_error.attributes_from_notice_error = options.delete(:custom_params) || {}
283
283
 
@@ -285,6 +285,8 @@ module NewRelic
285
285
  # get treated as custom attributes, so merge them into that hash.
286
286
  noticed_error.attributes_from_notice_error.merge!(options)
287
287
 
288
+ update_error_group_name(noticed_error, exception, options)
289
+
288
290
  noticed_error
289
291
  end
290
292
 
@@ -306,6 +308,32 @@ module NewRelic
306
308
  @error_event_aggregator.reset!
307
309
  nil
308
310
  end
311
+
312
+ private
313
+
314
+ def update_error_group_name(noticed_error, exception, options)
315
+ return unless error_group_callback
316
+
317
+ callback_hash = build_customer_callback_hash(noticed_error, exception, options)
318
+ result = error_group_callback.call(callback_hash)
319
+ noticed_error.error_group = result
320
+ rescue StandardError => e
321
+ NewRelic::Agent.logger.error("Failed to obtain error group from customer callback: #{e.class} - #{e.message}")
322
+ end
323
+
324
+ def build_customer_callback_hash(noticed_error, exception, options)
325
+ {error: exception,
326
+ customAttributes: noticed_error.custom_attributes,
327
+ 'request.uri': noticed_error.request_uri,
328
+ 'http.statusCode': noticed_error.agent_attributes[:'http.statusCode'],
329
+ 'http.method': noticed_error.intrinsic_attributes[:'http.method'],
330
+ 'error.expected': noticed_error.expected,
331
+ options: options}
332
+ end
333
+
334
+ def error_group_callback
335
+ NewRelic::Agent.error_group_callback
336
+ end
309
337
  end
310
338
  end
311
339
  end
@@ -19,7 +19,7 @@ module NewRelic
19
19
 
20
20
  def load_all
21
21
  %i[
22
- ignore_errors ignore_classes ignore_messages ignore_status_codes
22
+ ignore_classes ignore_messages ignore_status_codes
23
23
  expected_classes expected_messages expected_status_codes
24
24
  ].each { |setting| load_from_config(setting) }
25
25
  end
@@ -31,7 +31,7 @@ module NewRelic
31
31
  return if new_value.nil? || (new_value.respond_to?(:empty?) && new_value.empty?)
32
32
 
33
33
  case setting.to_sym
34
- when :ignore_errors, :ignore_classes
34
+ when :ignore_classes
35
35
  new_value = new_value.split(',').map!(&:strip) if new_value.is_a?(String)
36
36
  errors = @ignore_classes = new_value
37
37
  when :ignore_messages
@@ -80,7 +80,7 @@ module NewRelic
80
80
  @ignore_messages.update(errors)
81
81
  log_filter(:ignore_messages, errors)
82
82
  when String
83
- if errors =~ /^[\d\,\-]+$/
83
+ if /^[\d\,\-]+$/.match?(errors)
84
84
  @ignore_status_codes |= parse_status_codes(errors)
85
85
  log_filter(:ignore_status_codes, errors)
86
86
  else
@@ -104,7 +104,7 @@ module NewRelic
104
104
  @expected_messages.update(errors)
105
105
  log_filter(:expected_messages, errors)
106
106
  when String
107
- if errors =~ /^[\d\,\-]+$/
107
+ if /^[\d\,\-]+$/.match?(errors)
108
108
  @expected_status_codes |= parse_status_codes(errors)
109
109
  log_filter(:expected_status_codes, errors)
110
110
  else
@@ -120,7 +120,7 @@ module NewRelic
120
120
 
121
121
  def log_filter(setting, errors)
122
122
  case setting
123
- when :ignore_errors, :ignore_classes
123
+ when :ignore_classes
124
124
  errors.each do |error|
125
125
  ::NewRelic::Agent.logger.debug("Ignoring errors of type '#{error}'")
126
126
  end
@@ -81,13 +81,14 @@ module NewRelic
81
81
  # Already seen this class once? Bail!
82
82
  return if @errors.any? { |err| err.exception_class_name == exception.class.name }
83
83
 
84
- trace = exception.backtrace || caller.dup
85
- noticed_error = NewRelic::NoticedError.new("NewRelic/AgentError", exception)
86
- noticed_error.stack_trace = trace
84
+ noticed_error = NewRelic::Agent.instance.error_collector.create_noticed_error(exception,
85
+ {metric: 'NewRelic/AgentError'})
86
+ noticed_error.stack_trace = caller.dup unless exception.backtrace
87
+
87
88
  @errors << noticed_error
88
89
  end
89
90
  rescue => e
90
- NewRelic::Agent.logger.info("Unable to capture internal agent error due to an exception:", e)
91
+ NewRelic::Agent.logger.info('Unable to capture internal agent error due to an exception:', e)
91
92
  end
92
93
 
93
94
  def register_config_callbacks
@@ -96,7 +96,7 @@ module NewRelic
96
96
  end
97
97
 
98
98
  def run
99
- ::NewRelic::Agent.logger.debug("Running event loop")
99
+ ::NewRelic::Agent.logger.debug('Running event loop')
100
100
  while !stopped?
101
101
  run_once
102
102
  end
@@ -161,7 +161,7 @@ module NewRelic
161
161
  end
162
162
 
163
163
  def reschedule_timer_for_event(e)
164
- @timers[e].reschedule if @timers[e]
164
+ @timers[e]&.reschedule
165
165
  end
166
166
 
167
167
  def on(event, &blk)
@@ -187,7 +187,7 @@ module NewRelic
187
187
  begin
188
188
  @self_pipe_wr.write_nonblock('.')
189
189
  rescue Errno::EAGAIN
190
- ::NewRelic::Agent.logger.debug("Failed to wakeup event loop")
190
+ ::NewRelic::Agent.logger.debug('Failed to wakeup event loop')
191
191
  end
192
192
  end
193
193
  end
@@ -97,7 +97,7 @@ module NewRelic
97
97
  obfuscator.obfuscate(::JSON.dump(rmd))
98
98
  end
99
99
  rescue => e
100
- NewRelic::Agent.logger.error("error during get_response_metadata", e)
100
+ NewRelic::Agent.logger.error('error during get_response_metadata', e)
101
101
  end
102
102
 
103
103
  private
@@ -14,9 +14,7 @@ module NewRelic
14
14
  @starting_pid = nil
15
15
  @after_forker = after_forker
16
16
 
17
- if events
18
- events.subscribe(:start_transaction, &method(:on_transaction))
19
- end
17
+ events&.subscribe(:start_transaction, &method(:on_transaction))
20
18
  end
21
19
 
22
20
  def on_transaction(*_)
@@ -26,7 +26,8 @@ module NewRelic
26
26
  def initialize(items = nil, &priority_fn)
27
27
  @items = []
28
28
  @priority_fn = priority_fn || ->(x) { x }
29
- items.each { |item| push(item) } if items
29
+ # the following line needs else branch coverage
30
+ items.each { |item| push(item) } if items # rubocop:disable Style/SafeNavigation
30
31
  end
31
32
 
32
33
  def [](index)
@@ -39,7 +39,7 @@ module NewRelic
39
39
 
40
40
  def self.heroku_dyno_name_prefix(dyno_name)
41
41
  get_dyno_prefixes.find do |dyno_prefix|
42
- dyno_name.start_with?(dyno_prefix + ".")
42
+ dyno_name.start_with?(dyno_prefix + '.')
43
43
  end
44
44
  end
45
45
 
@@ -5,8 +5,8 @@
5
5
  module NewRelic
6
6
  module Agent
7
7
  module HTTPClients
8
- MUST_IMPLEMENT_ERROR = "Subclasses of %s must implement a :%s method"
9
- WHINY_NIL_ERROR = "%s cannot initialize with a nil wrapped_response object."
8
+ MUST_IMPLEMENT_ERROR = 'Subclasses of %s must implement a :%s method'
9
+ WHINY_NIL_ERROR = '%s cannot initialize with a nil wrapped_response object.'
10
10
 
11
11
  # This class provides a public interface for wrapping HTTP requests. This
12
12
  # may be used to create wrappers that are compatible with New Relic's
@@ -14,28 +14,16 @@ module NewRelic
14
14
  #
15
15
  # @api public
16
16
  class AbstractRequest
17
- def []
18
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
19
- end
20
-
21
- def []=
22
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
23
- end
24
-
25
- def type
26
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
27
- end
28
-
29
- def host_from_header
30
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
17
+ %i[[] []= type host_from_header host method headers uri].each do |name|
18
+ define_method(name) do
19
+ not_implemented(name)
20
+ end
31
21
  end
32
22
 
33
- def host
34
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
35
- end
23
+ private
36
24
 
37
- def method
38
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
25
+ def not_implemented(method_name)
26
+ raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, method_name]
39
27
  end
40
28
  end
41
29
 
@@ -0,0 +1,83 @@
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
+ require_relative 'abstract'
6
+ require 'resolv'
7
+
8
+ module NewRelic
9
+ module Agent
10
+ module HTTPClients
11
+ class AsyncHTTPResponse < AbstractResponse
12
+ def get_status_code
13
+ get_status_code_using(:status)
14
+ end
15
+
16
+ def [](key)
17
+ to_hash[key.downcase]&.first
18
+ end
19
+
20
+ def to_hash
21
+ @wrapped_response.headers.to_h
22
+ end
23
+ end
24
+
25
+ class AsyncHTTPRequest < AbstractRequest
26
+ def initialize(connection, method, url, headers)
27
+ @connection = connection
28
+ @method = method
29
+ @url = ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(url)
30
+ @headers = headers
31
+ end
32
+
33
+ ASYNC_HTTP = 'Async::HTTP'
34
+ LHOST = 'host'
35
+ UHOST = 'Host'
36
+ COLON = ':'
37
+
38
+ def type
39
+ ASYNC_HTTP
40
+ end
41
+
42
+ def host_from_header
43
+ if hostname = (self[LHOST] || self[UHOST])
44
+ hostname.split(COLON).first
45
+ end
46
+ end
47
+
48
+ def host
49
+ host_from_header || uri.host.to_s
50
+ end
51
+
52
+ def [](key)
53
+ return headers[key] unless headers.is_a?(Array)
54
+
55
+ headers.each do |header|
56
+ return header[1] if header[0].casecmp?(key)
57
+ end
58
+ nil
59
+ end
60
+
61
+ def []=(key, value)
62
+ if headers.is_a?(Array)
63
+ headers << [key, value]
64
+ else
65
+ headers[key] = value
66
+ end
67
+ end
68
+
69
+ def uri
70
+ @url
71
+ end
72
+
73
+ def headers
74
+ @headers
75
+ end
76
+
77
+ def method
78
+ @method
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -33,16 +33,20 @@ module NewRelic
33
33
  end
34
34
 
35
35
  def [](key)
36
- @curlobj.headers[key]
36
+ headers[key]
37
37
  end
38
38
 
39
39
  def []=(key, value)
40
- @curlobj.headers[key] = value
40
+ headers[key] = value
41
41
  end
42
42
 
43
43
  def uri
44
44
  @uri ||= URIUtil.parse_and_normalize_url(@curlobj.url)
45
45
  end
46
+
47
+ def headers
48
+ @curlobj.headers
49
+ end
46
50
  end
47
51
 
48
52
  class CurbResponse < AbstractResponse
@@ -62,7 +66,7 @@ module NewRelic
62
66
  def append_header_data(data)
63
67
  key, value = data.split(/:\s*/, 2)
64
68
  @headers[key.downcase] = value
65
- @wrapped_response._nr_header_str ||= String.new
69
+ @wrapped_response._nr_header_str ||= +''
66
70
  @wrapped_response._nr_header_str << data
67
71
  end
68
72