newrelic_rpm 8.9.0 → 8.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (361) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -6
  3. data/.simplecov +1 -0
  4. data/.snyk +11 -0
  5. data/Brewfile +1 -0
  6. data/CHANGELOG.md +56 -0
  7. data/Guardfile +1 -0
  8. data/Rakefile +5 -0
  9. data/bin/mongrel_rpm +7 -6
  10. data/bin/newrelic +2 -1
  11. data/bin/newrelic_cmd +1 -0
  12. data/bin/nrdebug +3 -2
  13. data/init.rb +3 -2
  14. data/install.rb +1 -0
  15. data/lib/new_relic/agent/adaptive_sampler.rb +4 -3
  16. data/lib/new_relic/agent/agent/shutdown.rb +3 -2
  17. data/lib/new_relic/agent/agent/special_startup.rb +3 -2
  18. data/lib/new_relic/agent/agent/start_worker_thread.rb +15 -14
  19. data/lib/new_relic/agent/agent/startup.rb +11 -10
  20. data/lib/new_relic/agent/agent.rb +35 -33
  21. data/lib/new_relic/agent/agent_logger.rb +2 -1
  22. data/lib/new_relic/agent/attribute_filter.rb +1 -0
  23. data/lib/new_relic/agent/attribute_processing.rb +4 -3
  24. data/lib/new_relic/agent/attributes.rb +2 -1
  25. data/lib/new_relic/agent/audit_logger.rb +1 -0
  26. data/lib/new_relic/agent/autostart.rb +1 -0
  27. data/lib/new_relic/agent/chained_call.rb +1 -0
  28. data/lib/new_relic/agent/commands/agent_command.rb +1 -0
  29. data/lib/new_relic/agent/commands/agent_command_router.rb +4 -3
  30. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -0
  31. data/lib/new_relic/agent/configuration/default_source.rb +35 -7
  32. data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -0
  33. data/lib/new_relic/agent/configuration/environment_source.rb +2 -1
  34. data/lib/new_relic/agent/configuration/event_harvest_config.rb +1 -0
  35. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
  36. data/lib/new_relic/agent/configuration/manager.rb +2 -1
  37. data/lib/new_relic/agent/configuration/manual_source.rb +1 -0
  38. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -0
  39. data/lib/new_relic/agent/configuration/security_policy_source.rb +7 -3
  40. data/lib/new_relic/agent/configuration/server_source.rb +7 -6
  41. data/lib/new_relic/agent/configuration/yaml_source.rb +4 -1
  42. data/lib/new_relic/agent/configuration.rb +1 -0
  43. data/lib/new_relic/agent/connect/request_builder.rb +1 -0
  44. data/lib/new_relic/agent/connect/response_handler.rb +4 -3
  45. data/lib/new_relic/agent/custom_event_aggregator.rb +5 -4
  46. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -0
  47. data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -0
  48. data/lib/new_relic/agent/database/obfuscator.rb +2 -1
  49. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -0
  50. data/lib/new_relic/agent/database.rb +3 -2
  51. data/lib/new_relic/agent/database_adapter.rb +1 -0
  52. data/lib/new_relic/agent/datastores/metric_helper.rb +9 -8
  53. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -0
  54. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -0
  55. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +2 -1
  56. data/lib/new_relic/agent/datastores/mongo.rb +1 -0
  57. data/lib/new_relic/agent/datastores/redis.rb +3 -2
  58. data/lib/new_relic/agent/datastores.rb +4 -3
  59. data/lib/new_relic/agent/deprecator.rb +1 -0
  60. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +1 -0
  61. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +16 -16
  62. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +9 -9
  63. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +18 -18
  64. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +8 -8
  65. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +2 -2
  66. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +40 -39
  67. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +16 -14
  68. data/lib/new_relic/agent/distributed_tracing.rb +17 -17
  69. data/lib/new_relic/agent/encoding_normalizer.rb +1 -0
  70. data/lib/new_relic/agent/error_collector.rb +6 -4
  71. data/lib/new_relic/agent/error_event_aggregator.rb +3 -3
  72. data/lib/new_relic/agent/error_filter.rb +1 -0
  73. data/lib/new_relic/agent/error_trace_aggregator.rb +2 -1
  74. data/lib/new_relic/agent/event_aggregator.rb +20 -19
  75. data/lib/new_relic/agent/event_buffer.rb +1 -0
  76. data/lib/new_relic/agent/event_listener.rb +1 -0
  77. data/lib/new_relic/agent/event_loop.rb +7 -6
  78. data/lib/new_relic/agent/external.rb +9 -8
  79. data/lib/new_relic/agent/guid_generator.rb +2 -1
  80. data/lib/new_relic/agent/harvester.rb +1 -0
  81. data/lib/new_relic/agent/heap.rb +3 -2
  82. data/lib/new_relic/agent/hostname.rb +4 -2
  83. data/lib/new_relic/agent/http_clients/abstract.rb +1 -1
  84. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +5 -5
  85. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +4 -4
  86. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +1 -1
  87. data/lib/new_relic/agent/http_clients/uri_util.rb +1 -1
  88. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +6 -4
  89. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +2 -0
  90. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +6 -4
  91. data/lib/new_relic/agent/instrumentation/active_job.rb +2 -1
  92. data/lib/new_relic/agent/instrumentation/active_merchant.rb +2 -1
  93. data/lib/new_relic/agent/instrumentation/active_record.rb +9 -8
  94. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +15 -14
  95. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +3 -2
  96. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +1 -0
  97. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +5 -3
  98. data/lib/new_relic/agent/instrumentation/active_storage.rb +2 -1
  99. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +16 -14
  100. data/lib/new_relic/agent/instrumentation/active_support_logger/chain.rb +1 -0
  101. data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +1 -0
  102. data/lib/new_relic/agent/instrumentation/active_support_logger/prepend.rb +1 -0
  103. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +2 -1
  104. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -1
  105. data/lib/new_relic/agent/instrumentation/authlogic.rb +2 -1
  106. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +10 -9
  107. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +10 -10
  108. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +4 -3
  109. data/lib/new_relic/agent/instrumentation/bunny.rb +1 -1
  110. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +13 -9
  111. data/lib/new_relic/agent/instrumentation/curb/chain.rb +21 -21
  112. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +8 -8
  113. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +2 -2
  114. data/lib/new_relic/agent/instrumentation/curb.rb +2 -1
  115. data/lib/new_relic/agent/instrumentation/data_mapper.rb +43 -42
  116. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +1 -1
  117. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +2 -2
  118. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +1 -1
  119. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +3 -2
  120. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -2
  121. data/lib/new_relic/agent/instrumentation/excon.rb +2 -1
  122. data/lib/new_relic/agent/instrumentation/grape/chain.rb +6 -5
  123. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +5 -4
  124. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +4 -3
  125. data/lib/new_relic/agent/instrumentation/grape.rb +1 -0
  126. data/lib/new_relic/agent/instrumentation/grpc/client/chain.rb +106 -0
  127. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +88 -0
  128. data/lib/new_relic/agent/instrumentation/grpc/client/prepend.rb +117 -0
  129. data/lib/new_relic/agent/instrumentation/grpc/client/request_wrapper.rb +31 -0
  130. data/lib/new_relic/agent/instrumentation/grpc/helper.rb +31 -0
  131. data/lib/new_relic/agent/instrumentation/grpc/server/chain.rb +70 -0
  132. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +135 -0
  133. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_desc_prepend.rb +36 -0
  134. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_server_prepend.rb +27 -0
  135. data/lib/new_relic/agent/instrumentation/grpc_client.rb +24 -0
  136. data/lib/new_relic/agent/instrumentation/grpc_server.rb +26 -0
  137. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +1 -0
  138. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +6 -5
  139. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +1 -0
  140. data/lib/new_relic/agent/instrumentation/httpclient.rb +2 -1
  141. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +1 -0
  142. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +4 -3
  143. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -0
  144. data/lib/new_relic/agent/instrumentation/httprb.rb +2 -1
  145. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -1
  146. data/lib/new_relic/agent/instrumentation/logger/chain.rb +2 -1
  147. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +5 -0
  148. data/lib/new_relic/agent/instrumentation/logger/prepend.rb +1 -0
  149. data/lib/new_relic/agent/instrumentation/logger.rb +2 -1
  150. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +2 -2
  151. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +19 -19
  152. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +8 -8
  153. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +17 -14
  154. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +14 -14
  155. data/lib/new_relic/agent/instrumentation/memcache.rb +1 -1
  156. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +1 -0
  157. data/lib/new_relic/agent/instrumentation/mongo.rb +2 -1
  158. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +14 -12
  159. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +1 -0
  160. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -4
  161. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +1 -0
  162. data/lib/new_relic/agent/instrumentation/net_http.rb +2 -1
  163. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +5 -4
  164. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +1 -0
  165. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +1 -0
  166. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +1 -0
  167. data/lib/new_relic/agent/instrumentation/padrino.rb +2 -1
  168. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +3 -2
  169. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -0
  170. data/lib/new_relic/agent/instrumentation/rack/chain.rb +12 -11
  171. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +1 -0
  172. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +7 -6
  173. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +4 -3
  174. data/lib/new_relic/agent/instrumentation/rack.rb +1 -0
  175. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -5
  176. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -0
  177. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +3 -1
  178. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +3 -1
  179. data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +3 -1
  180. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +3 -2
  181. data/lib/new_relic/agent/instrumentation/rake/chain.rb +2 -1
  182. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +1 -1
  183. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +1 -0
  184. data/lib/new_relic/agent/instrumentation/rake.rb +3 -2
  185. data/lib/new_relic/agent/instrumentation/redis/chain.rb +3 -3
  186. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +5 -5
  187. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +3 -3
  188. data/lib/new_relic/agent/instrumentation/redis.rb +2 -1
  189. data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -1
  190. data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -0
  191. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -0
  192. data/lib/new_relic/agent/instrumentation/resque.rb +3 -2
  193. data/lib/new_relic/agent/instrumentation/sequel.rb +8 -7
  194. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -0
  195. data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -4
  196. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +1 -0
  197. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +2 -1
  198. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +1 -0
  199. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +1 -0
  200. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +2 -1
  201. data/lib/new_relic/agent/instrumentation/sinatra.rb +2 -1
  202. data/lib/new_relic/agent/instrumentation/sunspot.rb +2 -1
  203. data/lib/new_relic/agent/instrumentation/thread/chain.rb +2 -1
  204. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -0
  205. data/lib/new_relic/agent/instrumentation/thread/prepend.rb +1 -0
  206. data/lib/new_relic/agent/instrumentation/thread.rb +2 -1
  207. data/lib/new_relic/agent/instrumentation/tilt/chain.rb +1 -0
  208. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +1 -0
  209. data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +1 -0
  210. data/lib/new_relic/agent/instrumentation/tilt.rb +1 -0
  211. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +1 -0
  212. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +6 -5
  213. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +1 -0
  214. data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -1
  215. data/lib/new_relic/agent/instrumentation.rb +1 -0
  216. data/lib/new_relic/agent/internal_agent_error.rb +1 -0
  217. data/lib/new_relic/agent/javascript_instrumentor.rb +7 -6
  218. data/lib/new_relic/agent/linking_metadata.rb +2 -2
  219. data/lib/new_relic/agent/log_event_aggregator.rb +6 -5
  220. data/lib/new_relic/agent/log_once.rb +1 -0
  221. data/lib/new_relic/agent/log_priority.rb +1 -0
  222. data/lib/new_relic/agent/logging.rb +13 -12
  223. data/lib/new_relic/agent/memory_logger.rb +1 -0
  224. data/lib/new_relic/agent/messaging.rb +18 -18
  225. data/lib/new_relic/agent/method_tracer.rb +6 -5
  226. data/lib/new_relic/agent/method_tracer_helpers.rb +8 -5
  227. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +3 -2
  228. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +3 -2
  229. data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +1 -0
  230. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +2 -1
  231. data/lib/new_relic/agent/monitors.rb +5 -4
  232. data/lib/new_relic/agent/new_relic_service/encoders.rb +2 -1
  233. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +4 -3
  234. data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -0
  235. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -0
  236. data/lib/new_relic/agent/new_relic_service.rb +11 -11
  237. data/lib/new_relic/agent/noticible_error.rb +1 -1
  238. data/lib/new_relic/agent/null_logger.rb +1 -0
  239. data/lib/new_relic/agent/obfuscator.rb +2 -1
  240. data/lib/new_relic/agent/parameter_filtering.rb +1 -0
  241. data/lib/new_relic/agent/payload_metric_mapping.rb +1 -0
  242. data/lib/new_relic/agent/pipe_channel_manager.rb +6 -5
  243. data/lib/new_relic/agent/pipe_service.rb +1 -0
  244. data/lib/new_relic/agent/prepend_supportability.rb +2 -1
  245. data/lib/new_relic/agent/priority_sampled_buffer.rb +2 -1
  246. data/lib/new_relic/agent/range_extensions.rb +8 -27
  247. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +2 -1
  248. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -0
  249. data/lib/new_relic/agent/rules_engine.rb +2 -1
  250. data/lib/new_relic/agent/sampler.rb +1 -0
  251. data/lib/new_relic/agent/sampler_collection.rb +1 -0
  252. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -0
  253. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -0
  254. data/lib/new_relic/agent/samplers/memory_sampler.rb +5 -4
  255. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -0
  256. data/lib/new_relic/agent/samplers/vm_sampler.rb +1 -0
  257. data/lib/new_relic/agent/span_event_aggregator.rb +2 -1
  258. data/lib/new_relic/agent/span_event_primitive.rb +15 -11
  259. data/lib/new_relic/agent/sql_sampler.rb +7 -6
  260. data/lib/new_relic/agent/stats.rb +3 -1
  261. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -0
  262. data/lib/new_relic/agent/stats_engine/stats_hash.rb +3 -2
  263. data/lib/new_relic/agent/stats_engine.rb +1 -0
  264. data/lib/new_relic/agent/synthetics_event_aggregator.rb +6 -5
  265. data/lib/new_relic/agent/system_info.rb +8 -7
  266. data/lib/new_relic/agent/threading/agent_thread.rb +1 -0
  267. data/lib/new_relic/agent/threading/backtrace_node.rb +6 -3
  268. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -0
  269. data/lib/new_relic/agent/threading/thread_profile.rb +1 -0
  270. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -0
  271. data/lib/new_relic/agent/tracer.rb +12 -11
  272. data/lib/new_relic/agent/transaction/abstract_segment.rb +64 -31
  273. data/lib/new_relic/agent/transaction/datastore_segment.rb +12 -11
  274. data/lib/new_relic/agent/transaction/distributed_tracer.rb +52 -47
  275. data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -21
  276. data/lib/new_relic/agent/transaction/external_request_segment.rb +36 -27
  277. data/lib/new_relic/agent/transaction/message_broker_segment.rb +6 -5
  278. data/lib/new_relic/agent/transaction/request_attributes.rb +29 -28
  279. data/lib/new_relic/agent/transaction/segment.rb +8 -7
  280. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -0
  281. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -0
  282. data/lib/new_relic/agent/transaction/trace.rb +3 -2
  283. data/lib/new_relic/agent/transaction/trace_builder.rb +10 -9
  284. data/lib/new_relic/agent/transaction/trace_context.rb +22 -19
  285. data/lib/new_relic/agent/transaction/trace_node.rb +9 -8
  286. data/lib/new_relic/agent/transaction/tracing.rb +7 -6
  287. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -0
  288. data/lib/new_relic/agent/transaction.rb +22 -21
  289. data/lib/new_relic/agent/transaction_error_primitive.rb +9 -8
  290. data/lib/new_relic/agent/transaction_event_aggregator.rb +5 -4
  291. data/lib/new_relic/agent/transaction_event_primitive.rb +3 -3
  292. data/lib/new_relic/agent/transaction_event_recorder.rb +14 -12
  293. data/lib/new_relic/agent/transaction_metrics.rb +3 -2
  294. data/lib/new_relic/agent/transaction_sampler.rb +4 -3
  295. data/lib/new_relic/agent/transaction_time_aggregator.rb +13 -12
  296. data/lib/new_relic/agent/utilization/aws.rb +4 -3
  297. data/lib/new_relic/agent/utilization/azure.rb +1 -0
  298. data/lib/new_relic/agent/utilization/gcp.rb +6 -5
  299. data/lib/new_relic/agent/utilization/pcf.rb +3 -2
  300. data/lib/new_relic/agent/utilization/vendor.rb +27 -26
  301. data/lib/new_relic/agent/utilization_data.rb +1 -0
  302. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -0
  303. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -0
  304. data/lib/new_relic/agent/vm/mri_vm.rb +1 -0
  305. data/lib/new_relic/agent/vm/snapshot.rb +1 -0
  306. data/lib/new_relic/agent/vm.rb +1 -0
  307. data/lib/new_relic/agent/worker_loop.rb +2 -1
  308. data/lib/new_relic/agent.rb +11 -10
  309. data/lib/new_relic/cli/command.rb +5 -4
  310. data/lib/new_relic/cli/commands/deployments.rb +9 -8
  311. data/lib/new_relic/cli/commands/install.rb +6 -5
  312. data/lib/new_relic/coerce.rb +4 -4
  313. data/lib/new_relic/collection_helper.rb +2 -1
  314. data/lib/new_relic/control/class_methods.rb +1 -0
  315. data/lib/new_relic/control/frameworks/external.rb +1 -0
  316. data/lib/new_relic/control/frameworks/rails.rb +3 -2
  317. data/lib/new_relic/control/frameworks/rails3.rb +1 -0
  318. data/lib/new_relic/control/frameworks/rails4.rb +1 -0
  319. data/lib/new_relic/control/frameworks/rails_notifications.rb +1 -0
  320. data/lib/new_relic/control/frameworks/ruby.rb +1 -0
  321. data/lib/new_relic/control/frameworks/sinatra.rb +1 -0
  322. data/lib/new_relic/control/frameworks.rb +1 -0
  323. data/lib/new_relic/control/instance_methods.rb +5 -4
  324. data/lib/new_relic/control/instrumentation.rb +7 -6
  325. data/lib/new_relic/control/server_methods.rb +2 -1
  326. data/lib/new_relic/control.rb +1 -0
  327. data/lib/new_relic/delayed_job_injection.rb +1 -0
  328. data/lib/new_relic/dependency_detection.rb +18 -16
  329. data/lib/new_relic/environment_report.rb +1 -0
  330. data/lib/new_relic/helper.rb +4 -3
  331. data/lib/new_relic/language_support.rb +1 -0
  332. data/lib/new_relic/latest_changes.rb +1 -0
  333. data/lib/new_relic/local_environment.rb +5 -6
  334. data/lib/new_relic/metric_data.rb +3 -2
  335. data/lib/new_relic/metric_spec.rb +2 -1
  336. data/lib/new_relic/noticed_error.rb +1 -1
  337. data/lib/new_relic/rack/agent_hooks.rb +1 -0
  338. data/lib/new_relic/rack/agent_middleware.rb +1 -0
  339. data/lib/new_relic/rack/browser_monitoring.rb +3 -2
  340. data/lib/new_relic/rack.rb +1 -0
  341. data/lib/new_relic/recipes/capistrano3.rb +7 -6
  342. data/lib/new_relic/recipes/capistrano_legacy.rb +12 -11
  343. data/lib/new_relic/recipes.rb +1 -0
  344. data/lib/new_relic/supportability_helper.rb +5 -4
  345. data/lib/new_relic/version.rb +2 -1
  346. data/lib/newrelic_rpm.rb +1 -0
  347. data/lib/sequel/extensions/newrelic_instrumentation.rb +6 -5
  348. data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -0
  349. data/lib/tasks/all.rb +1 -0
  350. data/lib/tasks/config.rake +2 -1
  351. data/lib/tasks/coverage_report.rake +2 -1
  352. data/lib/tasks/install.rake +1 -0
  353. data/lib/tasks/multiverse.rake +1 -0
  354. data/lib/tasks/multiverse.rb +8 -7
  355. data/lib/tasks/newrelic.rb +1 -0
  356. data/lib/tasks/tests.rake +1 -0
  357. data/newrelic.yml +505 -486
  358. data/newrelic_rpm.gemspec +3 -1
  359. data/recipes/newrelic.rb +1 -0
  360. data/test/agent_helper.rb +113 -103
  361. metadata +28 -2
@@ -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,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
  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
@@ -420,11 +421,11 @@ module NewRelic
420
421
 
421
422
  private
422
423
 
423
- def start_and_add_segment segment, parent = nil
424
+ def start_and_add_segment(segment, parent = nil)
424
425
  tracer_state = state
425
426
  if (txn = tracer_state.current_transaction) &&
426
427
  tracer_state.tracing_enabled?
427
- txn.add_segment segment, parent
428
+ txn.add_segment(segment, parent)
428
429
  else
429
430
  segment.record_metrics = false
430
431
  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/range_extensions'
6
7
  require 'new_relic/agent/guid_generator'
@@ -25,7 +26,7 @@ module NewRelic
25
26
  attr_writer :record_metrics, :record_scoped_metric, :record_on_finish
26
27
  attr_reader :noticed_error
27
28
 
28
- def initialize name = nil, start_time = nil
29
+ def initialize(name = nil, start_time = nil)
29
30
  @name = name
30
31
  @starting_thread_id = ::Thread.current.object_id
31
32
  @transaction_name = nil
@@ -37,8 +38,8 @@ module NewRelic
37
38
  @end_time = nil
38
39
  @duration = 0.0
39
40
  @exclusive_duration = 0.0
41
+ @children_timings = []
40
42
  @children_time = 0.0
41
- @children_time_ranges = nil
42
43
  @active_children = 0
43
44
  @range_recorded = false
44
45
  @concurrent_children = false
@@ -55,7 +56,7 @@ module NewRelic
55
56
  def start
56
57
  @start_time ||= Process.clock_gettime(Process::CLOCK_REALTIME)
57
58
  return unless transaction
58
- parent.child_start self if parent
59
+ parent.child_start(self) if parent
59
60
  end
60
61
 
61
62
  def finish
@@ -66,7 +67,7 @@ module NewRelic
66
67
  run_complete_callbacks
67
68
  finalize if record_on_finish?
68
69
  rescue => e
69
- NewRelic::Agent.logger.error "Exception finishing segment: #{name}", e
70
+ NewRelic::Agent.logger.error("Exception finishing segment: #{name}", e)
70
71
  end
71
72
 
72
73
  def finished?
@@ -103,12 +104,40 @@ module NewRelic
103
104
  @start_time.to_f..@end_time.to_f
104
105
  end
105
106
 
107
+ def timings_overlap?(timing1, timing2)
108
+ (timing1.first >= timing2.first && timing1.first <= timing2.last) ||
109
+ (timing2.first >= timing1.first && timing2.first <= timing1.last)
110
+ end
111
+
112
+ def merge_timings(timing1, timing2)
113
+ [(timing1.first < timing2.first ? timing1.first : timing2.first),
114
+ (timing1.last > timing2.last ? timing1.last : timing2.last)]
115
+ end
116
+
117
+ # @children_timings is an array of array, with each inner array
118
+ # holding exactly 2 values, a child segment's start time and finish
119
+ # time (in that order). When it's time to record, these timings are
120
+ # converted into an array of range objects (using the same start and
121
+ # end values as the original array). Any two range objects that
122
+ # intersect and merged into a larger range. This checking for a
123
+ # intersections and merging of ranges is expensive, so the operation
124
+ # is only done at recording time.
106
125
  def children_time_ranges
107
- @children_time_ranges ||= []
126
+ @children_time_ranges ||= begin
127
+ overlapped = @children_timings.each_with_object([]) do |timing, timings|
128
+ i = timings.index { |t| timings_overlap?(t, timing) }
129
+ if i
130
+ timings[i] = merge_timings(timing, timings[i])
131
+ else
132
+ timings << timing
133
+ end
134
+ end
135
+ overlapped.map { |t| Range.new(t.first, t.last) }
136
+ end
108
137
  end
109
138
 
110
139
  def children_time_ranges?
111
- !!@children_time_ranges
140
+ !@children_timings.empty?
112
141
  end
113
142
 
114
143
  def concurrent_children?
@@ -150,22 +179,24 @@ module NewRelic
150
179
  def transaction_assigned
151
180
  end
152
181
 
153
- def set_noticed_error noticed_error
182
+ def set_noticed_error(noticed_error)
154
183
  if @noticed_error
155
- NewRelic::Agent.logger.debug \
184
+ NewRelic::Agent.logger.debug( \
156
185
  "Segment: #{name} overwriting previously noticed " \
157
186
  "error: #{@noticed_error.inspect} with: #{noticed_error.inspect}"
187
+ )
158
188
  end
159
189
  @noticed_error = noticed_error
160
190
  end
161
191
 
162
- def notice_error exception, options = {}
192
+ def notice_error(exception, options = {})
163
193
  if Agent.config[:high_security]
164
- NewRelic::Agent.logger.debug \
194
+ NewRelic::Agent.logger.debug( \
165
195
  "Segment: #{name} ignores notice_error for " \
166
196
  "error: #{exception.inspect} because :high_security is enabled"
197
+ )
167
198
  else
168
- NewRelic::Agent.instance.error_collector.notice_segment_error self, exception, options
199
+ NewRelic::Agent.instance.error_collector.notice_segment_error(self, exception, options)
169
200
  end
170
201
  end
171
202
 
@@ -182,16 +213,16 @@ module NewRelic
182
213
  @range_recorded
183
214
  end
184
215
 
185
- def child_start segment
216
+ def child_start(segment)
186
217
  @active_children += 1
187
218
  @concurrent_children ||= @active_children > 1
188
219
 
189
220
  transaction.async = true if @concurrent_children
190
221
  end
191
222
 
192
- def child_complete segment
223
+ def child_complete(segment)
193
224
  @active_children -= 1
194
- record_child_time segment
225
+ record_child_time(segment)
195
226
 
196
227
  if finished?
197
228
  transaction.async = true
@@ -205,36 +236,39 @@ module NewRelic
205
236
  # an ancestor whose end time is greater than or equal to the descendant's
206
237
  # we can stop the propagation. We pass along the direct child so we can
207
238
  # make any corrections needed for exclusive time calculation.
239
+ def descendant_complete(child, descendant)
240
+ add_child_timing(descendant)
208
241
 
209
- def descendant_complete child, descendant
210
- RangeExtensions.merge_or_append descendant.time_range,
211
- children_time_ranges
212
242
  # If this child's time was previously added to this segment's
213
243
  # aggregate children time, we need to re-record it using a time range
214
244
  # for proper exclusive time calculation
215
245
  unless child.range_recorded?
216
246
  self.children_time -= child.duration
217
- record_child_time_as_range child
247
+ record_child_time_as_range(child)
218
248
  end
219
249
 
220
250
  if parent && finished? && descendant.end_time >= end_time
221
- parent.descendant_complete self, descendant
251
+ parent.descendant_complete(self, descendant)
222
252
  end
223
253
  end
224
254
 
225
255
  private
226
256
 
257
+ def add_child_timing(segment)
258
+ @children_timings << [segment.start_time, segment.end_time]
259
+ end
260
+
227
261
  def force_finish
228
262
  finish
229
- NewRelic::Agent.logger.warn "Segment: #{name} was unfinished at " \
263
+ NewRelic::Agent.logger.warn("Segment: #{name} was unfinished at " \
230
264
  "the end of transaction. Timing information for this segment's" \
231
- "parent #{parent.name} in #{transaction.best_name} may be inaccurate."
265
+ "parent #{parent.name} in #{transaction.best_name} may be inaccurate.")
232
266
  end
233
267
 
234
268
  def run_complete_callbacks
235
269
  segment_complete
236
- parent.child_complete self if parent
237
- transaction.segment_complete self
270
+ parent.child_complete(self) if parent
271
+ transaction.segment_complete(self)
238
272
  end
239
273
 
240
274
  def record_metrics
@@ -245,27 +279,26 @@ module NewRelic
245
279
  def segment_complete
246
280
  end
247
281
 
248
- def record_child_time child
282
+ def record_child_time(child)
249
283
  if concurrent_children? || finished? && end_time < child.end_time
250
- record_child_time_as_range child
284
+ record_child_time_as_range(child)
251
285
  else
252
- record_child_time_as_number child
286
+ record_child_time_as_number(child)
253
287
  end
254
288
  end
255
289
 
256
- def record_child_time_as_range child
257
- RangeExtensions.merge_or_append child.time_range,
258
- children_time_ranges
290
+ def record_child_time_as_range(child)
291
+ add_child_timing(child)
259
292
  child.range_recorded = true
260
293
  end
261
294
 
262
- def record_child_time_as_number child
295
+ def record_child_time_as_number(child)
263
296
  self.children_time += child.duration
264
297
  end
265
298
 
266
299
  def record_exclusive_duration
267
300
  overlapping_duration = if children_time_ranges?
268
- RangeExtensions.compute_overlap time_range, children_time_ranges
301
+ RangeExtensions.compute_overlap(time_range, children_time_ranges)
269
302
  else
270
303
  0.0
271
304
  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/transaction/segment'
6
7
  require 'new_relic/agent/datastores/metric_helper'
@@ -16,26 +17,26 @@ module NewRelic
16
17
  attr_reader :product, :operation, :collection, :sql_statement, :nosql_statement, :host, :port_path_or_id
17
18
  attr_accessor :database_name, :record_sql
18
19
 
19
- def initialize product, operation, collection = nil, host = nil, port_path_or_id = nil, database_name = nil, start_time = nil
20
+ def initialize(product, operation, collection = nil, host = nil, port_path_or_id = nil, database_name = nil, start_time = nil)
20
21
  @product = product
21
22
  @operation = operation
22
23
  @collection = collection
23
24
  @sql_statement = nil
24
25
  @nosql_statement = nil
25
26
  @record_sql = true
26
- set_instance_info host, port_path_or_id
27
+ set_instance_info(host, port_path_or_id)
27
28
  @database_name = database_name ? database_name.to_s : nil
28
- super Datastores::MetricHelper.scoped_metric_for(product, operation, collection),
29
+ super(Datastores::MetricHelper.scoped_metric_for(product, operation, collection),
29
30
  nil,
30
- start_time
31
+ start_time)
31
32
  end
32
33
 
33
- def set_instance_info host = nil, port_path_or_id = nil
34
+ def set_instance_info(host = nil, port_path_or_id = nil)
34
35
  port_path_or_id = port_path_or_id.to_s if port_path_or_id
35
36
  host_present = host && !host.empty?
36
37
  ppi_present = port_path_or_id && !port_path_or_id.empty?
37
38
 
38
- host = NewRelic::Agent::Hostname.get_external host if host_present
39
+ host = NewRelic::Agent::Hostname.get_external(host) if host_present
39
40
 
40
41
  case
41
42
  when host_present && ppi_present
@@ -55,15 +56,15 @@ module NewRelic
55
56
  end
56
57
  end
57
58
 
58
- def notice_sql sql
59
- _notice_sql sql
59
+ def notice_sql(sql)
60
+ _notice_sql(sql)
60
61
  nil
61
62
  end
62
63
 
63
64
  # @api private
64
- def _notice_sql sql, config = nil, explainer = nil, binds = nil, name = nil
65
+ def _notice_sql(sql, config = nil, explainer = nil, binds = nil, name = nil)
65
66
  return unless record_sql?
66
- @sql_statement = Database::Statement.new sql, config, explainer, binds, name, host, port_path_or_id, database_name
67
+ @sql_statement = Database::Statement.new(sql, config, explainer, binds, name, host, port_path_or_id, database_name)
67
68
  end
68
69
 
69
70
  # Method for simplifying attaching non-SQL data statements to a
@@ -83,7 +84,7 @@ module NewRelic
83
84
  # please ensure all data passed to this method is safe to transmit to
84
85
  # New Relic.
85
86
 
86
- def notice_nosql_statement nosql_statement
87
+ def notice_nosql_statement(nosql_statement)
87
88
  return unless record_sql?
88
89
  @nosql_statement = Database.truncate_query(nosql_statement)
89
90
  nil