newrelic_rpm 8.7.0 → 8.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (398) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +68 -189
  4. data/.rubocop_todo.yml +52 -0
  5. data/.simplecov +15 -0
  6. data/.snyk +11 -0
  7. data/.yardopts +1 -0
  8. data/Brewfile +1 -0
  9. data/CHANGELOG.md +181 -23
  10. data/CONTRIBUTING.md +1 -1
  11. data/Gemfile +0 -1
  12. data/Guardfile +1 -0
  13. data/README.md +1 -1
  14. data/Rakefile +13 -20
  15. data/Thorfile +5 -0
  16. data/bin/newrelic +2 -1
  17. data/bin/newrelic_cmd +1 -0
  18. data/bin/nrdebug +66 -45
  19. data/config.dot +5 -5
  20. data/init.rb +4 -4
  21. data/install.rb +2 -2
  22. data/lib/new_relic/agent/adaptive_sampler.rb +4 -4
  23. data/lib/new_relic/agent/agent/shutdown.rb +34 -0
  24. data/lib/new_relic/agent/agent/special_startup.rb +70 -0
  25. data/lib/new_relic/agent/agent/start_worker_thread.rb +163 -0
  26. data/lib/new_relic/agent/agent/startup.rb +196 -0
  27. data/lib/new_relic/agent/agent.rb +134 -534
  28. data/lib/new_relic/agent/agent_logger.rb +8 -10
  29. data/lib/new_relic/agent/attribute_filter.rb +40 -21
  30. data/lib/new_relic/agent/attribute_processing.rb +7 -7
  31. data/lib/new_relic/agent/attributes.rb +2 -2
  32. data/lib/new_relic/agent/audit_logger.rb +3 -3
  33. data/lib/new_relic/agent/autostart.rb +2 -2
  34. data/lib/new_relic/agent/chained_call.rb +1 -1
  35. data/lib/new_relic/agent/commands/agent_command.rb +1 -1
  36. data/lib/new_relic/agent/commands/agent_command_router.rb +8 -8
  37. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
  38. data/lib/new_relic/agent/configuration/default_source.rb +105 -41
  39. data/lib/new_relic/agent/configuration/dotted_hash.rb +2 -2
  40. data/lib/new_relic/agent/configuration/environment_source.rb +5 -5
  41. data/lib/new_relic/agent/configuration/event_harvest_config.rb +1 -1
  42. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -1
  43. data/lib/new_relic/agent/configuration/manager.rb +5 -5
  44. data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
  45. data/lib/new_relic/agent/configuration/mask_defaults.rb +3 -3
  46. data/lib/new_relic/agent/configuration/security_policy_source.rb +7 -4
  47. data/lib/new_relic/agent/configuration/server_source.rb +7 -7
  48. data/lib/new_relic/agent/configuration/yaml_source.rb +6 -4
  49. data/lib/new_relic/agent/configuration.rb +1 -1
  50. data/lib/new_relic/agent/connect/request_builder.rb +3 -3
  51. data/lib/new_relic/agent/connect/response_handler.rb +5 -5
  52. data/lib/new_relic/agent/custom_event_aggregator.rb +5 -5
  53. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
  54. data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -1
  55. data/lib/new_relic/agent/database/obfuscator.rb +2 -2
  56. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
  57. data/lib/new_relic/agent/database.rb +21 -21
  58. data/lib/new_relic/agent/database_adapter.rb +1 -1
  59. data/lib/new_relic/agent/datastores/metric_helper.rb +12 -13
  60. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +4 -3
  61. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +2 -4
  62. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +2 -2
  63. data/lib/new_relic/agent/datastores/mongo.rb +1 -1
  64. data/lib/new_relic/agent/datastores/redis.rb +3 -3
  65. data/lib/new_relic/agent/datastores.rb +4 -4
  66. data/lib/new_relic/agent/deprecator.rb +1 -1
  67. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +1 -1
  68. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +16 -17
  69. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +9 -10
  70. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +18 -19
  71. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +8 -10
  72. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +2 -3
  73. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +40 -40
  74. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +16 -15
  75. data/lib/new_relic/agent/distributed_tracing.rb +17 -18
  76. data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
  77. data/lib/new_relic/agent/error_collector.rb +6 -5
  78. data/lib/new_relic/agent/error_event_aggregator.rb +3 -4
  79. data/lib/new_relic/agent/error_filter.rb +5 -5
  80. data/lib/new_relic/agent/error_trace_aggregator.rb +3 -3
  81. data/lib/new_relic/agent/event_aggregator.rb +20 -20
  82. data/lib/new_relic/agent/event_buffer.rb +1 -1
  83. data/lib/new_relic/agent/event_listener.rb +1 -1
  84. data/lib/new_relic/agent/event_loop.rb +9 -9
  85. data/lib/new_relic/agent/external.rb +10 -10
  86. data/lib/new_relic/agent/guid_generator.rb +2 -2
  87. data/lib/new_relic/agent/harvester.rb +1 -1
  88. data/lib/new_relic/agent/heap.rb +5 -5
  89. data/lib/new_relic/agent/hostname.rb +4 -3
  90. data/lib/new_relic/agent/http_clients/abstract.rb +1 -2
  91. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +5 -6
  92. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +4 -5
  93. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +2 -3
  94. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +1 -2
  95. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +0 -1
  96. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -2
  97. data/lib/new_relic/agent/http_clients/uri_util.rb +1 -2
  98. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +6 -5
  99. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +31 -23
  100. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +7 -6
  101. data/lib/new_relic/agent/instrumentation/active_job.rb +11 -4
  102. data/lib/new_relic/agent/instrumentation/active_merchant.rb +4 -3
  103. data/lib/new_relic/agent/instrumentation/active_record.rb +9 -9
  104. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +37 -21
  105. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +3 -3
  106. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +1 -1
  107. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +21 -11
  108. data/lib/new_relic/agent/instrumentation/active_storage.rb +2 -2
  109. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +16 -15
  110. data/lib/new_relic/agent/instrumentation/active_support_logger/chain.rb +1 -1
  111. data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +1 -1
  112. data/lib/new_relic/agent/instrumentation/active_support_logger/prepend.rb +1 -1
  113. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +2 -2
  114. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -2
  115. data/lib/new_relic/agent/instrumentation/authlogic.rb +2 -2
  116. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +10 -10
  117. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +10 -11
  118. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +4 -4
  119. data/lib/new_relic/agent/instrumentation/bunny.rb +1 -2
  120. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +25 -17
  121. data/lib/new_relic/agent/instrumentation/curb/chain.rb +21 -22
  122. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +19 -16
  123. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +2 -3
  124. data/lib/new_relic/agent/instrumentation/curb.rb +2 -2
  125. data/lib/new_relic/agent/instrumentation/data_mapper.rb +44 -44
  126. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +1 -2
  127. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +2 -3
  128. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +1 -2
  129. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +3 -3
  130. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -3
  131. data/lib/new_relic/agent/instrumentation/excon.rb +2 -2
  132. data/lib/new_relic/agent/instrumentation/grape/chain.rb +6 -6
  133. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +5 -5
  134. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +4 -4
  135. data/lib/new_relic/agent/instrumentation/grape.rb +1 -1
  136. data/lib/new_relic/agent/instrumentation/grpc/client/chain.rb +97 -0
  137. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +89 -0
  138. data/lib/new_relic/agent/instrumentation/grpc/client/prepend.rb +111 -0
  139. data/lib/new_relic/agent/instrumentation/grpc/client/request_wrapper.rb +30 -0
  140. data/lib/new_relic/agent/instrumentation/grpc/helper.rb +32 -0
  141. data/lib/new_relic/agent/instrumentation/grpc/server/chain.rb +69 -0
  142. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +134 -0
  143. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_desc_prepend.rb +35 -0
  144. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_server_prepend.rb +26 -0
  145. data/lib/new_relic/agent/instrumentation/grpc_client.rb +23 -0
  146. data/lib/new_relic/agent/instrumentation/grpc_server.rb +25 -0
  147. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +1 -1
  148. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +6 -6
  149. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +1 -1
  150. data/lib/new_relic/agent/instrumentation/httpclient.rb +2 -2
  151. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +1 -1
  152. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +4 -4
  153. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -1
  154. data/lib/new_relic/agent/instrumentation/httprb.rb +2 -2
  155. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -2
  156. data/lib/new_relic/agent/instrumentation/logger/chain.rb +2 -2
  157. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +5 -1
  158. data/lib/new_relic/agent/instrumentation/logger/prepend.rb +1 -1
  159. data/lib/new_relic/agent/instrumentation/logger.rb +2 -2
  160. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +2 -3
  161. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +24 -17
  162. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +8 -9
  163. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +17 -15
  164. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +21 -15
  165. data/lib/new_relic/agent/instrumentation/memcache.rb +5 -6
  166. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +2 -2
  167. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +0 -1
  168. data/lib/new_relic/agent/instrumentation/mongo.rb +2 -2
  169. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +15 -14
  170. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +1 -1
  171. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -5
  172. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +1 -1
  173. data/lib/new_relic/agent/instrumentation/net_http.rb +2 -2
  174. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +6 -6
  175. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +1 -1
  176. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +1 -1
  177. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +1 -1
  178. data/lib/new_relic/agent/instrumentation/padrino.rb +2 -2
  179. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +3 -3
  180. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -2
  181. data/lib/new_relic/agent/instrumentation/rack/chain.rb +12 -12
  182. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +1 -1
  183. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +7 -7
  184. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +4 -4
  185. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  186. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -6
  187. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
  188. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +3 -2
  189. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +3 -2
  190. data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +3 -2
  191. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +3 -3
  192. data/lib/new_relic/agent/instrumentation/rake/chain.rb +2 -2
  193. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +6 -2
  194. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +1 -1
  195. data/lib/new_relic/agent/instrumentation/rake.rb +3 -3
  196. data/lib/new_relic/agent/instrumentation/redis/chain.rb +3 -4
  197. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +5 -6
  198. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +3 -4
  199. data/lib/new_relic/agent/instrumentation/redis.rb +2 -2
  200. data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -2
  201. data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
  202. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +0 -1
  203. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -1
  204. data/lib/new_relic/agent/instrumentation/resque.rb +3 -3
  205. data/lib/new_relic/agent/instrumentation/sequel.rb +8 -8
  206. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
  207. data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -5
  208. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +1 -1
  209. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +2 -2
  210. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +1 -1
  211. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +1 -1
  212. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +2 -2
  213. data/lib/new_relic/agent/instrumentation/sinatra.rb +2 -2
  214. data/lib/new_relic/agent/instrumentation/sunspot.rb +4 -4
  215. data/lib/new_relic/agent/instrumentation/thread/chain.rb +2 -2
  216. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -1
  217. data/lib/new_relic/agent/instrumentation/thread/prepend.rb +1 -1
  218. data/lib/new_relic/agent/instrumentation/thread.rb +2 -2
  219. data/lib/new_relic/agent/instrumentation/tilt/chain.rb +1 -1
  220. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +1 -1
  221. data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +1 -1
  222. data/lib/new_relic/agent/instrumentation/tilt.rb +1 -1
  223. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +1 -1
  224. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +8 -8
  225. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +1 -1
  226. data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
  227. data/lib/new_relic/agent/instrumentation.rb +1 -1
  228. data/lib/new_relic/agent/internal_agent_error.rb +1 -1
  229. data/lib/new_relic/agent/javascript_instrumentor.rb +8 -8
  230. data/lib/new_relic/agent/linking_metadata.rb +2 -3
  231. data/lib/new_relic/agent/local_log_decorator.rb +0 -1
  232. data/lib/new_relic/agent/log_event_aggregator.rb +7 -7
  233. data/lib/new_relic/agent/log_once.rb +1 -1
  234. data/lib/new_relic/agent/log_priority.rb +1 -1
  235. data/lib/new_relic/agent/logging.rb +13 -13
  236. data/lib/new_relic/agent/memory_logger.rb +1 -1
  237. data/lib/new_relic/agent/messaging.rb +19 -20
  238. data/lib/new_relic/agent/method_tracer.rb +15 -10
  239. data/lib/new_relic/agent/method_tracer_helpers.rb +83 -1
  240. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +4 -4
  241. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +3 -3
  242. data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +1 -1
  243. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +2 -2
  244. data/lib/new_relic/agent/monitors.rb +5 -5
  245. data/lib/new_relic/agent/new_relic_service/encoders.rb +2 -2
  246. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +4 -4
  247. data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
  248. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -1
  249. data/lib/new_relic/agent/new_relic_service.rb +214 -166
  250. data/lib/new_relic/agent/{noticible_error.rb → noticeable_error.rb} +2 -3
  251. data/lib/new_relic/agent/null_logger.rb +1 -1
  252. data/lib/new_relic/agent/obfuscator.rb +3 -3
  253. data/lib/new_relic/agent/parameter_filtering.rb +1 -1
  254. data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
  255. data/lib/new_relic/agent/pipe_channel_manager.rb +10 -5
  256. data/lib/new_relic/agent/pipe_service.rb +2 -2
  257. data/lib/new_relic/agent/prepend_supportability.rb +2 -2
  258. data/lib/new_relic/agent/priority_sampled_buffer.rb +4 -4
  259. data/lib/new_relic/agent/range_extensions.rb +8 -28
  260. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +2 -2
  261. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
  262. data/lib/new_relic/agent/rules_engine.rb +2 -2
  263. data/lib/new_relic/agent/sampler.rb +1 -1
  264. data/lib/new_relic/agent/sampler_collection.rb +1 -1
  265. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  266. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -2
  267. data/lib/new_relic/agent/samplers/memory_sampler.rb +10 -10
  268. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  269. data/lib/new_relic/agent/samplers/vm_sampler.rb +3 -1
  270. data/lib/new_relic/agent/span_event_aggregator.rb +2 -2
  271. data/lib/new_relic/agent/span_event_primitive.rb +24 -19
  272. data/lib/new_relic/agent/sql_sampler.rb +8 -8
  273. data/lib/new_relic/agent/stats.rb +15 -4
  274. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -2
  275. data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -4
  276. data/lib/new_relic/agent/stats_engine.rb +1 -1
  277. data/lib/new_relic/agent/synthetics_event_aggregator.rb +6 -6
  278. data/lib/new_relic/agent/system_info.rb +68 -53
  279. data/lib/new_relic/agent/threading/agent_thread.rb +13 -9
  280. data/lib/new_relic/agent/threading/backtrace_node.rb +6 -4
  281. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
  282. data/lib/new_relic/agent/threading/thread_profile.rb +4 -4
  283. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
  284. data/lib/new_relic/agent/tracer.rb +19 -17
  285. data/lib/new_relic/agent/transaction/abstract_segment.rb +93 -34
  286. data/lib/new_relic/agent/transaction/datastore_segment.rb +12 -12
  287. data/lib/new_relic/agent/transaction/distributed_tracer.rb +52 -48
  288. data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -22
  289. data/lib/new_relic/agent/transaction/external_request_segment.rb +37 -29
  290. data/lib/new_relic/agent/transaction/message_broker_segment.rb +6 -6
  291. data/lib/new_relic/agent/transaction/request_attributes.rb +29 -29
  292. data/lib/new_relic/agent/transaction/segment.rb +8 -8
  293. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
  294. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  295. data/lib/new_relic/agent/transaction/trace.rb +3 -3
  296. data/lib/new_relic/agent/transaction/trace_builder.rb +10 -10
  297. data/lib/new_relic/agent/transaction/trace_context.rb +22 -20
  298. data/lib/new_relic/agent/transaction/trace_node.rb +9 -9
  299. data/lib/new_relic/agent/transaction/tracing.rb +7 -7
  300. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -2
  301. data/lib/new_relic/agent/transaction.rb +35 -31
  302. data/lib/new_relic/agent/transaction_error_primitive.rb +9 -9
  303. data/lib/new_relic/agent/transaction_event_aggregator.rb +5 -5
  304. data/lib/new_relic/agent/transaction_event_primitive.rb +3 -4
  305. data/lib/new_relic/agent/transaction_event_recorder.rb +15 -14
  306. data/lib/new_relic/agent/transaction_metrics.rb +4 -4
  307. data/lib/new_relic/agent/transaction_sampler.rb +5 -5
  308. data/lib/new_relic/agent/transaction_time_aggregator.rb +14 -14
  309. data/lib/new_relic/agent/utilization/aws.rb +4 -4
  310. data/lib/new_relic/agent/utilization/azure.rb +2 -2
  311. data/lib/new_relic/agent/utilization/gcp.rb +7 -7
  312. data/lib/new_relic/agent/utilization/pcf.rb +4 -4
  313. data/lib/new_relic/agent/utilization/vendor.rb +28 -28
  314. data/lib/new_relic/agent/utilization_data.rb +1 -1
  315. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
  316. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  317. data/lib/new_relic/agent/vm/mri_vm.rb +36 -23
  318. data/lib/new_relic/agent/vm/snapshot.rb +2 -2
  319. data/lib/new_relic/agent/vm.rb +1 -1
  320. data/lib/new_relic/agent/worker_loop.rb +2 -2
  321. data/lib/new_relic/agent.rb +27 -27
  322. data/lib/new_relic/cli/command.rb +6 -6
  323. data/lib/new_relic/cli/commands/deployments.rb +81 -29
  324. data/lib/new_relic/cli/commands/install.rb +6 -6
  325. data/lib/new_relic/coerce.rb +5 -6
  326. data/lib/new_relic/collection_helper.rb +4 -4
  327. data/lib/new_relic/constants.rb +0 -1
  328. data/lib/new_relic/control/class_methods.rb +1 -1
  329. data/lib/new_relic/control/frameworks/external.rb +1 -1
  330. data/lib/new_relic/control/frameworks/rails.rb +3 -3
  331. data/lib/new_relic/control/frameworks/rails3.rb +1 -1
  332. data/lib/new_relic/control/frameworks/rails4.rb +1 -1
  333. data/lib/new_relic/control/frameworks/rails_notifications.rb +1 -1
  334. data/lib/new_relic/control/frameworks/ruby.rb +1 -1
  335. data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
  336. data/lib/new_relic/control/frameworks.rb +1 -1
  337. data/lib/new_relic/control/instance_methods.rb +20 -42
  338. data/lib/new_relic/control/instrumentation.rb +7 -7
  339. data/lib/new_relic/control/private_instance_methods.rb +48 -0
  340. data/lib/new_relic/control/server_methods.rb +2 -2
  341. data/lib/new_relic/control.rb +1 -1
  342. data/lib/new_relic/delayed_job_injection.rb +1 -1
  343. data/lib/new_relic/dependency_detection.rb +23 -22
  344. data/lib/new_relic/environment_report.rb +24 -14
  345. data/lib/new_relic/helper.rb +5 -5
  346. data/lib/new_relic/language_support.rb +8 -3
  347. data/lib/new_relic/latest_changes.rb +4 -4
  348. data/lib/new_relic/local_environment.rb +9 -11
  349. data/lib/new_relic/metric_data.rb +30 -24
  350. data/lib/new_relic/metric_spec.rb +3 -3
  351. data/lib/new_relic/noticed_error.rb +3 -6
  352. data/lib/new_relic/rack/agent_hooks.rb +1 -1
  353. data/lib/new_relic/rack/agent_middleware.rb +1 -1
  354. data/lib/new_relic/rack/browser_monitoring.rb +132 -123
  355. data/lib/new_relic/rack.rb +1 -1
  356. data/lib/new_relic/recipes/capistrano3.rb +3 -59
  357. data/lib/new_relic/recipes/capistrano_legacy.rb +13 -13
  358. data/lib/new_relic/recipes/helpers/send_deployment.rb +69 -0
  359. data/lib/new_relic/recipes.rb +1 -1
  360. data/lib/new_relic/supportability_helper.rb +6 -6
  361. data/lib/new_relic/traced_thread.rb +5 -7
  362. data/lib/new_relic/version.rb +2 -2
  363. data/lib/newrelic_rpm.rb +1 -1
  364. data/lib/sequel/extensions/newrelic_instrumentation.rb +8 -8
  365. data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
  366. data/lib/tasks/all.rb +1 -1
  367. data/lib/tasks/config.rake +8 -112
  368. data/lib/tasks/coverage_report.rake +28 -0
  369. data/lib/tasks/{config.html.erb → helpers/config.html.erb} +0 -0
  370. data/lib/tasks/{config.text.erb → helpers/config.text.erb} +0 -0
  371. data/lib/tasks/helpers/format.rb +120 -0
  372. data/lib/tasks/helpers/matches.rb +12 -0
  373. data/lib/tasks/helpers/prompt.rb +24 -0
  374. data/lib/tasks/helpers/removers.rb +33 -0
  375. data/lib/tasks/install.rake +4 -0
  376. data/lib/tasks/instrumentation_generator/README.md +63 -0
  377. data/lib/tasks/instrumentation_generator/TODO.md +33 -0
  378. data/lib/tasks/instrumentation_generator/instrumentation.thor +102 -0
  379. data/lib/tasks/instrumentation_generator/templates/Envfile.tt +9 -0
  380. data/lib/tasks/instrumentation_generator/templates/chain.tt +21 -0
  381. data/lib/tasks/instrumentation_generator/templates/chain_method.tt +7 -0
  382. data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +29 -0
  383. data/lib/tasks/instrumentation_generator/templates/instrumentation.tt +12 -0
  384. data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +3 -0
  385. data/lib/tasks/instrumentation_generator/templates/newrelic.yml.tt +19 -0
  386. data/lib/tasks/instrumentation_generator/templates/prepend.tt +13 -0
  387. data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +3 -0
  388. data/lib/tasks/instrumentation_generator/templates/test.tt +15 -0
  389. data/lib/tasks/multiverse.rake +4 -0
  390. data/lib/tasks/multiverse.rb +5 -30
  391. data/lib/tasks/newrelic.rb +1 -1
  392. data/lib/tasks/tests.rake +7 -8
  393. data/newrelic.yml +514 -483
  394. data/newrelic_rpm.gemspec +16 -21
  395. data/recipes/newrelic.rb +1 -1
  396. data/test/agent_helper.rb +125 -147
  397. metadata +82 -90
  398. data/bin/mongrel_rpm +0 -32
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  # This module is intended to provide access to information about the host OS and
6
6
  # [virtual] machine. It intentionally does no caching and maintains no state -
@@ -39,54 +39,69 @@ module NewRelic
39
39
  @processor_info = nil
40
40
  end
41
41
 
42
- def self.get_processor_info
43
- if @processor_info.nil?
44
- if darwin?
45
- @processor_info = {
46
- :num_physical_packages => sysctl_value('hw.packages').to_i,
47
- :num_physical_cores => sysctl_value('hw.physicalcpu_max').to_i,
48
- :num_logical_processors => sysctl_value('hw.logicalcpu_max').to_i
49
- }
50
- # in case those don't work, try backup values
51
- if @processor_info[:num_physical_cores] <= 0
52
- @processor_info[:num_physical_cores] = sysctl_value('hw.physicalcpu').to_i
53
- end
54
- if @processor_info[:num_logical_processors] <= 0
55
- @processor_info[:num_logical_processors] = sysctl_value('hw.logicalcpu').to_i
56
- end
57
- if @processor_info[:num_logical_processors] <= 0
58
- @processor_info[:num_logical_processors] = sysctl_value('hw.ncpu').to_i
59
- end
60
-
61
- elsif linux?
62
- cpuinfo = proc_try_read('/proc/cpuinfo')
63
- @processor_info = cpuinfo ? parse_cpuinfo(cpuinfo) : {}
42
+ def self.processor_info
43
+ return @processor_info if @processor_info
64
44
 
65
- elsif bsd?
66
- @processor_info = {
67
- :num_physical_packages => nil,
68
- :num_physical_cores => nil,
69
- :num_logical_processors => sysctl_value('hw.ncpu').to_i
70
- }
71
- end
72
-
73
- # give nils for obviously wrong values
74
- @processor_info.keys.each do |key|
75
- value = @processor_info[key]
76
- if value.is_a?(Numeric) && value <= 0
77
- @processor_info[key] = nil
78
- end
79
- end
45
+ if darwin?
46
+ processor_info_darwin
47
+ elsif linux?
48
+ processor_info_linux
49
+ elsif bsd?
50
+ processor_info_bsd
51
+ else
52
+ raise "Couldn't determine OS"
80
53
  end
54
+ remove_bad_values
81
55
 
82
56
  @processor_info
83
57
  rescue
84
- {}
58
+ @processor_info = NewRelic::EMPTY_HASH
59
+ end
60
+
61
+ def self.processor_info_darwin
62
+ @processor_info = {
63
+ num_physical_packages: sysctl_value('hw.packages'),
64
+ num_physical_cores: sysctl_value('hw.physicalcpu_max'),
65
+ num_logical_processors: sysctl_value('hw.logicalcpu_max')
66
+ }
67
+ # in case those don't work, try backup values
68
+ if @processor_info[:num_physical_cores] <= 0
69
+ @processor_info[:num_physical_cores] = sysctl_value('hw.physicalcpu')
70
+ end
71
+ if @processor_info[:num_logical_processors] <= 0
72
+ @processor_info[:num_logical_processors] = sysctl_value('hw.logicalcpu')
73
+ end
74
+ if @processor_info[:num_logical_processors] <= 0
75
+ @processor_info[:num_logical_processors] = sysctl_value('hw.ncpu')
76
+ end
77
+ end
78
+
79
+ def self.processor_info_linux
80
+ cpuinfo = proc_try_read('/proc/cpuinfo')
81
+ @processor_info = cpuinfo ? parse_cpuinfo(cpuinfo) : NewRelic::EMPTY_HASH
82
+ end
83
+
84
+ def self.processor_info_bsd
85
+ @processor_info = {
86
+ num_physical_packages: nil,
87
+ num_physical_cores: nil,
88
+ num_logical_processors: sysctl_value('hw.ncpu')
89
+ }
90
+ end
91
+
92
+ def self.remove_bad_values
93
+ # give nils for obviously wrong values
94
+ @processor_info.keys.each do |key|
95
+ value = @processor_info[key]
96
+ if value.is_a?(Numeric) && value <= 0
97
+ @processor_info[key] = nil
98
+ end
99
+ end
85
100
  end
86
101
 
87
102
  def self.sysctl_value(name)
88
103
  # make sure to redirect stderr so we don't spew if the name is unknown
89
- `sysctl -n #{name} 2>/dev/null`
104
+ `sysctl -n #{name} 2>/dev/null`.to_i
90
105
  end
91
106
 
92
107
  def self.parse_cpuinfo(cpuinfo)
@@ -143,11 +158,11 @@ module NewRelic
143
158
  }
144
159
  end
145
160
 
146
- def self.num_physical_packages; get_processor_info[:num_physical_packages] end
161
+ def self.num_physical_packages; processor_info[:num_physical_packages] end
147
162
 
148
- def self.num_physical_cores; get_processor_info[:num_physical_cores] end
163
+ def self.num_physical_cores; processor_info[:num_physical_cores] end
149
164
 
150
- def self.num_logical_processors; get_processor_info[:num_logical_processors] end
165
+ def self.num_logical_processors; processor_info[:num_logical_processors] end
151
166
 
152
167
  def self.processor_arch
153
168
  RbConfig::CONFIG['target_cpu']
@@ -158,7 +173,7 @@ module NewRelic
158
173
  end
159
174
 
160
175
  def self.docker_container_id
161
- return unless ruby_os_identifier =~ /linux/
176
+ return unless ruby_os_identifier.include?('linux')
162
177
 
163
178
  cgroup_info = proc_try_read('/proc/self/cgroup')
164
179
  return unless cgroup_info
@@ -187,7 +202,7 @@ module NewRelic
187
202
  return
188
203
  when /docker/
189
204
  ::NewRelic::Agent.logger.debug("Cgroup indicates docker but container_id unrecognized: '#{cpu_cgroup}'")
190
- ::NewRelic::Agent.increment_metric "Supportability/utilization/docker/error"
205
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/docker/error")
191
206
  return
192
207
  else
193
208
  ::NewRelic::Agent.logger.debug("Ignoring unrecognized cgroup ID format: '#{cpu_cgroup}'")
@@ -196,7 +211,7 @@ module NewRelic
196
211
 
197
212
  if container_id && container_id.size != 64
198
213
  ::NewRelic::Agent.logger.debug("Found docker container_id with invalid length: #{container_id}")
199
- ::NewRelic::Agent.increment_metric "Supportability/utilization/docker/error"
214
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/docker/error")
200
215
  nil
201
216
  else
202
217
  container_id
@@ -225,7 +240,7 @@ module NewRelic
225
240
  # for details on why we do it this way.
226
241
  def self.proc_try_read(path)
227
242
  return nil unless File.exist?(path)
228
- content = ''
243
+ content = String.new('')
229
244
  File.open(path) do |f|
230
245
  loop do
231
246
  begin
@@ -243,12 +258,12 @@ module NewRelic
243
258
 
244
259
  def self.ram_in_mib
245
260
  if darwin?
246
- (sysctl_value('hw.memsize').to_i / (1024**2)).to_i
261
+ (sysctl_value('hw.memsize') / (1024**2))
247
262
  elsif linux?
248
263
  meminfo = proc_try_read('/proc/meminfo')
249
264
  parse_linux_meminfo_in_mib(meminfo)
250
265
  elsif bsd?
251
- (sysctl_value('hw.realmem').to_i / (1024**2)).to_i
266
+ (sysctl_value('hw.realmem') / (1024**2))
252
267
  else
253
268
  ::NewRelic::Agent.logger.debug("Unable to determine ram_in_mib for host os: #{ruby_os_identifier}")
254
269
  nil
@@ -272,7 +287,7 @@ module NewRelic
272
287
  if bid.ascii_only?
273
288
  if bid.empty?
274
289
  ::NewRelic::Agent.logger.debug("boot_id not found in /proc/sys/kernel/random/boot_id")
275
- ::NewRelic::Agent.increment_metric "Supportability/utilization/boot_id/error"
290
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/boot_id/error")
276
291
  nil
277
292
 
278
293
  elsif bid.bytesize == 36
@@ -280,19 +295,19 @@ module NewRelic
280
295
 
281
296
  else
282
297
  ::NewRelic::Agent.logger.debug("Found boot_id with invalid length: #{bid}")
283
- ::NewRelic::Agent.increment_metric "Supportability/utilization/boot_id/error"
298
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/boot_id/error")
284
299
  bid[0, 128]
285
300
 
286
301
  end
287
302
  else
288
303
  ::NewRelic::Agent.logger.debug("Found boot_id with non-ASCII characters: #{bid}")
289
- ::NewRelic::Agent.increment_metric "Supportability/utilization/boot_id/error"
304
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/boot_id/error")
290
305
  nil
291
306
 
292
307
  end
293
308
  else
294
309
  ::NewRelic::Agent.logger.debug("boot_id not found in /proc/sys/kernel/random/boot_id")
295
- ::NewRelic::Agent.increment_metric "Supportability/utilization/boot_id/error"
310
+ ::NewRelic::Agent.increment_metric("Supportability/utilization/boot_id/error")
296
311
  nil
297
312
 
298
313
  end
@@ -1,27 +1,31 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  module NewRelic
6
6
  module Agent
7
7
  module Threading
8
8
  class AgentThread
9
9
  def self.create(label, &blk)
10
- ::NewRelic::Agent.logger.debug("Creating New Relic thread: #{label}")
11
- wrapped_blk = Proc.new do
10
+ ::NewRelic::Agent.logger.debug("Creating AgentThread: #{label}")
11
+ wrapped_blk = proc do
12
+ if ::Thread.current[:newrelic_tracer_state] && Thread.current[:newrelic_tracer_state].current_transaction
13
+ txn = ::Thread.current[:newrelic_tracer_state].current_transaction
14
+ ::NewRelic::Agent.logger.warn("AgentThread created with current transaction #{txn.best_name}")
15
+ end
12
16
  begin
13
- blk.call
17
+ yield
14
18
  rescue => e
15
- ::NewRelic::Agent.logger.error("Thread #{label} exited with error", e)
19
+ ::NewRelic::Agent.logger.error("AgentThread #{label} exited with error", e)
16
20
  rescue Exception => e
17
- ::NewRelic::Agent.logger.error("Thread #{label} exited with exception. Re-raising in case of interrupt.", e)
21
+ ::NewRelic::Agent.logger.error("AgentThread #{label} exited with exception. Re-raising in case of interrupt.", e)
18
22
  raise
19
23
  ensure
20
- ::NewRelic::Agent.logger.debug("Exiting New Relic thread: #{label}")
24
+ ::NewRelic::Agent.logger.debug("Exiting AgentThread: #{label}")
21
25
  end
22
26
  end
23
-
24
- thread = backing_thread_class.new(&wrapped_blk)
27
+ thread = nil
28
+ NewRelic::Agent.disable_all_tracing { thread = backing_thread_class.new(&wrapped_blk) }
25
29
  thread[:newrelic_label] = label
26
30
  thread
27
31
  end
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  module NewRelic
6
6
  module Agent
@@ -18,7 +18,7 @@ module NewRelic
18
18
 
19
19
  def add_child_unless_present(child)
20
20
  child.depth = @depth + 1
21
- @children << child unless @children.include? child
21
+ @children << child unless @children.include?(child)
22
22
  end
23
23
 
24
24
  def add_child(child)
@@ -70,7 +70,7 @@ module NewRelic
70
70
  end
71
71
 
72
72
  def dump_string
73
- result = "#<BacktraceRoot:#{object_id}>"
73
+ result = String.new("#<BacktraceRoot:#{object_id}>")
74
74
  child_results = @children.map { |c| c.dump_string(2) }.join("\n")
75
75
  result << "\n" unless child_results.empty?
76
76
  result << child_results
@@ -115,7 +115,9 @@ module NewRelic
115
115
 
116
116
  def dump_string(indent = 0)
117
117
  @file, @method, @line_no = parse_backtrace_frame(@raw_line)
118
- result = "#{" " * indent}#<BacktraceNode:#{object_id} [#{@runnable_count}] #{@file}:#{@line_no} in #{@method}>"
118
+ indentation = ' ' * indent
119
+ result = String.new("#{indentation}#<BacktraceNode:#{object_id} ) + \
120
+ [#{@runnable_count}] #{@file}:#{@line_no} in #{@method}>")
119
121
  child_results = @children.map { |c| c.dump_string(indent + 2) }.join("\n")
120
122
  result << "\n" unless child_results.empty?
121
123
  result << child_results
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  module NewRelic
6
6
  module Agent
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'set'
6
6
  require 'new_relic/agent/worker_loop'
@@ -78,7 +78,7 @@ module NewRelic
78
78
  comparison = b.runnable_count <=> a.runnable_count
79
79
  # we secondarily prefer lower depth
80
80
  comparison = a.depth <=> b.depth if comparison == 0
81
- # it is thus impossible for any child to preceed their parent
81
+ # it is thus impossible for any child to precede their parent
82
82
  comparison
83
83
  end
84
84
 
@@ -122,8 +122,8 @@ module NewRelic
122
122
  end
123
123
 
124
124
  def to_log_description
125
- "#<ThreadProfile:#{object_id} "\
126
- "@profile_id: #{profile_id} "\
125
+ "#<ThreadProfile:#{object_id} " \
126
+ "@profile_id: #{profile_id} " \
127
127
  "@command_arguments=#{@command_arguments.inspect}>"
128
128
  end
129
129
  end
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'new_relic/agent/heap'
6
6
 
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'new_relic/agent/transaction'
6
6
  require 'new_relic/agent/transaction/segment'
@@ -234,8 +234,8 @@ module NewRelic
234
234
  start_time: nil,
235
235
  parent: nil)
236
236
 
237
- segment = Transaction::Segment.new name, unscoped_metrics, start_time
238
- start_and_add_segment segment, parent
237
+ segment = Transaction::Segment.new(name, unscoped_metrics, start_time)
238
+ start_and_add_segment(segment, parent)
239
239
  rescue ArgumentError
240
240
  raise
241
241
  rescue => exception
@@ -292,8 +292,8 @@ module NewRelic
292
292
  product ||= UNKNOWN
293
293
  operation ||= OTHER
294
294
 
295
- segment = Transaction::DatastoreSegment.new product, operation, collection, host, port_path_or_id, database_name
296
- start_and_add_segment segment, parent
295
+ segment = Transaction::DatastoreSegment.new(product, operation, collection, host, port_path_or_id, database_name)
296
+ start_and_add_segment(segment, parent)
297
297
  rescue ArgumentError
298
298
  raise
299
299
  rescue => exception
@@ -333,8 +333,8 @@ module NewRelic
333
333
  start_time: nil,
334
334
  parent: nil)
335
335
 
336
- segment = Transaction::ExternalRequestSegment.new library, uri, procedure, start_time
337
- start_and_add_segment segment, parent
336
+ segment = Transaction::ExternalRequestSegment.new(library, uri, procedure, start_time)
337
+ start_and_add_segment(segment, parent)
338
338
  rescue ArgumentError
339
339
  raise
340
340
  rescue => exception
@@ -346,12 +346,12 @@ module NewRelic
346
346
  # if passed +segment+ is something that doesn't
347
347
  # respond to +notice_segment_error+ then this method
348
348
  # is effectively just a yield to the given &block
349
- def capture_segment_error segment
349
+ def capture_segment_error(segment)
350
350
  return unless block_given?
351
351
  yield
352
352
  rescue => exception
353
353
  if segment && segment.is_a?(Transaction::AbstractSegment)
354
- segment.notice_error exception
354
+ segment.notice_error(exception)
355
355
  end
356
356
  raise
357
357
  end
@@ -375,7 +375,7 @@ module NewRelic
375
375
  parameters: parameters,
376
376
  start_time: start_time
377
377
  )
378
- start_and_add_segment segment, parent
378
+ start_and_add_segment(segment, parent)
379
379
  rescue ArgumentError
380
380
  raise
381
381
  rescue => exception
@@ -406,12 +406,14 @@ module NewRelic
406
406
  alias_method :tl_clear, :clear_state
407
407
 
408
408
  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
- Proc.new do
409
+ current_txn = ::Thread.current[:newrelic_tracer_state].current_transaction if ::Thread.current[:newrelic_tracer_state] && ::Thread.current[:newrelic_tracer_state].is_execution_traced?
410
+ proc do
411
411
  begin
412
- NewRelic::Agent::Tracer.state.current_transaction = current_txn
413
- segment = NewRelic::Agent::Tracer.start_segment(name: "Ruby/Thread/#{::Thread.current.object_id}")
414
- block.call(*args) if block.respond_to?(:call)
412
+ if current_txn
413
+ NewRelic::Agent::Tracer.state.current_transaction = current_txn
414
+ segment = NewRelic::Agent::Tracer.start_segment(name: "Ruby/Thread/#{::Thread.current.object_id}")
415
+ end
416
+ yield(*args) if block.respond_to?(:call)
415
417
  ensure
416
418
  segment.finish if segment
417
419
  end
@@ -420,11 +422,11 @@ module NewRelic
420
422
 
421
423
  private
422
424
 
423
- def start_and_add_segment segment, parent = nil
425
+ def start_and_add_segment(segment, parent = nil)
424
426
  tracer_state = state
425
427
  if (txn = tracer_state.current_transaction) &&
426
428
  tracer_state.tracing_enabled?
427
- txn.add_segment segment, parent
429
+ txn.add_segment(segment, parent)
428
430
  else
429
431
  segment.record_metrics = false
430
432
  end