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
@@ -10,6 +10,9 @@ module NewRelic
10
10
  # Rails specific configuration, instrumentation, environment values,
11
11
  # etc.
12
12
  class Rails < NewRelic::Control::Frameworks::Ruby
13
+ BROWSER_MONITORING_INSTALLED_SINGLETON = NewRelic::Agent.config
14
+ BROWSER_MONITORING_INSTALLED_VARIABLE = :@browser_monitoring_installed
15
+
13
16
  def env
14
17
  @env ||= (ENV['NEW_RELIC_ENV'] || RAILS_ENV.dup)
15
18
  end
@@ -44,26 +47,38 @@ module NewRelic
44
47
  # find a config and use that.
45
48
  def init_config(options = {})
46
49
  @config = options[:config]
47
- # Install the dependency detection,
48
- if rails_config && ::Rails.configuration.respond_to?(:after_initialize)
49
- rails_config.after_initialize do
50
- # This will insure we load all the instrumentation as late as possible. If the agent
51
- # is not enabled, it will load a limited amount of instrumentation.
52
- DependencyDetection.detect!
53
- end
50
+ install_dependency_detection
51
+ install_browser_monitoring_and_agent_hooks
52
+ rescue => e
53
+ ::NewRelic::Agent.logger.error('Failure during init_config for Rails. Is Rails required in a non-Rails ' \
54
+ 'app? Set NEW_RELIC_FRAMEWORK=ruby to avoid this message. The Ruby agent ' \
55
+ 'will continue running, but Rails-specific features may be missing. ' \
56
+ "#{e.class} - #{e.message}")
57
+ end
58
+
59
+ def install_dependency_detection
60
+ return unless rails_config && ::Rails.configuration.respond_to?(:after_initialize)
61
+
62
+ rails_config.after_initialize do
63
+ # This will insure we load all the instrumentation as late as
64
+ # possible. If the agent is not enabled, it will load a limited
65
+ # amount of instrumentation.
66
+ DependencyDetection.detect!
54
67
  end
68
+ end
69
+
70
+ def install_browser_monitoring_and_agent_hooks
71
+ return unless rails_config
72
+
55
73
  if !Agent.config[:agent_enabled]
56
- # Might not be running if it does not think mongrel, thin, passenger, etc
57
- # is running, if it thinks it's a rake task, or if the agent_enabled is false.
58
- ::NewRelic::Agent.logger.info("New Relic Agent not running.")
74
+ # Might not be running if it does not think mongrel, thin,
75
+ # passenger, etc. is running, if it thinks it's a rake task, or
76
+ # if the agent_enabled is false.
77
+ ::NewRelic::Agent.logger.info('New Relic Agent not running. Skipping browser monitoring and agent hooks.')
59
78
  else
60
79
  install_browser_monitoring(rails_config)
61
80
  install_agent_hooks(rails_config)
62
81
  end
63
- rescue => e
64
- ::NewRelic::Agent.logger.error("Failure during init_config for Rails. Is Rails required in a non-Rails app? Set NEW_RELIC_FRAMEWORK=ruby to avoid this message.",
65
- "The Ruby agent will continue running, but Rails-specific features may be missing.",
66
- e)
67
82
  end
68
83
 
69
84
  def install_agent_hooks(config)
@@ -77,29 +92,38 @@ module NewRelic
77
92
  return unless NewRelic::Rack::AgentHooks.needed?
78
93
 
79
94
  config.middleware.use(NewRelic::Rack::AgentHooks)
80
- ::NewRelic::Agent.logger.debug("Installed New Relic Agent Hooks middleware")
95
+ ::NewRelic::Agent.logger.debug('Installed New Relic Agent Hooks middleware')
81
96
  rescue => e
82
- ::NewRelic::Agent.logger.warn("Error installing New Relic Agent Hooks middleware", e)
97
+ ::NewRelic::Agent.logger.warn('Error installing New Relic Agent Hooks middleware', e)
83
98
  end
84
99
  end
85
100
 
86
101
  def install_browser_monitoring(config)
87
102
  @install_lock.synchronize do
88
- return if defined?(@browser_monitoring_installed) && @browser_monitoring_installed
103
+ return if browser_agent_already_installed?
89
104
 
90
- @browser_monitoring_installed = true
105
+ mark_browser_agent_as_installed
91
106
  return if config.nil? || !config.respond_to?(:middleware) || !Agent.config[:'browser_monitoring.auto_instrument']
92
107
 
93
108
  begin
94
109
  require 'new_relic/rack/browser_monitoring'
95
110
  config.middleware.use(NewRelic::Rack::BrowserMonitoring)
96
- ::NewRelic::Agent.logger.debug("Installed New Relic Browser Monitoring middleware")
111
+ ::NewRelic::Agent.logger.debug('Installed New Relic Browser Monitoring middleware')
97
112
  rescue => e
98
- ::NewRelic::Agent.logger.warn("Error installing New Relic Browser Monitoring middleware", e)
113
+ ::NewRelic::Agent.logger.warn('Error installing New Relic Browser Monitoring middleware', e)
99
114
  end
100
115
  end
101
116
  end
102
117
 
118
+ def browser_agent_already_installed?
119
+ BROWSER_MONITORING_INSTALLED_SINGLETON.instance_variable_defined?(BROWSER_MONITORING_INSTALLED_VARIABLE) &&
120
+ BROWSER_MONITORING_INSTALLED_SINGLETON.instance_variable_get(BROWSER_MONITORING_INSTALLED_VARIABLE)
121
+ end
122
+
123
+ def mark_browser_agent_as_installed
124
+ BROWSER_MONITORING_INSTALLED_SINGLETON.instance_variable_set(BROWSER_MONITORING_INSTALLED_VARIABLE, true)
125
+ end
126
+
103
127
  def rails_version
104
128
  @rails_version ||= Gem::Version.new(::Rails::VERSION::STRING)
105
129
  end
@@ -0,0 +1,20 @@
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 'new_relic/control/frameworks/ruby'
6
+ module NewRelic
7
+ class Control
8
+ module Frameworks
9
+ # Contains basic control logic for Roda
10
+ class Roda < NewRelic::Control::Frameworks::Ruby
11
+ protected
12
+
13
+ def install_shim
14
+ super
15
+ ::Roda.class_eval { include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -65,7 +65,7 @@ module NewRelic
65
65
  # An artifact of earlier implementation, we put both #add_method_tracer and #trace_execution
66
66
  # methods in the module methods.
67
67
  # Rails applications load the next two lines before any other initializers are run
68
- unless defined?(Rails::VERSION) && NewRelic::Agent.config[:defer_rails_initialization]
68
+ unless defined?(Rails::VERSION) && ENV['NEW_RELIC_DEFER_RAILS_INITIALIZATION']
69
69
  Module.send(:include, NewRelic::Agent::MethodTracer::ClassMethods)
70
70
  Module.send(:include, NewRelic::Agent::MethodTracer)
71
71
  end
@@ -82,10 +82,10 @@ module NewRelic
82
82
  if @started_in_env && @started_in_env != env
83
83
  Agent.logger.error("Attempted to start agent in #{env.inspect} environment, but agent was already running " \
84
84
  "in #{@started_in_env.inspect}", "The agent will continue running in #{@started_in_env.inspect}. To " \
85
- "alter this, ensure the desired environment is set before the agent starts.")
85
+ 'alter this, ensure the desired environment is set before the agent starts.')
86
86
  else
87
87
  Agent.logger.info("Starting the New Relic agent version #{NewRelic::VERSION::STRING} in #{env.inspect} " \
88
- "environment.", "To prevent agent startup add a NEW_RELIC_AGENT_ENABLED=false environment variable or " \
88
+ 'environment.', 'To prevent agent startup add a NEW_RELIC_AGENT_ENABLED=false environment variable or ' \
89
89
  "modify the #{env.inspect} section of your newrelic.yml.")
90
90
  end
91
91
 
@@ -106,9 +106,9 @@ module NewRelic
106
106
  end
107
107
 
108
108
  def handle_invalid_security_settings
109
- NewRelic::Agent.logger.error("Security Policies and High Security Mode cannot both be present in the agent " \
110
- "configuration. If Security Policies have been set for your account, please ensure the " \
111
- "security_policies_token is set but high_security is disabled (default).")
109
+ NewRelic::Agent.logger.error('Security Policies and High Security Mode cannot both be present in the agent ' \
110
+ 'configuration. If Security Policies have been set for your account, please ensure the ' \
111
+ 'security_policies_token is set but high_security is disabled (default).')
112
112
  install_shim
113
113
  end
114
114
 
@@ -62,9 +62,8 @@ module NewRelic
62
62
  File.join(instrumentation_path, app.to_s, '*.rb')
63
63
  @instrumentation_files.each { |pattern| load_instrumentation_files(pattern) }
64
64
  DependencyDetection.detect!
65
- ruby_deprecation
66
65
  rails_32_deprecation
67
- ::NewRelic::Agent.logger.info("Finished instrumentation")
66
+ ::NewRelic::Agent.logger.info('Finished instrumentation')
68
67
  end
69
68
  end
70
69
 
@@ -81,19 +80,6 @@ module NewRelic
81
80
  )
82
81
  end
83
82
 
84
- def ruby_deprecation
85
- return unless RUBY_VERSION < '2.4.0'
86
-
87
- deprecation_msg = 'The Ruby Agent is dropping support for Rubies below 2.4 ' \
88
- 'in version 9.0.0. Please upgrade your Ruby version to continue receiving support. ' \
89
-
90
- ::NewRelic::Agent.logger.log_once(
91
- :warn,
92
- :deprecated_ruby_version,
93
- deprecation_msg
94
- )
95
- end
96
-
97
83
  include Instrumentation
98
84
  end
99
85
  end
@@ -12,7 +12,7 @@ module NewRelic
12
12
 
13
13
  def configure_high_security
14
14
  if security_settings_valid? && Agent.config[:high_security]
15
- Agent.logger.info("Installing high security configuration based on local configuration")
15
+ Agent.logger.info('Installing high security configuration based on local configuration')
16
16
  Agent.config.replace_or_add_config(Agent::Configuration::HighSecuritySource.new(Agent.config))
17
17
  end
18
18
  end
@@ -27,6 +27,8 @@ module DependencyDetection
27
27
  @items.each do |item|
28
28
  if item.dependencies_satisfied?
29
29
  item.execute
30
+ else
31
+ item.configure_as_unsatisfied unless item.disabled_configured?
30
32
  end
31
33
  end
32
34
  end
@@ -35,19 +37,6 @@ module DependencyDetection
35
37
  @items.find { |i| i.name == name }
36
38
  end
37
39
 
38
- def installed?(name)
39
- item = dependency_by_name(name)
40
- item && item.executed
41
- end
42
-
43
- def items
44
- @items
45
- end
46
-
47
- def items=(new_items)
48
- @items = new_items
49
- end
50
-
51
40
  class Dependent
52
41
  attr_reader :executed
53
42
  attr_accessor :name
@@ -75,6 +64,10 @@ module DependencyDetection
75
64
  !executed and check_dependencies
76
65
  end
77
66
 
67
+ def configure_as_unsatisfied
68
+ NewRelic::Agent.config.instance_variable_get(:@cache)[config_key] = :unsatisfied
69
+ end
70
+
78
71
  def source_location_for(klass, method_name)
79
72
  Object.instance_method(:method).bind(klass.allocate).call(method_name).source_location.to_s
80
73
  end
@@ -83,7 +76,7 @@ module DependencyDetection
83
76
  # Given "NewRelic::Agent::Instrumentation::NetHTTP::Prepend"
84
77
  # Will extract "NetHTTP" which is in the 2nd to last spot
85
78
  def extract_supportability_name(instrumenting_module)
86
- instrumenting_module.to_s.split("::")[-2]
79
+ instrumenting_module.to_s.split('::')[-2]
87
80
  end
88
81
 
89
82
  def log_and_instrument(method, instrumenting_module, supportability_name)
@@ -94,20 +87,20 @@ module DependencyDetection
94
87
  end
95
88
 
96
89
  def prepend_instrument(target_class, instrumenting_module, supportability_name = nil)
97
- log_and_instrument("Prepend", instrumenting_module, supportability_name) do
90
+ log_and_instrument('Prepend', instrumenting_module, supportability_name) do
98
91
  target_class.send(:prepend, instrumenting_module)
99
92
  end
100
93
  end
101
94
 
102
95
  def chain_instrument(instrumenting_module, supportability_name = nil)
103
- log_and_instrument("MethodChaining", instrumenting_module, supportability_name) do
96
+ log_and_instrument('MethodChaining', instrumenting_module, supportability_name) do
104
97
  instrumenting_module.instrument!
105
98
  end
106
99
  end
107
100
 
108
101
  def chain_instrument_target(target, instrumenting_module, supportability_name = nil)
109
102
  NewRelic::Agent.logger.info("Installing deferred #{target} instrumentation")
110
- log_and_instrument("MethodChaining", instrumenting_module, supportability_name) do
103
+ log_and_instrument('MethodChaining', instrumenting_module, supportability_name) do
111
104
  instrumenting_module.instrument!(target)
112
105
  end
113
106
  end
@@ -192,6 +185,15 @@ module DependencyDetection
192
185
  return valid_value
193
186
  end
194
187
 
188
+ # update any :auto config value to be either :prepend or :chain after auto
189
+ # determination has selected one of those to use
190
+ def update_config_value(use_prepend)
191
+ if config_key && auto_configured?
192
+ NewRelic::Agent.config.instance_variable_get(:@cache)[config_key] = use_prepend ? :prepend : :chain
193
+ end
194
+ use_prepend
195
+ end
196
+
195
197
  def config_value
196
198
  return AUTO_CONFIG_VALUE unless config_key
197
199
 
@@ -215,7 +217,7 @@ module DependencyDetection
215
217
  end
216
218
 
217
219
  def use_prepend?
218
- prepend_configured? || (auto_configured? && !prepend_conflicts?)
220
+ update_config_value(prepend_configured? || (auto_configured? && !prepend_conflicts?))
219
221
  end
220
222
 
221
223
  def prepend_conflicts?
@@ -52,7 +52,7 @@ module NewRelic
52
52
  # though so try it if the above fails.
53
53
  Bundler.load.specs.map do |spec|
54
54
  version = (spec.respond_to?(:version) && spec.version)
55
- spec.name + (version ? "(#{version})" : "")
55
+ spec.name + (version ? "(#{version})" : '')
56
56
  end
57
57
  end
58
58
  end
@@ -118,19 +118,19 @@ module NewRelic
118
118
  def record_value(data, key, value)
119
119
  data[key] = value
120
120
 
121
- Agent.record_metric("Supportability/EnvironmentReport/success", 0.0)
121
+ Agent.record_metric('Supportability/EnvironmentReport/success', 0.0)
122
122
  Agent.record_metric("Supportability/EnvironmentReport/success/#{key}", 0.0)
123
123
  end
124
124
 
125
125
  def record_empty_value(key, value)
126
126
  Agent.logger.debug("EnvironmentReport ignoring value for #{key.inspect} which came back falsey: #{value.inspect}")
127
- Agent.record_metric("Supportability/EnvironmentReport/empty", 0.0)
127
+ Agent.record_metric('Supportability/EnvironmentReport/empty', 0.0)
128
128
  Agent.record_metric("Supportability/EnvironmentReport/empty/#{key}", 0.0)
129
129
  end
130
130
 
131
131
  def rescue_initialize(key, exception)
132
132
  Agent.logger.debug("EnvironmentReport failed to retrieve value for #{key.inspect}: #{exception}")
133
- Agent.record_metric("Supportability/EnvironmentReport/error", 0.0)
133
+ Agent.record_metric('Supportability/EnvironmentReport/error', 0.0)
134
134
  Agent.record_metric("Supportability/EnvironmentReport/error/#{key}", 0.0)
135
135
  end
136
136
  end
@@ -63,7 +63,8 @@ module NewRelic
63
63
  raise NewRelic::CommandRunFailedError.new("Failed to run command '#{command}': #{message}")
64
64
  end
65
65
 
66
- output.chomp if output
66
+ # needs else branch coverage
67
+ output.chomp if output # rubocop:disable Style/SafeNavigation
67
68
  end
68
69
 
69
70
  # TODO: Open3 defers the actual execution of a binary to Process.spawn,
@@ -62,7 +62,7 @@ module NewRelic
62
62
  #
63
63
  # Can't help if the constant isn't a class...
64
64
  if result.is_a?(Module)
65
- expected_name = "#{namespace}::#{name}".gsub(/^Object::/, "")
65
+ expected_name = "#{namespace}::#{name}".gsub(/^Object::/, '')
66
66
  return unless expected_name == result.to_s
67
67
  end
68
68
 
@@ -78,6 +78,15 @@ module NewRelic
78
78
  camelized.split(/\-|\_/).map(&:capitalize).join
79
79
  end
80
80
 
81
+ def camelize_with_first_letter_downcased(string)
82
+ camelized = camelize(string)
83
+ camelized[0].downcase.concat(camelized[1..-1])
84
+ end
85
+
86
+ def snakeize(string)
87
+ string.gsub(/(.)([A-Z])/, '\1_\2').downcase
88
+ end
89
+
81
90
  def bundled_gem?(gem_name)
82
91
  defined?(Bundler) && Bundler.rubygems.all_specs.map(&:name).include?(gem_name)
83
92
  rescue => e
@@ -8,7 +8,7 @@ module NewRelic
8
8
  File.join(File.dirname(__FILE__), '..', '..', 'CHANGELOG.md')
9
9
  end
10
10
 
11
- FOOTER = <<'EOS'
11
+ FOOTER = <<EOS
12
12
  See https://github.com/newrelic/newrelic-ruby-agent/blob/main/CHANGELOG.md for a full list of
13
13
  changes.
14
14
  EOS
@@ -26,12 +26,12 @@ EOS
26
26
  # * This is a patch item (3.7.1.188)
27
27
  def self.read_patch(patch_level, changelog = default_changelog)
28
28
  latest = extract_latest_changes(File.read(changelog))
29
- changes = ["## v#{patch_level}", ""]
29
+ changes = ["## v#{patch_level}", '']
30
30
 
31
31
  current_item = nil
32
32
  latest.each do |line|
33
- if line =~ /^\s*\*.*/
34
- if line =~ /\(#{patch_level}\)/
33
+ if /^\s*\*.*/.match?(line)
34
+ if /\(#{patch_level}\)/.match?(line)
35
35
  # Found a patch level item, so start tracking the lines!
36
36
  current_item = line
37
37
  else
@@ -52,12 +52,12 @@ EOS
52
52
  changes = []
53
53
  version_count = 0
54
54
  contents.each_line do |line|
55
- if line =~ /##\s+v[\d.]+/
55
+ if /##\s+v[\d.]+/.match?(line)
56
56
  version_count += 1
57
57
  end
58
58
  break if version_count >= 2
59
59
 
60
- changes << line.sub(/^ \* /, "* ").chomp
60
+ changes << line.sub(/^ \* /, '* ').chomp
61
61
  end
62
62
  changes
63
63
  end
@@ -74,9 +74,7 @@ module NewRelic
74
74
  unicorn
75
75
  webrick
76
76
  fastcgi
77
- rainbows
78
77
  ]
79
- # TODO: MAJOR VERSION - remove rainbows
80
78
  while dispatchers.any? && @discovered_dispatcher.nil?
81
79
  send('check_for_' + (dispatchers.shift))
82
80
  end
@@ -134,14 +132,6 @@ module NewRelic
134
132
  end
135
133
  end
136
134
 
137
- # TODO: MAJOR VERSION - remove this method
138
- def check_for_rainbows
139
- if (defined?(::Rainbows) && defined?(::Rainbows::HttpServer)) && NewRelic::LanguageSupport.object_space_usable?
140
- v = find_class_in_object_space(::Rainbows::HttpServer)
141
- @discovered_dispatcher = :rainbows if v
142
- end
143
- end
144
-
145
135
  def check_for_puma
146
136
  if defined?(::Puma) && File.basename($0) == 'puma'
147
137
  @discovered_dispatcher = :puma
@@ -13,20 +13,22 @@ class NewRelic::NoticedError
13
13
  attr_accessor :path, :timestamp, :message, :exception_class_name,
14
14
  :request_uri, :request_port, :file_name, :line_number,
15
15
  :stack_trace, :attributes_from_notice_error, :attributes,
16
- :expected
16
+ :expected, :transaction_id
17
17
 
18
- attr_reader :exception_id, :is_internal
18
+ attr_reader :error_group, :exception_id, :is_internal
19
19
 
20
20
  STRIPPED_EXCEPTION_REPLACEMENT_MESSAGE = "Message removed by New Relic 'strip_exception_messages' setting"
21
21
  UNKNOWN_ERROR_CLASS_NAME = 'Error'
22
22
  NIL_ERROR_MESSAGE = '<no message>'
23
23
 
24
- USER_ATTRIBUTES = "userAttributes"
25
- AGENT_ATTRIBUTES = "agentAttributes"
26
- INTRINSIC_ATTRIBUTES = "intrinsics"
24
+ USER_ATTRIBUTES = 'userAttributes'
25
+ AGENT_ATTRIBUTES = 'agentAttributes'
26
+ INTRINSIC_ATTRIBUTES = 'intrinsics'
27
27
 
28
28
  DESTINATION = NewRelic::Agent::AttributeFilter::DST_ERROR_COLLECTOR
29
29
 
30
+ AGENT_ATTRIBUTE_ERROR_GROUP = :'error.group.name'
31
+
30
32
  ERROR_PREFIX_KEY = 'error'
31
33
  ERROR_MESSAGE_KEY = "#{ERROR_PREFIX_KEY}.message"
32
34
  ERROR_CLASS_KEY = "#{ERROR_PREFIX_KEY}.class"
@@ -43,6 +45,7 @@ class NewRelic::NoticedError
43
45
  @is_internal = (exception.class < NewRelic::Agent::InternalAgentError)
44
46
 
45
47
  extract_class_name_and_message_from(exception)
48
+ @transaction_id = NewRelic::Agent::Tracer&.current_transaction&.guid
46
49
 
47
50
  # clamp long messages to 4k so that we don't send a lot of
48
51
  # overhead across the wire
@@ -77,11 +80,13 @@ class NewRelic::NoticedError
77
80
  include NewRelic::Coerce
78
81
 
79
82
  def to_collector_array(encoder = nil)
80
- [NewRelic::Helper.time_to_millis(timestamp),
83
+ arr = [NewRelic::Helper.time_to_millis(timestamp),
81
84
  string(path),
82
85
  string(message),
83
86
  string(exception_class_name),
84
87
  processed_attributes]
88
+ arr << @transaction_id if @transaction_id
89
+ arr
85
90
  end
86
91
 
87
92
  # Note that we process attributes lazily and store the result. This is because
@@ -141,21 +146,9 @@ class NewRelic::NoticedError
141
146
  end
142
147
 
143
148
  def build_agent_attributes(merged_attributes)
144
- agent_attributes = if @attributes
145
- @attributes.agent_attributes_for(DESTINATION)
146
- else
147
- NewRelic::EMPTY_HASH
148
- end
149
-
150
- # It's possible to override the request_uri from the transaction attributes
151
- # with a uri passed to notice_error. Add it to merged_attributes filter and
152
- # merge with the transaction attributes, possibly overriding the request_uri
153
- if request_uri
154
- merged_attributes.add_agent_attribute(:'request.uri', request_uri, DESTINATION)
155
- agent_attributes.merge(merged_attributes.agent_attributes_for(DESTINATION))
156
- end
149
+ return NewRelic::EMPTY_HASH unless @attributes
157
150
 
158
- agent_attributes
151
+ @attributes.agent_attributes_for(DESTINATION)
159
152
  end
160
153
 
161
154
  def build_intrinsic_attributes
@@ -197,4 +190,16 @@ class NewRelic::NoticedError
197
190
  @message = exception.to_s
198
191
  end
199
192
  end
193
+
194
+ def error_group=(name)
195
+ return if name.nil? || name.empty?
196
+
197
+ if agent_attributes.frozen?
198
+ processed_attributes[AGENT_ATTRIBUTES] = agent_attributes.merge(AGENT_ATTRIBUTE_ERROR_GROUP => name)
199
+ else
200
+ agent_attributes[AGENT_ATTRIBUTE_ERROR_GROUP] = name
201
+ end
202
+
203
+ @error_group = name
204
+ end
200
205
  end
@@ -23,7 +23,7 @@ module NewRelic::Rack
23
23
  #
24
24
  class AgentHooks < AgentMiddleware
25
25
  def self.needed?
26
- !NewRelic::Agent.config[:disable_middleware_instrumentation]
26
+ NewRelic::Agent.config[:disable_middleware_instrumentation]
27
27
  end
28
28
 
29
29
  def traced_call(env)
@@ -26,22 +26,6 @@ module NewRelic
26
26
  prefix = ::NewRelic::Agent::Instrumentation::ControllerInstrumentation::TransactionNamer.prefix_for_category(nil, @category)
27
27
  "#{prefix}#{self.class.name}/call"
28
28
  end
29
-
30
- # If middleware tracing is disabled, we'll still inject our agent-specific
31
- # middlewares, and still trace those, but we don't want to capture HTTP
32
- # response codes, since middleware that's outside of ours might change the
33
- # response code before it goes back to the client.
34
- def capture_http_response_code(state, result)
35
- return if NewRelic::Agent.config[:disable_middleware_instrumentation]
36
-
37
- super
38
- end
39
-
40
- def capture_response_content_type(state, result)
41
- return if NewRelic::Agent.config[:disable_middleware_instrumentation]
42
-
43
- super
44
- end
45
29
  end
46
30
  end
47
31
  end
@@ -26,11 +26,11 @@ module NewRelic
26
26
  ATTACHMENT = 'attachment'.freeze
27
27
  TEXT_HTML = 'text/html'.freeze
28
28
 
29
- BODY_START = "<body".freeze
30
- HEAD_START = "<head".freeze
31
- GT = ">".freeze
29
+ BODY_START = '<body'.freeze
30
+ HEAD_START = '<head'.freeze
31
+ GT = '>'.freeze
32
32
 
33
- ALREADY_INSTRUMENTED_KEY = "newrelic.browser_monitoring_already_instrumented"
33
+ ALREADY_INSTRUMENTED_KEY = 'newrelic.browser_monitoring_already_instrumented'
34
34
  CHARSET_RE = /<\s*meta[^>]+charset\s*=[^>]*>/im.freeze
35
35
  X_UA_COMPATIBLE_RE = /<\s*meta[^>]+http-equiv\s*=\s*['"]x-ua-compatible['"][^>]*>/im.freeze
36
36
 
@@ -40,7 +40,7 @@ module NewRelic
40
40
 
41
41
  js_to_inject = NewRelic::Agent.browser_timing_header
42
42
  if (js_to_inject != NewRelic::EMPTY_STR) && should_instrument?(env, status, headers)
43
- response_string = autoinstrument_source(response, headers, js_to_inject)
43
+ response_string = autoinstrument_source(response, js_to_inject)
44
44
  if headers.key?(CONTENT_LENGTH)
45
45
  content_length = response_string ? response_string.bytesize : 0
46
46
  headers[CONTENT_LENGTH] = content_length.to_s
@@ -69,11 +69,17 @@ module NewRelic
69
69
 
70
70
  private
71
71
 
72
- def autoinstrument_source(response, headers, js_to_inject)
72
+ def autoinstrument_source(response, js_to_inject)
73
73
  source = gather_source(response)
74
74
  close_old_response(response)
75
- return nil unless source
75
+ return unless source
76
76
 
77
+ modify_source(source, js_to_inject)
78
+ rescue => e
79
+ NewRelic::Agent.logger.debug("Skipping RUM instrumentation on exception: #{e.class} - #{e.message}")
80
+ end
81
+
82
+ def modify_source(source, js_to_inject)
77
83
  # Only scan the first 50k (roughly) then give up.
78
84
  beginning_of_source = source[0..SCAN_LIMIT]
79
85
  meta_tag_positions = find_meta_tag_positions(beginning_of_source)
@@ -81,26 +87,24 @@ module NewRelic
81
87
  if insertion_index = find_insertion_index(meta_tag_positions, beginning_of_source, body_start)
82
88
  source = source_injection(source, insertion_index, js_to_inject)
83
89
  else
84
- NewRelic::Agent.logger.debug("Skipping RUM instrumentation. Could not properly determine location to inject script.")
90
+ NewRelic::Agent.logger.debug('Skipping RUM instrumentation. Could not properly determine location to ' \
91
+ 'inject script.')
85
92
  end
86
93
  else
87
94
  msg = "Skipping RUM instrumentation. Unable to find <body> tag in first #{SCAN_LIMIT} bytes of document."
88
95
  NewRelic::Agent.logger.log_once(:warn, :rum_insertion_failure, msg)
89
96
  NewRelic::Agent.logger.debug(msg)
90
97
  end
91
-
92
98
  source
93
- rescue => e
94
- NewRelic::Agent.logger.debug("Skipping RUM instrumentation on exception.", e)
95
- nil
96
99
  end
97
100
 
98
101
  def html?(headers)
99
- headers[CONTENT_TYPE] && headers[CONTENT_TYPE].include?(TEXT_HTML)
102
+ # needs else branch coverage
103
+ headers[CONTENT_TYPE] && headers[CONTENT_TYPE].include?(TEXT_HTML) # rubocop:disable Style/SafeNavigation
100
104
  end
101
105
 
102
106
  def attachment?(headers)
103
- headers[CONTENT_DISPOSITION] && headers[CONTENT_DISPOSITION].include?(ATTACHMENT)
107
+ headers[CONTENT_DISPOSITION]&.include?(ATTACHMENT)
104
108
  end
105
109
 
106
110
  def streaming?(env, headers)
@@ -139,7 +143,7 @@ module NewRelic
139
143
  end
140
144
 
141
145
  # Per "The Response > The Body" section of Rack spec, we should close
142
- # if our response is able. http://rack.rubyforge.org/doc/SPEC.html
146
+ # if our response is able. https://github.com/rack/rack/blob/main/SPEC.rdoc
143
147
  def close_old_response(response)
144
148
  response.close if response.respond_to?(:close)
145
149
  end
@@ -150,12 +154,12 @@ module NewRelic
150
154
 
151
155
  def find_x_ua_compatible_position(beginning_of_source)
152
156
  match = X_UA_COMPATIBLE_RE.match(beginning_of_source)
153
- match.end(0) if match
157
+ match&.end(0)
154
158
  end
155
159
 
156
160
  def find_charset_position(beginning_of_source)
157
161
  match = CHARSET_RE.match(beginning_of_source)
158
- match.end(0) if match
162
+ match&.end(0)
159
163
  end
160
164
 
161
165
  def find_end_of_head_open(beginning_of_source)