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
@@ -1,21 +1,25 @@
1
1
  # This file is distributed under New Relic's license terms.
2
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
3
  # frozen_string_literal: true
4
+
4
5
  require_relative '../../datastores/nosql_obfuscator'
5
6
 
6
7
  module NewRelic::Agent::Instrumentation
7
8
  module Elasticsearch
8
9
  PRODUCT_NAME = 'Elasticsearch'
9
10
  OPERATION = 'perform_request'
11
+ INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name)
10
12
 
11
13
  def perform_request_with_tracing(method, path, params = {}, body = nil, headers = nil)
12
14
  return yield unless NewRelic::Agent::Tracer.tracing_enabled?
13
15
 
16
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
17
+
14
18
  segment = NewRelic::Agent::Tracer.start_datastore_segment(
15
19
  product: PRODUCT_NAME,
16
20
  operation: nr_operation || OPERATION,
17
21
  host: nr_hosts[:host],
18
- port_path_or_id: path,
22
+ port_path_or_id: nr_hosts[:port],
19
23
  database_name: nr_cluster_name
20
24
  )
21
25
  begin
@@ -37,7 +41,7 @@ module NewRelic::Agent::Instrumentation
37
41
  end
38
42
  return nil unless operation_index
39
43
 
40
- caller_locations[operation_index].to_s.split('`')[-1].gsub(/\W/, "")
44
+ caller_locations[operation_index].to_s.split('`')[-1].gsub(/\W/, '')
41
45
  end
42
46
 
43
47
  def nr_reported_query(query)
@@ -52,10 +56,10 @@ module NewRelic::Agent::Instrumentation
52
56
  return if nr_hosts.empty?
53
57
 
54
58
  NewRelic::Agent.disable_all_tracing do
55
- @nr_cluster_name ||= perform_request('GET', '_cluster/health').body["cluster_name"]
59
+ @nr_cluster_name ||= perform_request('GET', '_cluster/health').body['cluster_name']
56
60
  end
57
61
  rescue StandardError => e
58
- NewRelic::Agent.logger.error("Failed to get cluster name for elasticsearch", e)
62
+ NewRelic::Agent.logger.error('Failed to get cluster name for elasticsearch', e)
59
63
  nil
60
64
  end
61
65
 
@@ -16,7 +16,7 @@ DependencyDetection.defer do
16
16
  executes do
17
17
  NewRelic::Agent.logger.info('Installing Elasticsearch instrumentation')
18
18
 
19
- to_instrument = if Gem::Version.create(Elasticsearch::VERSION) < Gem::Version.create("8.0.0")
19
+ to_instrument = if Gem::Version.create(Elasticsearch::VERSION) < Gem::Version.create('8.0.0')
20
20
  Elasticsearch::Transport::Client
21
21
  else
22
22
  Elastic::Transport::Client
@@ -25,7 +25,7 @@ DependencyDetection.defer do
25
25
  if use_prepend?
26
26
  prepend_instrument to_instrument, NewRelic::Agent::Instrumentation::Elasticsearch::Prepend
27
27
  else
28
- chain_instrument NewRelic::Agent::Instrumentation::Elasticsearch
28
+ chain_instrument NewRelic::Agent::Instrumentation::Elasticsearch::Chain
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,39 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module Ethon
7
+ module Chain
8
+ def self.instrument!
9
+ ::Ethon::Easy.class_eval do
10
+ include NewRelic::Agent::Instrumentation::Ethon::Easy
11
+
12
+ alias_method(:fabricate_without_tracing, :fabricate)
13
+ def fabricate(url, action_name, options)
14
+ fabricate_with_tracing(url, action_name, options) { fabricate_without_tracing(url, action_name, options) }
15
+ end
16
+
17
+ alias_method(:headers_equals_without_tracing, :headers=)
18
+ def headers=(headers)
19
+ headers_equals_with_tracing(headers) { headers_equals_without_tracing(headers) }
20
+ end
21
+
22
+ alias_method(:perform_without_tracing, :perform)
23
+ def perform(*args)
24
+ perform_with_tracing(*args) { perform_without_tracing(*args) }
25
+ end
26
+ end
27
+
28
+ ::Ethon::Multi.class_eval do
29
+ include NewRelic::Agent::Instrumentation::Ethon::Multi
30
+
31
+ alias_method(:perform_without_tracing, :perform)
32
+ def perform(*args)
33
+ perform_with_tracing(*args) { perform_without_tracing(*args) }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,105 @@
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/agent/http_clients/ethon_wrappers'
6
+
7
+ module NewRelic::Agent::Instrumentation
8
+ module Ethon
9
+ module NRShared
10
+ INSTRUMENTATION_NAME = 'Ethon'
11
+ NOTICEABLE_ERROR_CLASS = 'Ethon::Errors::EthonError'
12
+
13
+ def prep_easy(easy, parent = nil)
14
+ wrapped_request = NewRelic::Agent::HTTPClients::EthonHTTPRequest.new(easy)
15
+ segment = NewRelic::Agent::Tracer.start_external_request_segment(
16
+ library: wrapped_request.type,
17
+ uri: wrapped_request.uri,
18
+ procedure: wrapped_request.method,
19
+ parent: parent
20
+ )
21
+ segment.add_request_headers(wrapped_request)
22
+
23
+ callback = proc do
24
+ wrapped_response = NewRelic::Agent::HTTPClients::EthonHTTPResponse.new(easy)
25
+ segment.process_response_headers(wrapped_response)
26
+
27
+ if easy.return_code != :ok
28
+ e = NewRelic::Agent::NoticeableError.new(NOTICEABLE_ERROR_CLASS,
29
+ "return_code: >>#{easy.return_code}<<, response_code: >>#{easy.response_code}<<")
30
+ segment.notice_error(e)
31
+ end
32
+
33
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
34
+ end
35
+
36
+ easy.on_complete { callback.call }
37
+
38
+ segment
39
+ end
40
+
41
+ def wrap_with_tracing(segment, &block)
42
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
43
+
44
+ NewRelic::Agent::Tracer.capture_segment_error(segment) do
45
+ yield
46
+ end
47
+ ensure
48
+ NewRelic::Agent::Transaction::Segment.finish(segment)
49
+ end
50
+ end
51
+
52
+ module Easy
53
+ include NRShared
54
+
55
+ ACTION_INSTANCE_VAR = :@nr_action
56
+ HEADERS_INSTANCE_VAR = :@nr_headers
57
+
58
+ # `Ethon::Easy` doesn't expose the "action name" ('GET', 'POST', etc.)
59
+ # and Ethon's fabrication of HTTP classes uses
60
+ # `Ethon::Easy::Http::Custom` for non-standard actions. To be able to
61
+ # know the action name at `#perform` time, we set a new instance variable
62
+ # on the `Ethon::Easy` instance with the base name of the fabricated
63
+ # class, respecting the 'Custom' name where appropriate.
64
+ def fabricate_with_tracing(_url, action_name, _options)
65
+ fabbed = yield
66
+ instance_variable_set(ACTION_INSTANCE_VAR, NewRelic::Agent.base_name(fabbed.class.name).upcase)
67
+ fabbed
68
+ end
69
+
70
+ # `Ethon::Easy` uses `Ethon::Easy::Header` to set request headers on
71
+ # libcurl with `#headers=`. After they are set, they aren't easy to get
72
+ # at again except via FFI so set a new instance variable on the
73
+ # `Ethon::Easy` instance to store them in Ruby hash format.
74
+ def headers_equals_with_tracing(headers)
75
+ instance_variable_set(HEADERS_INSTANCE_VAR, headers)
76
+ yield
77
+ end
78
+
79
+ def perform_with_tracing(*args)
80
+ return unless NewRelic::Agent::Tracer.state.is_execution_traced?
81
+
82
+ segment = prep_easy(self)
83
+ wrap_with_tracing(segment) { yield }
84
+ end
85
+ end
86
+
87
+ module Multi
88
+ include NRShared
89
+
90
+ MULTI_SEGMENT_NAME = 'External/Multiple/Ethon::Multi/perform'
91
+
92
+ def perform_with_tracing(*args)
93
+ return unless NewRelic::Agent::Tracer.state.is_execution_traced?
94
+
95
+ segment = NewRelic::Agent::Tracer.start_segment(name: MULTI_SEGMENT_NAME)
96
+
97
+ wrap_with_tracing(segment) do
98
+ easy_handles.each { |easy| prep_easy(easy, segment) }
99
+
100
+ yield
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,35 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module Ethon
7
+ module Easy
8
+ module Prepend
9
+ include NewRelic::Agent::Instrumentation::Ethon::Easy
10
+
11
+ def fabricate(url, action_name, options)
12
+ fabricate_with_tracing(url, action_name, options) { super }
13
+ end
14
+
15
+ def headers=(headers)
16
+ headers_equals_with_tracing(headers) { super }
17
+ end
18
+
19
+ def perform(*args)
20
+ perform_with_tracing(*args) { super }
21
+ end
22
+ end
23
+ end
24
+
25
+ module Multi
26
+ module Prepend
27
+ include NewRelic::Agent::Instrumentation::Ethon::Multi
28
+
29
+ def perform(*args)
30
+ perform_with_tracing(*args) { super }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
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 'ethon/instrumentation'
6
+ require_relative 'ethon/chain'
7
+ require_relative 'ethon/prepend'
8
+
9
+ DependencyDetection.defer do
10
+ named :ethon
11
+
12
+ # If Ethon is being used as a dependency of Typhoeus, allow the Typhoeus
13
+ # instrumentation to handle everything. Otherwise each external network call
14
+ # will confusingly result in "Ethon" segments duplicating the information
15
+ # already provided by "Typhoeus" segments.
16
+ depends_on do
17
+ !defined?(Typhoeus)
18
+ end
19
+
20
+ depends_on do
21
+ defined?(Ethon) && Gem::Version.new(Ethon::VERSION) >= Gem::Version.new('0.12.0')
22
+ end
23
+
24
+ executes do
25
+ NewRelic::Agent.logger.info('Installing ethon instrumentation')
26
+ end
27
+
28
+ executes do
29
+ if use_prepend?
30
+ # NOTE: by default prepend_instrument will go with the module name that
31
+ # precedes 'Prepend' (so 'Easy' and 'Multi'), but we want to use
32
+ # 'Ethon::Easy' and 'Ethon::Multi' so 3rd argument is supplied
33
+ prepend_instrument Ethon::Easy, NewRelic::Agent::Instrumentation::Ethon::Easy::Prepend, Ethon::Easy.name
34
+ prepend_instrument Ethon::Multi, NewRelic::Agent::Instrumentation::Ethon::Multi::Prepend, Ethon::Multi.name
35
+ else
36
+ chain_instrument NewRelic::Agent::Instrumentation::Ethon::Chain
37
+ end
38
+ end
39
+ end
@@ -6,6 +6,7 @@ module ::Excon
6
6
  module Middleware
7
7
  class NewRelicCrossAppTracing
8
8
  TRACE_DATA_IVAR = :@newrelic_trace_data
9
+ INSTRUMENTATION_NAME = 'Excon'
9
10
 
10
11
  def initialize(stack)
11
12
  @stack = stack
@@ -18,6 +19,8 @@ module ::Excon
18
19
  # :idempotent in the options, but there will be only a single
19
20
  # accompanying response_call/error_call.
20
21
  if datum[:connection] && !datum[:connection].instance_variable_get(TRACE_DATA_IVAR)
22
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
23
+
21
24
  wrapped_request = ::NewRelic::Agent::HTTPClients::ExconHTTPRequest.new(datum)
22
25
  segment = NewRelic::Agent::Tracer.start_external_request_segment(
23
26
  library: wrapped_request.type,
@@ -46,7 +49,8 @@ module ::Excon
46
49
  end
47
50
 
48
51
  def finish_trace(datum) # THREAD_LOCAL_ACCESS
49
- segment = datum[:connection] && datum[:connection].instance_variable_get(TRACE_DATA_IVAR)
52
+ # The following line needs else branch coverage
53
+ segment = datum[:connection] && datum[:connection].instance_variable_get(TRACE_DATA_IVAR) # rubocop:disable Style/SafeNavigation
50
54
  if segment
51
55
  begin
52
56
  segment.notice_error(datum[:error]) if datum[:error]
@@ -18,7 +18,7 @@ DependencyDetection.defer do
18
18
  # but alas, it does not yet.
19
19
 
20
20
  # TODO: MAJOR VERSION - update min version to 0.56.0
21
- EXCON_MIN_VERSION = Gem::Version.new("0.19.0")
21
+ EXCON_MIN_VERSION = Gem::Version.new('0.19.0')
22
22
 
23
23
  depends_on do
24
24
  defined?(Excon) && defined?(Excon::VERSION)
@@ -46,7 +46,7 @@ DependencyDetection.defer do
46
46
  deprecation_msg
47
47
  )
48
48
 
49
- NewRelic::Agent.record_metric("Supportability/Deprecated/Excon", 1)
49
+ NewRelic::Agent.record_metric('Supportability/Deprecated/Excon', 1)
50
50
  end
51
51
 
52
52
  def install_excon_instrumentation(excon_version)
@@ -64,7 +64,7 @@ DependencyDetection.defer do
64
64
  if defaults[:middlewares]
65
65
  defaults[:middlewares] << Excon::Middleware::NewRelicCrossAppTracing
66
66
  else
67
- NewRelic::Agent.logger.warn("Did not find :middlewares key in Excon.defaults, skipping Excon instrumentation")
67
+ NewRelic::Agent.logger.warn('Did not find :middlewares key in Excon.defaults, skipping Excon instrumentation')
68
68
  end
69
69
  end
70
70
  end
@@ -0,0 +1,27 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module MonitoredFiber::Chain
7
+ def self.instrument!
8
+ ::Fiber.class_eval do
9
+ include NewRelic::Agent::Instrumentation::MonitoredFiber
10
+
11
+ alias_method(:initialize_without_new_relic, :initialize)
12
+
13
+ if RUBY_VERSION < '2.7.0'
14
+ def initialize(*_args, &block)
15
+ traced_block = add_thread_tracing(&block)
16
+ initialize_with_newrelic_tracing { initialize_without_new_relic(&traced_block) }
17
+ end
18
+ else
19
+ def initialize(**kwargs, &block)
20
+ traced_block = add_thread_tracing(&block)
21
+ initialize_with_newrelic_tracing { initialize_without_new_relic(**kwargs, &traced_block) }
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module MonitoredFiber
7
+ attr_reader :nr_parent_key
8
+
9
+ def initialize_with_newrelic_tracing
10
+ @nr_parent_key = NewRelic::Agent::Tracer.current_segment_key
11
+ yield
12
+ end
13
+
14
+ def add_thread_tracing(&block)
15
+ return block if !NewRelic::Agent::Tracer.thread_tracing_enabled?
16
+
17
+ NewRelic::Agent::Tracer.thread_block_with_current_transaction(
18
+ segment_name: 'Ruby/Fiber',
19
+ &block
20
+ )
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
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 'instrumentation'
6
+
7
+ module NewRelic::Agent::Instrumentation
8
+ module MonitoredFiber
9
+ module Prepend
10
+ include NewRelic::Agent::Instrumentation::MonitoredFiber
11
+
12
+ if RUBY_VERSION < '2.7.0'
13
+ def initialize(*_args, &block)
14
+ traced_block = add_thread_tracing(&block)
15
+ initialize_with_newrelic_tracing { super(&traced_block) }
16
+ end
17
+ else
18
+ def initialize(**kawrgs, &block)
19
+ traced_block = add_thread_tracing(&block)
20
+ initialize_with_newrelic_tracing { super(**kawrgs, &traced_block) }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
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 'fiber/instrumentation'
6
+ require_relative 'fiber/chain'
7
+ require_relative 'fiber/prepend'
8
+
9
+ DependencyDetection.defer do
10
+ named :fiber
11
+
12
+ depends_on do
13
+ defined?(Fiber)
14
+ end
15
+
16
+ executes do
17
+ NewRelic::Agent.logger.info('Installing Fiber instrumentation')
18
+
19
+ if use_prepend?
20
+ prepend_instrument Fiber, NewRelic::Agent::Instrumentation::MonitoredFiber::Prepend
21
+ else
22
+ chain_instrument NewRelic::Agent::Instrumentation::MonitoredFiber::Chain
23
+ end
24
+ end
25
+ end
@@ -9,6 +9,8 @@ module NewRelic::Agent::Instrumentation
9
9
  module Instrumentation
10
10
  extend self
11
11
 
12
+ INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name)
13
+
12
14
  # Since 1.2.0, the class `Grape::API` no longer refers to an API instance, rather, what used to be `Grape::API` is `Grape::API::Instance`
13
15
  # https://github.com/ruby-grape/grape/blob/c20a73ac1e3f3ba1082005ed61bf69452373ba87/UPGRADING.md#upgrading-to--120
14
16
  def instrumented_class
@@ -23,12 +25,12 @@ module NewRelic::Agent::Instrumentation
23
25
  api_class = (context.class.respond_to?(:base) && context.class.base) || context.class
24
26
  handle_transaction(endpoint, api_class.name, version)
25
27
  rescue => e
26
- ::NewRelic::Agent.logger.warn("Error in Grape instrumentation", e)
28
+ ::NewRelic::Agent.logger.warn('Error in Grape instrumentation', e)
27
29
  end
28
30
  end
29
31
 
30
32
  def prepare!
31
- if defined?(::Grape::VERSION) && Gem::Version.new(::Grape::VERSION) >= Gem::Version.new("0.16.0")
33
+ if defined?(::Grape::VERSION) && Gem::Version.new(::Grape::VERSION) >= Gem::Version.new('0.16.0')
32
34
  send(:remove_method, :name_for_transaction_deprecated)
33
35
  else
34
36
  send(:remove_method, :name_for_transaction)
@@ -40,12 +42,14 @@ module NewRelic::Agent::Instrumentation
40
42
  API_VERSION = 'api.version'.freeze
41
43
  FORMAT_REGEX = /\(\/?\.[\:\w]*\)/.freeze # either :format (< 0.12.0) or .ext (>= 0.12.0)
42
44
  VERSION_REGEX = /:version(\/|$)/.freeze
43
- MIN_VERSION = Gem::Version.new("0.2.0")
45
+ MIN_VERSION = Gem::Version.new('0.2.0')
44
46
  PIPE_STRING = '|'.freeze
45
47
 
46
48
  def handle_transaction(endpoint, class_name, version)
47
49
  return unless endpoint && route = endpoint.route
48
50
 
51
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
52
+
49
53
  name_transaction(route, class_name, version)
50
54
  capture_params(endpoint)
51
55
  end
@@ -91,7 +95,7 @@ module NewRelic::Agent::Instrumentation
91
95
  txn = ::NewRelic::Agent::Transaction.tl_current
92
96
  env = endpoint.request.env
93
97
  params = ::NewRelic::Agent::ParameterFiltering::apply_filters(env, endpoint.params)
94
- params.delete("route_info")
98
+ params.delete('route_info')
95
99
  txn.filtered_params = params
96
100
  txn.merge_request_parameters(params)
97
101
  end
@@ -9,7 +9,7 @@ require_relative 'grape/prepend'
9
9
  DependencyDetection.defer do
10
10
  # Why not just :grape? newrelic-grape used that name already, and while we're
11
11
  # not shipping yet, overloading the name interferes with the plugin.
12
- named :grape_instrumentation
12
+ @name = :grape_instrumentation
13
13
  configure_with :grape
14
14
 
15
15
  depends_on do
@@ -19,14 +19,14 @@ DependencyDetection.defer do
19
19
 
20
20
  depends_on do
21
21
  begin
22
- if defined?(Bundler) && Bundler.rubygems.all_specs.map(&:name).include?("newrelic-grape")
23
- NewRelic::Agent.logger.info("Not installing New Relic supported Grape instrumentation because the third party newrelic-grape gem is present")
22
+ if defined?(Bundler) && Bundler.rubygems.all_specs.map(&:name).include?('newrelic-grape')
23
+ NewRelic::Agent.logger.info('Not installing New Relic supported Grape instrumentation because the third party newrelic-grape gem is present')
24
24
  false
25
25
  else
26
26
  true
27
27
  end
28
28
  rescue => e
29
- NewRelic::Agent.logger.info("Could not determine if third party newrelic-grape gem is installed", e)
29
+ NewRelic::Agent.logger.info('Could not determine if third party newrelic-grape gem is installed', e)
30
30
  true
31
31
  end
32
32
  end
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require_relative 'instrumentation'
6
6
 
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require_relative 'request_wrapper'
6
6
  require_relative '../helper'
@@ -12,13 +12,18 @@ module NewRelic
12
12
  module Client
13
13
  include NewRelic::Agent::Instrumentation::GRPC::Helper
14
14
 
15
+ INSTRUMENTATION_NAME = 'gRPC_Client'
16
+
15
17
  def issue_request_with_tracing(grpc_type, method, requests, marshal, unmarshal,
16
18
  deadline:, return_op:, parent:, credentials:, metadata:)
17
19
  return yield unless trace_with_newrelic?
18
20
 
21
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
22
+
19
23
  segment = request_segment(method)
20
24
  request_wrapper = NewRelic::Agent::Instrumentation::GRPC::Client::RequestWrapper.new(@host)
21
- segment.add_request_headers(request_wrapper)
25
+ # do not insert CAT headers for gRPC requests https://github.com/newrelic/newrelic-ruby-agent/issues/1730
26
+ segment.add_request_headers(request_wrapper) unless CrossAppTracing.cross_app_enabled?
22
27
  metadata.merge!(request_wrapper.instance_variable_get(:@newrelic_metadata))
23
28
  grpc_message = nil
24
29
  grpc_status = 0
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require_relative 'instrumentation'
6
6
 
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  module NewRelic
6
6
  module Agent
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require_relative '../helper'
6
6
 
@@ -11,6 +11,8 @@ module NewRelic
11
11
  module Server
12
12
  include NewRelic::Agent::Instrumentation::GRPC::Helper
13
13
 
14
+ INSTRUMENTATION_NAME = 'gRPC_Server'
15
+
14
16
  DT_KEYS = [NewRelic::NEWRELIC_KEY, NewRelic::TRACEPARENT_KEY, NewRelic::TRACESTATE_KEY].freeze
15
17
  INSTANCE_VAR_HOST = :@host_nr
16
18
  INSTANCE_VAR_PORT = :@port_nr
@@ -23,6 +25,8 @@ module NewRelic
23
25
  def handle_with_tracing(streamer_type, active_call, mth, _inter_ctx)
24
26
  return yield unless trace_with_newrelic?
25
27
 
28
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
29
+
26
30
  metadata = metadata_for_call(active_call)
27
31
  txn = NewRelic::Agent::Transaction.start_new_transaction(NewRelic::Agent::Tracer.state,
28
32
  CATEGORY,
@@ -37,7 +41,7 @@ module NewRelic
37
41
  raise
38
42
  end
39
43
  ensure
40
- txn.finish if txn
44
+ txn&.finish
41
45
  end
42
46
 
43
47
  def add_http2_port_with_tracing(*args)
@@ -55,12 +59,12 @@ module NewRelic
55
59
  def add_attributes(txn, metadata, streamer_type)
56
60
  grpc_params(metadata, streamer_type).each do |attr, value|
57
61
  txn.add_agent_attribute(attr, value, DESTINATIONS)
58
- txn.current_segment.add_agent_attribute(attr, value) if txn.current_segment
62
+ txn.current_segment&.add_agent_attribute(attr, value)
59
63
  end
60
64
  end
61
65
 
62
66
  def metadata_for_call(active_call)
63
- return NewRelic::EMPTY_HASH unless active_call && active_call.metadata
67
+ return NewRelic::EMPTY_HASH unless active_call&.metadata
64
68
 
65
69
  active_call.metadata
66
70
  end
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require_relative 'grpc/client/chain'
6
6
  require_relative 'grpc/client/prepend'
@@ -13,7 +13,7 @@ DependencyDetection.defer do
13
13
  end
14
14
 
15
15
  executes do
16
- supportability_name = 'gRPC_Client'
16
+ supportability_name = NewRelic::Agent::Instrumentation::GRPC::Client::INSTRUMENTATION_NAME
17
17
  if use_prepend?
18
18
  prepend_instrument GRPC::ClientStub, NewRelic::Agent::Instrumentation::GRPC::Client::Prepend, supportability_name
19
19
  else
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require_relative 'grpc/server/chain'
6
6
  require_relative 'grpc/server/rpc_server_prepend'
@@ -14,7 +14,7 @@ DependencyDetection.defer do
14
14
  end
15
15
 
16
16
  executes do
17
- supportability_name = 'gRPC_Server'
17
+ supportability_name = NewRelic::Agent::Instrumentation::GRPC::Client::INSTRUMENTATION_NAME
18
18
  if use_prepend?
19
19
  prepend_instrument GRPC::RpcServer, NewRelic::Agent::Instrumentation::GRPC::Server::RpcServerPrepend, supportability_name
20
20
  prepend_instrument GRPC::RpcDesc, NewRelic::Agent::Instrumentation::GRPC::Server::RpcDescPrepend, supportability_name