newrelic_rpm 8.9.0 → 8.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (377) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +23 -8
  4. data/.rubocop_todo.yml +243 -0
  5. data/.simplecov +10 -2
  6. data/.snyk +11 -0
  7. data/Brewfile +1 -0
  8. data/CHANGELOG.md +78 -0
  9. data/Guardfile +1 -0
  10. data/Rakefile +5 -0
  11. data/Thorfile +6 -0
  12. data/bin/newrelic +2 -1
  13. data/bin/newrelic_cmd +1 -0
  14. data/bin/nrdebug +3 -2
  15. data/init.rb +3 -2
  16. data/install.rb +1 -0
  17. data/lib/new_relic/agent/adaptive_sampler.rb +4 -3
  18. data/lib/new_relic/agent/agent/shutdown.rb +3 -2
  19. data/lib/new_relic/agent/agent/special_startup.rb +3 -2
  20. data/lib/new_relic/agent/agent/start_worker_thread.rb +15 -14
  21. data/lib/new_relic/agent/agent/startup.rb +11 -10
  22. data/lib/new_relic/agent/agent.rb +35 -33
  23. data/lib/new_relic/agent/agent_logger.rb +2 -1
  24. data/lib/new_relic/agent/attribute_filter.rb +1 -0
  25. data/lib/new_relic/agent/attribute_processing.rb +4 -3
  26. data/lib/new_relic/agent/attributes.rb +2 -1
  27. data/lib/new_relic/agent/audit_logger.rb +1 -0
  28. data/lib/new_relic/agent/autostart.rb +1 -0
  29. data/lib/new_relic/agent/chained_call.rb +1 -0
  30. data/lib/new_relic/agent/commands/agent_command.rb +1 -0
  31. data/lib/new_relic/agent/commands/agent_command_router.rb +4 -3
  32. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -0
  33. data/lib/new_relic/agent/configuration/default_source.rb +35 -7
  34. data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -0
  35. data/lib/new_relic/agent/configuration/environment_source.rb +2 -1
  36. data/lib/new_relic/agent/configuration/event_harvest_config.rb +1 -0
  37. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
  38. data/lib/new_relic/agent/configuration/manager.rb +2 -1
  39. data/lib/new_relic/agent/configuration/manual_source.rb +1 -0
  40. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -0
  41. data/lib/new_relic/agent/configuration/security_policy_source.rb +7 -3
  42. data/lib/new_relic/agent/configuration/server_source.rb +7 -6
  43. data/lib/new_relic/agent/configuration/yaml_source.rb +4 -1
  44. data/lib/new_relic/agent/configuration.rb +1 -0
  45. data/lib/new_relic/agent/connect/request_builder.rb +1 -0
  46. data/lib/new_relic/agent/connect/response_handler.rb +4 -3
  47. data/lib/new_relic/agent/custom_event_aggregator.rb +5 -4
  48. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -0
  49. data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -0
  50. data/lib/new_relic/agent/database/obfuscator.rb +2 -1
  51. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -0
  52. data/lib/new_relic/agent/database.rb +3 -2
  53. data/lib/new_relic/agent/database_adapter.rb +1 -0
  54. data/lib/new_relic/agent/datastores/metric_helper.rb +9 -8
  55. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -0
  56. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -0
  57. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +2 -1
  58. data/lib/new_relic/agent/datastores/mongo.rb +1 -0
  59. data/lib/new_relic/agent/datastores/redis.rb +3 -2
  60. data/lib/new_relic/agent/datastores.rb +4 -3
  61. data/lib/new_relic/agent/deprecator.rb +1 -0
  62. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +1 -0
  63. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +16 -16
  64. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +9 -9
  65. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +18 -18
  66. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +8 -8
  67. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +2 -2
  68. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +40 -39
  69. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +16 -14
  70. data/lib/new_relic/agent/distributed_tracing.rb +17 -17
  71. data/lib/new_relic/agent/encoding_normalizer.rb +1 -0
  72. data/lib/new_relic/agent/error_collector.rb +6 -4
  73. data/lib/new_relic/agent/error_event_aggregator.rb +3 -3
  74. data/lib/new_relic/agent/error_filter.rb +1 -0
  75. data/lib/new_relic/agent/error_trace_aggregator.rb +2 -1
  76. data/lib/new_relic/agent/event_aggregator.rb +20 -19
  77. data/lib/new_relic/agent/event_buffer.rb +1 -0
  78. data/lib/new_relic/agent/event_listener.rb +1 -0
  79. data/lib/new_relic/agent/event_loop.rb +7 -6
  80. data/lib/new_relic/agent/external.rb +9 -8
  81. data/lib/new_relic/agent/guid_generator.rb +2 -1
  82. data/lib/new_relic/agent/harvester.rb +1 -0
  83. data/lib/new_relic/agent/heap.rb +3 -2
  84. data/lib/new_relic/agent/hostname.rb +4 -2
  85. data/lib/new_relic/agent/http_clients/abstract.rb +1 -1
  86. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +5 -5
  87. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +4 -4
  88. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +1 -1
  89. data/lib/new_relic/agent/http_clients/uri_util.rb +1 -1
  90. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +6 -4
  91. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +10 -4
  92. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +6 -4
  93. data/lib/new_relic/agent/instrumentation/active_job.rb +2 -1
  94. data/lib/new_relic/agent/instrumentation/active_merchant.rb +2 -1
  95. data/lib/new_relic/agent/instrumentation/active_record.rb +9 -8
  96. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +15 -14
  97. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +3 -2
  98. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +1 -0
  99. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +5 -3
  100. data/lib/new_relic/agent/instrumentation/active_storage.rb +2 -1
  101. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +16 -14
  102. data/lib/new_relic/agent/instrumentation/active_support_logger/chain.rb +1 -0
  103. data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +1 -0
  104. data/lib/new_relic/agent/instrumentation/active_support_logger/prepend.rb +1 -0
  105. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +2 -1
  106. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -1
  107. data/lib/new_relic/agent/instrumentation/authlogic.rb +2 -1
  108. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +10 -9
  109. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +10 -10
  110. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +4 -3
  111. data/lib/new_relic/agent/instrumentation/bunny.rb +1 -1
  112. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +13 -9
  113. data/lib/new_relic/agent/instrumentation/curb/chain.rb +21 -21
  114. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +8 -8
  115. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +2 -2
  116. data/lib/new_relic/agent/instrumentation/curb.rb +2 -1
  117. data/lib/new_relic/agent/instrumentation/data_mapper.rb +43 -42
  118. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +1 -1
  119. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +2 -2
  120. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +1 -1
  121. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +3 -2
  122. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -2
  123. data/lib/new_relic/agent/instrumentation/excon.rb +2 -1
  124. data/lib/new_relic/agent/instrumentation/grape/chain.rb +6 -5
  125. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +5 -4
  126. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +4 -3
  127. data/lib/new_relic/agent/instrumentation/grape.rb +1 -0
  128. data/lib/new_relic/agent/instrumentation/grpc/client/chain.rb +98 -0
  129. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +90 -0
  130. data/lib/new_relic/agent/instrumentation/grpc/client/prepend.rb +112 -0
  131. data/lib/new_relic/agent/instrumentation/grpc/client/request_wrapper.rb +31 -0
  132. data/lib/new_relic/agent/instrumentation/grpc/helper.rb +33 -0
  133. data/lib/new_relic/agent/instrumentation/grpc/server/chain.rb +70 -0
  134. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +135 -0
  135. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_desc_prepend.rb +36 -0
  136. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_server_prepend.rb +27 -0
  137. data/lib/new_relic/agent/instrumentation/grpc_client.rb +24 -0
  138. data/lib/new_relic/agent/instrumentation/grpc_server.rb +26 -0
  139. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +1 -0
  140. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +6 -5
  141. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +1 -0
  142. data/lib/new_relic/agent/instrumentation/httpclient.rb +2 -1
  143. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +1 -0
  144. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +4 -3
  145. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -0
  146. data/lib/new_relic/agent/instrumentation/httprb.rb +2 -1
  147. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -1
  148. data/lib/new_relic/agent/instrumentation/logger/chain.rb +2 -1
  149. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +5 -0
  150. data/lib/new_relic/agent/instrumentation/logger/prepend.rb +1 -0
  151. data/lib/new_relic/agent/instrumentation/logger.rb +2 -1
  152. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +2 -2
  153. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +19 -19
  154. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +8 -8
  155. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +17 -14
  156. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +14 -14
  157. data/lib/new_relic/agent/instrumentation/memcache.rb +1 -1
  158. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +1 -0
  159. data/lib/new_relic/agent/instrumentation/mongo.rb +2 -1
  160. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +14 -12
  161. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +1 -0
  162. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -4
  163. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +1 -0
  164. data/lib/new_relic/agent/instrumentation/net_http.rb +2 -1
  165. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +5 -4
  166. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +1 -0
  167. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +1 -0
  168. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +1 -0
  169. data/lib/new_relic/agent/instrumentation/padrino.rb +2 -1
  170. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +3 -2
  171. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -0
  172. data/lib/new_relic/agent/instrumentation/rack/chain.rb +12 -11
  173. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +1 -0
  174. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +7 -6
  175. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +4 -3
  176. data/lib/new_relic/agent/instrumentation/rack.rb +1 -0
  177. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -5
  178. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -0
  179. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +3 -1
  180. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +3 -1
  181. data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +3 -1
  182. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +3 -2
  183. data/lib/new_relic/agent/instrumentation/rake/chain.rb +2 -1
  184. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +1 -1
  185. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +1 -0
  186. data/lib/new_relic/agent/instrumentation/rake.rb +3 -2
  187. data/lib/new_relic/agent/instrumentation/redis/chain.rb +3 -3
  188. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +5 -5
  189. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +3 -3
  190. data/lib/new_relic/agent/instrumentation/redis.rb +2 -1
  191. data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -1
  192. data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -0
  193. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -0
  194. data/lib/new_relic/agent/instrumentation/resque.rb +3 -2
  195. data/lib/new_relic/agent/instrumentation/sequel.rb +8 -7
  196. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -0
  197. data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -4
  198. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +1 -0
  199. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +2 -1
  200. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +1 -0
  201. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +1 -0
  202. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +2 -1
  203. data/lib/new_relic/agent/instrumentation/sinatra.rb +2 -1
  204. data/lib/new_relic/agent/instrumentation/sunspot.rb +2 -1
  205. data/lib/new_relic/agent/instrumentation/thread/chain.rb +2 -1
  206. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -0
  207. data/lib/new_relic/agent/instrumentation/thread/prepend.rb +1 -0
  208. data/lib/new_relic/agent/instrumentation/thread.rb +2 -1
  209. data/lib/new_relic/agent/instrumentation/tilt/chain.rb +1 -0
  210. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +1 -0
  211. data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +1 -0
  212. data/lib/new_relic/agent/instrumentation/tilt.rb +1 -0
  213. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +1 -0
  214. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +6 -5
  215. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +1 -0
  216. data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -1
  217. data/lib/new_relic/agent/instrumentation.rb +1 -0
  218. data/lib/new_relic/agent/internal_agent_error.rb +1 -0
  219. data/lib/new_relic/agent/javascript_instrumentor.rb +7 -6
  220. data/lib/new_relic/agent/linking_metadata.rb +2 -2
  221. data/lib/new_relic/agent/log_event_aggregator.rb +6 -5
  222. data/lib/new_relic/agent/log_once.rb +1 -0
  223. data/lib/new_relic/agent/log_priority.rb +1 -0
  224. data/lib/new_relic/agent/logging.rb +13 -12
  225. data/lib/new_relic/agent/memory_logger.rb +1 -0
  226. data/lib/new_relic/agent/messaging.rb +18 -18
  227. data/lib/new_relic/agent/method_tracer.rb +6 -5
  228. data/lib/new_relic/agent/method_tracer_helpers.rb +8 -5
  229. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +3 -2
  230. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +3 -2
  231. data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +1 -0
  232. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +2 -1
  233. data/lib/new_relic/agent/monitors.rb +5 -4
  234. data/lib/new_relic/agent/new_relic_service/encoders.rb +2 -1
  235. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +4 -3
  236. data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -0
  237. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -0
  238. data/lib/new_relic/agent/new_relic_service.rb +11 -11
  239. data/lib/new_relic/agent/noticible_error.rb +1 -1
  240. data/lib/new_relic/agent/null_logger.rb +1 -0
  241. data/lib/new_relic/agent/obfuscator.rb +2 -1
  242. data/lib/new_relic/agent/parameter_filtering.rb +1 -0
  243. data/lib/new_relic/agent/payload_metric_mapping.rb +1 -0
  244. data/lib/new_relic/agent/pipe_channel_manager.rb +6 -5
  245. data/lib/new_relic/agent/pipe_service.rb +1 -0
  246. data/lib/new_relic/agent/prepend_supportability.rb +2 -1
  247. data/lib/new_relic/agent/priority_sampled_buffer.rb +2 -1
  248. data/lib/new_relic/agent/range_extensions.rb +8 -27
  249. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +2 -1
  250. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -0
  251. data/lib/new_relic/agent/rules_engine.rb +2 -1
  252. data/lib/new_relic/agent/sampler.rb +1 -0
  253. data/lib/new_relic/agent/sampler_collection.rb +1 -0
  254. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -0
  255. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -0
  256. data/lib/new_relic/agent/samplers/memory_sampler.rb +5 -4
  257. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -0
  258. data/lib/new_relic/agent/samplers/vm_sampler.rb +1 -0
  259. data/lib/new_relic/agent/span_event_aggregator.rb +2 -1
  260. data/lib/new_relic/agent/span_event_primitive.rb +15 -11
  261. data/lib/new_relic/agent/sql_sampler.rb +7 -6
  262. data/lib/new_relic/agent/stats.rb +3 -1
  263. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -0
  264. data/lib/new_relic/agent/stats_engine/stats_hash.rb +3 -2
  265. data/lib/new_relic/agent/stats_engine.rb +1 -0
  266. data/lib/new_relic/agent/synthetics_event_aggregator.rb +6 -5
  267. data/lib/new_relic/agent/system_info.rb +8 -7
  268. data/lib/new_relic/agent/threading/agent_thread.rb +11 -6
  269. data/lib/new_relic/agent/threading/backtrace_node.rb +6 -3
  270. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -0
  271. data/lib/new_relic/agent/threading/thread_profile.rb +1 -0
  272. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -0
  273. data/lib/new_relic/agent/tracer.rb +17 -14
  274. data/lib/new_relic/agent/transaction/abstract_segment.rb +64 -31
  275. data/lib/new_relic/agent/transaction/datastore_segment.rb +12 -11
  276. data/lib/new_relic/agent/transaction/distributed_tracer.rb +52 -47
  277. data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -21
  278. data/lib/new_relic/agent/transaction/external_request_segment.rb +36 -27
  279. data/lib/new_relic/agent/transaction/message_broker_segment.rb +6 -5
  280. data/lib/new_relic/agent/transaction/request_attributes.rb +29 -28
  281. data/lib/new_relic/agent/transaction/segment.rb +8 -7
  282. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -0
  283. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -0
  284. data/lib/new_relic/agent/transaction/trace.rb +3 -2
  285. data/lib/new_relic/agent/transaction/trace_builder.rb +10 -9
  286. data/lib/new_relic/agent/transaction/trace_context.rb +22 -19
  287. data/lib/new_relic/agent/transaction/trace_node.rb +9 -8
  288. data/lib/new_relic/agent/transaction/tracing.rb +7 -6
  289. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -0
  290. data/lib/new_relic/agent/transaction.rb +22 -21
  291. data/lib/new_relic/agent/transaction_error_primitive.rb +9 -8
  292. data/lib/new_relic/agent/transaction_event_aggregator.rb +5 -4
  293. data/lib/new_relic/agent/transaction_event_primitive.rb +3 -3
  294. data/lib/new_relic/agent/transaction_event_recorder.rb +14 -12
  295. data/lib/new_relic/agent/transaction_metrics.rb +3 -2
  296. data/lib/new_relic/agent/transaction_sampler.rb +4 -3
  297. data/lib/new_relic/agent/transaction_time_aggregator.rb +13 -12
  298. data/lib/new_relic/agent/utilization/aws.rb +4 -3
  299. data/lib/new_relic/agent/utilization/azure.rb +1 -0
  300. data/lib/new_relic/agent/utilization/gcp.rb +6 -5
  301. data/lib/new_relic/agent/utilization/pcf.rb +3 -2
  302. data/lib/new_relic/agent/utilization/vendor.rb +27 -26
  303. data/lib/new_relic/agent/utilization_data.rb +1 -0
  304. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -0
  305. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -0
  306. data/lib/new_relic/agent/vm/mri_vm.rb +1 -0
  307. data/lib/new_relic/agent/vm/snapshot.rb +1 -0
  308. data/lib/new_relic/agent/vm.rb +1 -0
  309. data/lib/new_relic/agent/worker_loop.rb +2 -1
  310. data/lib/new_relic/agent.rb +11 -10
  311. data/lib/new_relic/cli/command.rb +5 -4
  312. data/lib/new_relic/cli/commands/deployments.rb +9 -8
  313. data/lib/new_relic/cli/commands/install.rb +6 -5
  314. data/lib/new_relic/coerce.rb +4 -4
  315. data/lib/new_relic/collection_helper.rb +2 -1
  316. data/lib/new_relic/control/class_methods.rb +1 -0
  317. data/lib/new_relic/control/frameworks/external.rb +1 -0
  318. data/lib/new_relic/control/frameworks/rails.rb +3 -2
  319. data/lib/new_relic/control/frameworks/rails3.rb +1 -0
  320. data/lib/new_relic/control/frameworks/rails4.rb +1 -0
  321. data/lib/new_relic/control/frameworks/rails_notifications.rb +1 -0
  322. data/lib/new_relic/control/frameworks/ruby.rb +1 -0
  323. data/lib/new_relic/control/frameworks/sinatra.rb +1 -0
  324. data/lib/new_relic/control/frameworks.rb +1 -0
  325. data/lib/new_relic/control/instance_methods.rb +5 -4
  326. data/lib/new_relic/control/instrumentation.rb +7 -6
  327. data/lib/new_relic/control/server_methods.rb +2 -1
  328. data/lib/new_relic/control.rb +1 -0
  329. data/lib/new_relic/delayed_job_injection.rb +1 -0
  330. data/lib/new_relic/dependency_detection.rb +18 -16
  331. data/lib/new_relic/environment_report.rb +1 -0
  332. data/lib/new_relic/helper.rb +4 -3
  333. data/lib/new_relic/language_support.rb +6 -0
  334. data/lib/new_relic/latest_changes.rb +1 -0
  335. data/lib/new_relic/local_environment.rb +5 -6
  336. data/lib/new_relic/metric_data.rb +3 -2
  337. data/lib/new_relic/metric_spec.rb +2 -1
  338. data/lib/new_relic/noticed_error.rb +1 -1
  339. data/lib/new_relic/rack/agent_hooks.rb +1 -0
  340. data/lib/new_relic/rack/agent_middleware.rb +1 -0
  341. data/lib/new_relic/rack/browser_monitoring.rb +3 -2
  342. data/lib/new_relic/rack.rb +1 -0
  343. data/lib/new_relic/recipes/capistrano3.rb +7 -6
  344. data/lib/new_relic/recipes/capistrano_legacy.rb +12 -11
  345. data/lib/new_relic/recipes.rb +1 -0
  346. data/lib/new_relic/supportability_helper.rb +5 -4
  347. data/lib/new_relic/version.rb +3 -2
  348. data/lib/newrelic_rpm.rb +1 -0
  349. data/lib/sequel/extensions/newrelic_instrumentation.rb +6 -5
  350. data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -0
  351. data/lib/tasks/all.rb +1 -0
  352. data/lib/tasks/config.rake +2 -1
  353. data/lib/tasks/coverage_report.rake +22 -11
  354. data/lib/tasks/install.rake +1 -0
  355. data/lib/tasks/instrumentation_generator/README.md +63 -0
  356. data/lib/tasks/instrumentation_generator/TODO.md +33 -0
  357. data/lib/tasks/instrumentation_generator/instrumentation.thor +96 -0
  358. data/lib/tasks/instrumentation_generator/templates/Envfile.tt +10 -0
  359. data/lib/tasks/instrumentation_generator/templates/chain.tt +22 -0
  360. data/lib/tasks/instrumentation_generator/templates/chain_method.tt +7 -0
  361. data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +30 -0
  362. data/lib/tasks/instrumentation_generator/templates/instrumentation.tt +13 -0
  363. data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +3 -0
  364. data/lib/tasks/instrumentation_generator/templates/newrelic.yml.tt +19 -0
  365. data/lib/tasks/instrumentation_generator/templates/prepend.tt +14 -0
  366. data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +3 -0
  367. data/lib/tasks/instrumentation_generator/templates/test.tt +16 -0
  368. data/lib/tasks/multiverse.rake +1 -0
  369. data/lib/tasks/multiverse.rb +8 -7
  370. data/lib/tasks/newrelic.rb +1 -0
  371. data/lib/tasks/tests.rake +1 -0
  372. data/newrelic.yml +505 -486
  373. data/newrelic_rpm.gemspec +15 -17
  374. data/recipes/newrelic.rb +1 -0
  375. data/test/agent_helper.rb +114 -118
  376. metadata +58 -89
  377. data/bin/mongrel_rpm +0 -32
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'new_relic/agent/rules_engine/replacement_rule'
6
7
  require 'new_relic/agent/rules_engine/segment_terms_rule'
@@ -36,7 +37,7 @@ module NewRelic
36
37
  # Build segment_rules in reverse order from which they're provided,
37
38
  # so that when we eliminate duplicates with #uniq!, we retain the last
38
39
  # instances of repeated rules.
39
- segment_rules.unshift SegmentTermsRule.new(spec)
40
+ segment_rules.unshift(SegmentTermsRule.new(spec))
40
41
  end
41
42
  end
42
43
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
  #
5
6
  # A Sampler is used to capture meaningful metrics in a background thread
6
7
  # periodically. They will be invoked about once a minute, each time the agent
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  module NewRelic
6
7
  module Agent
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'new_relic/agent/sampler'
6
7
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'new_relic/agent/sampler'
6
7
  require 'new_relic/delayed_job_injection'
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'new_relic/agent/sampler'
6
7
  require 'new_relic/helper'
@@ -22,10 +23,10 @@ module NewRelic
22
23
  elsif platform =~ /linux/
23
24
  @sampler = ProcStatus.new
24
25
  if !@sampler.can_run?
25
- ::NewRelic::Agent.logger.debug "Error attempting to use /proc/#{$$}/status file for reading memory. Using ps command instead."
26
+ ::NewRelic::Agent.logger.debug("Error attempting to use /proc/#{$$}/status file for reading memory. Using ps command instead.")
26
27
  @sampler = ShellPS.new("ps -o rsz")
27
28
  else
28
- ::NewRelic::Agent.logger.debug "Using /proc/#{$$}/status for reading process memory."
29
+ ::NewRelic::Agent.logger.debug("Using /proc/#{$$}/status for reading process memory.")
29
30
  end
30
31
  elsif platform =~ /darwin9/ # 10.5
31
32
  @sampler = ShellPS.new("ps -o rsz")
@@ -84,12 +85,12 @@ module NewRelic
84
85
  begin
85
86
  m = get_memory
86
87
  if m.nil?
87
- ::NewRelic::Agent.logger.warn "Unable to get the resident memory for process #{$$}. Disabling memory sampler."
88
+ ::NewRelic::Agent.logger.warn("Unable to get the resident memory for process #{$$}. Disabling memory sampler.")
88
89
  @broken = true
89
90
  end
90
91
  return m
91
92
  rescue => e
92
- ::NewRelic::Agent.logger.warn "Unable to get the resident memory for process #{$$}. Disabling memory sampler.", e
93
+ ::NewRelic::Agent.logger.warn("Unable to get the resident memory for process #{$$}. Disabling memory sampler.", e)
93
94
  @broken = true
94
95
  return nil
95
96
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'new_relic/agent/sampler'
6
7
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'new_relic/agent/sampler'
6
7
  require 'new_relic/agent/vm'
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'newrelic_rpm' unless defined?(NewRelic)
6
7
  require 'new_relic/agent' unless defined?(NewRelic::Agent)
@@ -24,7 +25,7 @@ module NewRelic
24
25
  return unless enabled?
25
26
 
26
27
  @lock.synchronize do
27
- @buffer.append priority: priority, event: event, &blk
28
+ @buffer.append(priority: priority, event: event, &blk)
28
29
  notify_if_full
29
30
  end
30
31
  end
@@ -52,20 +52,20 @@ module NewRelic
52
52
 
53
53
  # Builds a Hash of error attributes as well as the Span ID when
54
54
  # an error is present. Otherwise, returns nil when no error present.
55
- def error_attributes segment
55
+ def error_attributes(segment)
56
56
  return if Agent.config[:high_security] || !segment.noticed_error
57
57
  segment.noticed_error.build_error_attributes
58
58
  segment.noticed_error_attributes
59
59
  end
60
60
 
61
- def for_segment segment
61
+ def for_segment(segment)
62
62
  intrinsics = intrinsics_for(segment)
63
63
  intrinsics[CATEGORY_KEY] = GENERIC_CATEGORY
64
64
 
65
65
  [intrinsics, custom_attributes(segment), agent_attributes(segment)]
66
66
  end
67
67
 
68
- def for_external_request_segment segment
68
+ def for_external_request_segment(segment)
69
69
  intrinsics = intrinsics_for(segment)
70
70
 
71
71
  intrinsics[COMPONENT_KEY] = segment.library
@@ -80,10 +80,14 @@ module NewRelic
80
80
  agent_attributes[HTTP_URL_KEY] = truncate(segment.uri)
81
81
  end
82
82
 
83
+ if segment.respond_to?(:record_agent_attributes?) && segment.record_agent_attributes?
84
+ agent_attributes.merge!(agent_attributes(segment))
85
+ end
86
+
83
87
  [intrinsics, custom_attributes(segment), agent_attributes]
84
88
  end
85
89
 
86
- def for_datastore_segment segment
90
+ def for_datastore_segment(segment)
87
91
  intrinsics = intrinsics_for(segment)
88
92
 
89
93
  intrinsics[COMPONENT_KEY] = segment.product
@@ -113,7 +117,7 @@ module NewRelic
113
117
 
114
118
  private
115
119
 
116
- def intrinsics_for segment
120
+ def intrinsics_for(segment)
117
121
  intrinsics = {
118
122
  TYPE_KEY => EVENT_TYPE,
119
123
  TRACE_ID_KEY => segment.transaction.trace_id,
@@ -155,7 +159,7 @@ module NewRelic
155
159
  intrinsics
156
160
  end
157
161
 
158
- def custom_attributes segment
162
+ def custom_attributes(segment)
159
163
  attributes = segment.attributes
160
164
  if attributes
161
165
  result = attributes.custom_attributes_for(NewRelic::Agent::AttributeFilter::DST_SPAN_EVENTS)
@@ -172,7 +176,7 @@ module NewRelic
172
176
  hash1.merge!(hash2)
173
177
  end
174
178
 
175
- def agent_attributes segment
179
+ def agent_attributes(segment)
176
180
  agent_attributes = segment.attributes
177
181
  .agent_attributes_for(NewRelic::Agent::AttributeFilter::DST_SPAN_EVENTS)
178
182
  error_attributes = error_attributes(segment)
@@ -182,7 +186,7 @@ module NewRelic
182
186
  agent_attributes.freeze
183
187
  end
184
188
 
185
- def parent_guid segment
189
+ def parent_guid(segment)
186
190
  if segment.parent
187
191
  segment.parent.guid
188
192
  elsif txn = segment.transaction
@@ -190,11 +194,11 @@ module NewRelic
190
194
  end
191
195
  end
192
196
 
193
- def milliseconds_since_epoch segment
197
+ def milliseconds_since_epoch(segment)
194
198
  Integer(segment.start_time.to_f * 1000.0)
195
199
  end
196
200
 
197
- def truncate value, max_size = 255
201
+ def truncate(value, max_size = 255)
198
202
  value = value.to_s
199
203
  if value.bytesize > max_size
200
204
  value.byteslice(0, max_size - 2).chop! << ELLIPSIS
@@ -203,7 +207,7 @@ module NewRelic
203
207
  end
204
208
  end
205
209
 
206
- def allowed? key
210
+ def allowed?(key)
207
211
  NewRelic::Agent.instance.attribute_filter.allows_key?(key, AttributeFilter::DST_SPAN_EVENTS)
208
212
  end
209
213
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'zlib'
6
7
  require 'base64'
@@ -74,8 +75,8 @@ module NewRelic
74
75
  data.set_transaction_name(name)
75
76
  if data.sql_data.size > 0
76
77
  @samples_lock.synchronize do
77
- ::NewRelic::Agent.logger.debug "Examining #{data.sql_data.size} slow transaction sql statement(s)"
78
- save_slow_sql data
78
+ ::NewRelic::Agent.logger.debug("Examining #{data.sql_data.size} slow transaction sql statement(s)")
79
+ save_slow_sql(data)
79
80
  end
80
81
  end
81
82
  end
@@ -162,7 +163,7 @@ module NewRelic
162
163
  if transaction && transaction.distributed_tracer.distributed_trace_payload
163
164
  params = {}
164
165
  payload = transaction.distributed_tracer.distributed_trace_payload
165
- DistributedTraceAttributes.copy_from_transaction transaction, payload, params
166
+ DistributedTraceAttributes.copy_from_transaction(transaction, payload, params)
166
167
  params[PRIORITY] = transaction.priority
167
168
  end
168
169
  params
@@ -176,7 +177,7 @@ module NewRelic
176
177
  if state.is_sql_recorded?
177
178
  if duration > Agent.config[:'slow_sql.explain_threshold']
178
179
  backtrace = caller.join("\n")
179
- params = distributed_trace_attributes state
180
+ params = distributed_trace_attributes(state)
180
181
  data.sql_data << SlowSql.new(statement, metric_name, duration, backtrace, params)
181
182
  end
182
183
  end
@@ -300,7 +301,7 @@ module NewRelic
300
301
  super()
301
302
  @params = slow_sql.base_params
302
303
  @sql_id = consistent_hash(normalized_query)
303
- set_primary slow_sql, path, uri
304
+ set_primary(slow_sql, path, uri)
304
305
  record_data_point(float(slow_sql.duration))
305
306
  end
306
307
 
@@ -315,7 +316,7 @@ module NewRelic
315
316
 
316
317
  def aggregate(slow_sql, path, uri)
317
318
  if slow_sql.duration > max_call_time
318
- set_primary slow_sql, path, uri
319
+ set_primary(slow_sql, path, uri)
319
320
  end
320
321
 
321
322
  record_data_point(float(slow_sql.duration))
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
5
+
4
6
  module NewRelic
5
7
  module Agent
6
8
  class Stats
@@ -65,7 +67,7 @@ module NewRelic
65
67
 
66
68
  def record(value = nil, aux = nil, &blk)
67
69
  if blk
68
- yield self
70
+ yield(self)
69
71
  else
70
72
  case value
71
73
  when Numeric
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  # -*- coding: utf-8 -*-
6
7
  module NewRelic
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  # A Hash-like class for storing metric data.
6
7
  #
@@ -76,11 +77,11 @@ module NewRelic
76
77
 
77
78
  def each
78
79
  @scoped.each do |k, v|
79
- yield k, v
80
+ yield(k, v)
80
81
  end
81
82
  @unscoped.each do |k, v|
82
83
  spec = NewRelic::MetricSpec.new(k)
83
- yield spec, v
84
+ yield(spec, v)
84
85
  end
85
86
  end
86
87
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'new_relic/agent/stats_engine/gc_profiler'
6
7
  require 'new_relic/agent/stats_engine/stats_hash'
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
  # This file is distributed under New Relic's license terms.
4
4
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
5
+ # frozen_string_literal: true
5
6
 
6
7
  require 'new_relic/agent/event_aggregator'
7
8
  require 'new_relic/agent/timestamp_sampled_buffer'
@@ -16,21 +17,21 @@ module NewRelic
16
17
  enabled_key :'transaction_events.enabled'
17
18
  buffer_class TimestampSampledBuffer
18
19
 
19
- def record event
20
+ def record(event)
20
21
  return unless enabled?
21
22
 
22
23
  @lock.synchronize do
23
- @buffer.append event: event, priority: -event[0][TIMESTAMP]
24
+ @buffer.append(event: event, priority: -event[0][TIMESTAMP])
24
25
  end
25
26
  end
26
27
 
27
28
  private
28
29
 
29
- def after_harvest metadata
30
- record_dropped_synthetics metadata
30
+ def after_harvest(metadata)
31
+ record_dropped_synthetics(metadata)
31
32
  end
32
33
 
33
- def record_dropped_synthetics metadata
34
+ def record_dropped_synthetics(metadata)
34
35
  num_dropped = metadata[:seen] - metadata[:captured]
35
36
  return unless num_dropped > 0
36
37
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  # This module is intended to provide access to information about the host OS and
6
7
  # [virtual] machine. It intentionally does no caching and maintains no state -
@@ -202,7 +203,7 @@ module NewRelic
202
203
  return
203
204
  when /docker/
204
205
  ::NewRelic::Agent.logger.debug("Cgroup indicates docker but container_id unrecognized: '#{cpu_cgroup}'")
205
- ::NewRelic::Agent.increment_metric "Supportability/utilization/docker/error"
206
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/docker/error")
206
207
  return
207
208
  else
208
209
  ::NewRelic::Agent.logger.debug("Ignoring unrecognized cgroup ID format: '#{cpu_cgroup}'")
@@ -211,7 +212,7 @@ module NewRelic
211
212
 
212
213
  if container_id && container_id.size != 64
213
214
  ::NewRelic::Agent.logger.debug("Found docker container_id with invalid length: #{container_id}")
214
- ::NewRelic::Agent.increment_metric "Supportability/utilization/docker/error"
215
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/docker/error")
215
216
  nil
216
217
  else
217
218
  container_id
@@ -240,7 +241,7 @@ module NewRelic
240
241
  # for details on why we do it this way.
241
242
  def self.proc_try_read(path)
242
243
  return nil unless File.exist?(path)
243
- content = ''
244
+ content = String.new('')
244
245
  File.open(path) do |f|
245
246
  loop do
246
247
  begin
@@ -287,7 +288,7 @@ module NewRelic
287
288
  if bid.ascii_only?
288
289
  if bid.empty?
289
290
  ::NewRelic::Agent.logger.debug("boot_id not found in /proc/sys/kernel/random/boot_id")
290
- ::NewRelic::Agent.increment_metric "Supportability/utilization/boot_id/error"
291
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/boot_id/error")
291
292
  nil
292
293
 
293
294
  elsif bid.bytesize == 36
@@ -295,19 +296,19 @@ module NewRelic
295
296
 
296
297
  else
297
298
  ::NewRelic::Agent.logger.debug("Found boot_id with invalid length: #{bid}")
298
- ::NewRelic::Agent.increment_metric "Supportability/utilization/boot_id/error"
299
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/boot_id/error")
299
300
  bid[0, 128]
300
301
 
301
302
  end
302
303
  else
303
304
  ::NewRelic::Agent.logger.debug("Found boot_id with non-ASCII characters: #{bid}")
304
- ::NewRelic::Agent.increment_metric "Supportability/utilization/boot_id/error"
305
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/boot_id/error")
305
306
  nil
306
307
 
307
308
  end
308
309
  else
309
310
  ::NewRelic::Agent.logger.debug("boot_id not found in /proc/sys/kernel/random/boot_id")
310
- ::NewRelic::Agent.increment_metric "Supportability/utilization/boot_id/error"
311
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/boot_id/error")
311
312
  nil
312
313
 
313
314
  end
@@ -1,27 +1,32 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  module NewRelic
6
7
  module Agent
7
8
  module Threading
8
9
  class AgentThread
9
10
  def self.create(label, &blk)
10
- ::NewRelic::Agent.logger.debug("Creating New Relic thread: #{label}")
11
+ ::NewRelic::Agent.logger.debug("Creating AgentThread: #{label}")
11
12
  wrapped_blk = Proc.new do
13
+ if ::Thread.current[:newrelic_tracer_state] && Thread.current[:newrelic_tracer_state].current_transaction
14
+ txn = ::Thread.current[:newrelic_tracer_state].current_transaction
15
+ ::NewRelic::Agent.logger.warn("AgentThread created with current transaction #{txn.best_name}")
16
+ end
12
17
  begin
13
18
  blk.call
14
19
  rescue => e
15
- ::NewRelic::Agent.logger.error("Thread #{label} exited with error", e)
20
+ ::NewRelic::Agent.logger.error("AgentThread #{label} exited with error", e)
16
21
  rescue Exception => e
17
- ::NewRelic::Agent.logger.error("Thread #{label} exited with exception. Re-raising in case of interrupt.", e)
22
+ ::NewRelic::Agent.logger.error("AgentThread #{label} exited with exception. Re-raising in case of interrupt.", e)
18
23
  raise
19
24
  ensure
20
- ::NewRelic::Agent.logger.debug("Exiting New Relic thread: #{label}")
25
+ ::NewRelic::Agent.logger.debug("Exiting AgentThread: #{label}")
21
26
  end
22
27
  end
23
-
24
- thread = backing_thread_class.new(&wrapped_blk)
28
+ thread = nil
29
+ NewRelic::Agent.disable_all_tracing { thread = backing_thread_class.new(&wrapped_blk) }
25
30
  thread[:newrelic_label] = label
26
31
  thread
27
32
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  module NewRelic
6
7
  module Agent
@@ -18,7 +19,7 @@ module NewRelic
18
19
 
19
20
  def add_child_unless_present(child)
20
21
  child.depth = @depth + 1
21
- @children << child unless @children.include? child
22
+ @children << child unless @children.include?(child)
22
23
  end
23
24
 
24
25
  def add_child(child)
@@ -70,7 +71,7 @@ module NewRelic
70
71
  end
71
72
 
72
73
  def dump_string
73
- result = "#<BacktraceRoot:#{object_id}>"
74
+ result = String.new("#<BacktraceRoot:#{object_id}>")
74
75
  child_results = @children.map { |c| c.dump_string(2) }.join("\n")
75
76
  result << "\n" unless child_results.empty?
76
77
  result << child_results
@@ -115,7 +116,9 @@ module NewRelic
115
116
 
116
117
  def dump_string(indent = 0)
117
118
  @file, @method, @line_no = parse_backtrace_frame(@raw_line)
118
- result = "#{" " * indent}#<BacktraceNode:#{object_id} [#{@runnable_count}] #{@file}:#{@line_no} in #{@method}>"
119
+ indentation = ' ' * indent
120
+ result = String.new("#{indentation}#<BacktraceNode:#{object_id} ) + \
121
+ [#{@runnable_count}] #{@file}:#{@line_no} in #{@method}>")
119
122
  child_results = @children.map { |c| c.dump_string(indent + 2) }.join("\n")
120
123
  result << "\n" unless child_results.empty?
121
124
  result << child_results
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  module NewRelic
6
7
  module Agent
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'set'
6
7
  require 'new_relic/agent/worker_loop'
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'new_relic/agent/heap'
6
7
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
6
  require 'new_relic/agent/transaction'
6
7
  require 'new_relic/agent/transaction/segment'
@@ -234,8 +235,8 @@ module NewRelic
234
235
  start_time: nil,
235
236
  parent: nil)
236
237
 
237
- segment = Transaction::Segment.new name, unscoped_metrics, start_time
238
- start_and_add_segment segment, parent
238
+ segment = Transaction::Segment.new(name, unscoped_metrics, start_time)
239
+ start_and_add_segment(segment, parent)
239
240
  rescue ArgumentError
240
241
  raise
241
242
  rescue => exception
@@ -292,8 +293,8 @@ module NewRelic
292
293
  product ||= UNKNOWN
293
294
  operation ||= OTHER
294
295
 
295
- segment = Transaction::DatastoreSegment.new product, operation, collection, host, port_path_or_id, database_name
296
- start_and_add_segment segment, parent
296
+ segment = Transaction::DatastoreSegment.new(product, operation, collection, host, port_path_or_id, database_name)
297
+ start_and_add_segment(segment, parent)
297
298
  rescue ArgumentError
298
299
  raise
299
300
  rescue => exception
@@ -333,8 +334,8 @@ module NewRelic
333
334
  start_time: nil,
334
335
  parent: nil)
335
336
 
336
- segment = Transaction::ExternalRequestSegment.new library, uri, procedure, start_time
337
- start_and_add_segment segment, parent
337
+ segment = Transaction::ExternalRequestSegment.new(library, uri, procedure, start_time)
338
+ start_and_add_segment(segment, parent)
338
339
  rescue ArgumentError
339
340
  raise
340
341
  rescue => exception
@@ -346,12 +347,12 @@ module NewRelic
346
347
  # if passed +segment+ is something that doesn't
347
348
  # respond to +notice_segment_error+ then this method
348
349
  # is effectively just a yield to the given &block
349
- def capture_segment_error segment
350
+ def capture_segment_error(segment)
350
351
  return unless block_given?
351
352
  yield
352
353
  rescue => exception
353
354
  if segment && segment.is_a?(Transaction::AbstractSegment)
354
- segment.notice_error exception
355
+ segment.notice_error(exception)
355
356
  end
356
357
  raise
357
358
  end
@@ -375,7 +376,7 @@ module NewRelic
375
376
  parameters: parameters,
376
377
  start_time: start_time
377
378
  )
378
- start_and_add_segment segment, parent
379
+ start_and_add_segment(segment, parent)
379
380
  rescue ArgumentError
380
381
  raise
381
382
  rescue => exception
@@ -406,11 +407,13 @@ module NewRelic
406
407
  alias_method :tl_clear, :clear_state
407
408
 
408
409
  def thread_block_with_current_transaction(*args, &block)
409
- current_txn = ::Thread.current[:newrelic_tracer_state].current_transaction if ::Thread.current[:newrelic_tracer_state]
410
+ current_txn = ::Thread.current[:newrelic_tracer_state].current_transaction if ::Thread.current[:newrelic_tracer_state] && ::Thread.current[:newrelic_tracer_state].is_execution_traced?
410
411
  Proc.new do
411
412
  begin
412
- NewRelic::Agent::Tracer.state.current_transaction = current_txn
413
- segment = NewRelic::Agent::Tracer.start_segment(name: "Ruby/Thread/#{::Thread.current.object_id}")
413
+ if current_txn
414
+ NewRelic::Agent::Tracer.state.current_transaction = current_txn
415
+ segment = NewRelic::Agent::Tracer.start_segment(name: "Ruby/Thread/#{::Thread.current.object_id}")
416
+ end
414
417
  block.call(*args) if block.respond_to?(:call)
415
418
  ensure
416
419
  segment.finish if segment
@@ -420,11 +423,11 @@ module NewRelic
420
423
 
421
424
  private
422
425
 
423
- def start_and_add_segment segment, parent = nil
426
+ def start_and_add_segment(segment, parent = nil)
424
427
  tracer_state = state
425
428
  if (txn = tracer_state.current_transaction) &&
426
429
  tracer_state.tracing_enabled?
427
- txn.add_segment segment, parent
430
+ txn.add_segment(segment, parent)
428
431
  else
429
432
  segment.record_metrics = false
430
433
  end