newrelic_rpm 5.5.0.348 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (364) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -0
  3. data/.yardopts +1 -0
  4. data/CHANGELOG.md +931 -0
  5. data/CONTRIBUTING.md +117 -19
  6. data/Gemfile +6 -2
  7. data/Guardfile +18 -1
  8. data/LICENSE +208 -38
  9. data/README.md +80 -84
  10. data/ROADMAP.md +24 -0
  11. data/Rakefile +2 -0
  12. data/THIRD_PARTY_NOTICES.md +213 -0
  13. data/bin/nrdebug +1 -1
  14. data/config.dot +1 -0
  15. data/init.rb +1 -1
  16. data/install.rb +1 -1
  17. data/lib/new_relic/agent.rb +111 -20
  18. data/lib/new_relic/agent/adaptive_sampler.rb +1 -1
  19. data/lib/new_relic/agent/agent.rb +182 -194
  20. data/lib/new_relic/agent/agent_logger.rb +5 -1
  21. data/lib/new_relic/agent/attribute_filter.rb +85 -25
  22. data/lib/new_relic/agent/attribute_processing.rb +1 -1
  23. data/lib/new_relic/agent/attributes.rb +152 -0
  24. data/lib/new_relic/agent/audit_logger.rb +11 -1
  25. data/lib/new_relic/agent/autostart.rb +19 -15
  26. data/lib/new_relic/agent/chained_call.rb +1 -1
  27. data/lib/new_relic/agent/commands/agent_command.rb +1 -1
  28. data/lib/new_relic/agent/commands/agent_command_router.rb +3 -22
  29. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
  30. data/lib/new_relic/agent/configuration.rb +1 -1
  31. data/lib/new_relic/agent/configuration/default_source.rb +656 -188
  32. data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -1
  33. data/lib/new_relic/agent/configuration/environment_source.rb +5 -3
  34. data/lib/new_relic/agent/configuration/event_harvest_config.rb +45 -0
  35. data/lib/new_relic/agent/configuration/high_security_source.rb +2 -1
  36. data/lib/new_relic/agent/configuration/manager.rb +17 -13
  37. data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
  38. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
  39. data/lib/new_relic/agent/configuration/security_policy_source.rb +15 -1
  40. data/lib/new_relic/agent/configuration/server_source.rb +39 -4
  41. data/lib/new_relic/agent/configuration/yaml_source.rb +12 -7
  42. data/lib/new_relic/agent/connect/request_builder.rb +63 -0
  43. data/lib/new_relic/agent/connect/response_handler.rb +61 -0
  44. data/lib/new_relic/agent/custom_event_aggregator.rb +1 -1
  45. data/lib/new_relic/agent/database.rb +2 -3
  46. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
  47. data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
  48. data/lib/new_relic/agent/database/obfuscator.rb +1 -1
  49. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
  50. data/lib/new_relic/agent/database_adapter.rb +33 -0
  51. data/lib/new_relic/agent/datastores.rb +7 -9
  52. data/lib/new_relic/agent/datastores/metric_helper.rb +2 -3
  53. data/lib/new_relic/agent/datastores/mongo.rb +2 -2
  54. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +3 -3
  55. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
  56. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +9 -9
  57. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +1 -1
  58. data/lib/new_relic/agent/datastores/redis.rb +1 -5
  59. data/lib/new_relic/agent/deprecator.rb +1 -1
  60. data/lib/new_relic/agent/distributed_tracing.rb +115 -32
  61. data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +3 -2
  62. data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +61 -46
  63. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +84 -0
  64. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  65. data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +32 -113
  66. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
  67. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
  68. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
  69. data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
  70. data/lib/new_relic/agent/error_collector.rb +88 -58
  71. data/lib/new_relic/agent/error_event_aggregator.rb +10 -7
  72. data/lib/new_relic/agent/error_filter.rb +167 -0
  73. data/lib/new_relic/agent/error_trace_aggregator.rb +2 -1
  74. data/lib/new_relic/agent/event_aggregator.rb +27 -33
  75. data/lib/new_relic/agent/event_buffer.rb +1 -1
  76. data/lib/new_relic/agent/event_listener.rb +1 -1
  77. data/lib/new_relic/agent/event_loop.rb +1 -1
  78. data/lib/new_relic/agent/external.rb +13 -11
  79. data/lib/new_relic/agent/guid_generator.rb +28 -0
  80. data/lib/new_relic/agent/harvester.rb +1 -1
  81. data/lib/new_relic/agent/heap.rb +1 -1
  82. data/lib/new_relic/agent/hostname.rb +16 -2
  83. data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
  84. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +25 -20
  85. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +29 -14
  86. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +18 -22
  87. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +11 -12
  88. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +17 -5
  89. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +5 -7
  90. data/lib/new_relic/agent/http_clients/uri_util.rb +12 -11
  91. data/lib/new_relic/agent/instrumentation.rb +1 -1
  92. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +26 -43
  93. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +53 -73
  94. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +81 -56
  95. data/lib/new_relic/agent/instrumentation/active_job.rb +7 -8
  96. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  97. data/lib/new_relic/agent/instrumentation/active_record.rb +85 -38
  98. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +17 -6
  99. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +152 -0
  100. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +35 -11
  101. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +47 -51
  102. data/lib/new_relic/agent/instrumentation/active_storage.rb +23 -0
  103. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +63 -0
  104. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +10 -9
  105. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  106. data/lib/new_relic/agent/instrumentation/bunny.rb +13 -132
  107. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +45 -0
  108. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +152 -0
  109. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +35 -0
  110. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +11 -4
  111. data/lib/new_relic/agent/instrumentation/curb.rb +11 -183
  112. data/lib/new_relic/agent/instrumentation/curb/chain.rb +93 -0
  113. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +222 -0
  114. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +63 -0
  115. data/lib/new_relic/agent/instrumentation/data_mapper.rb +5 -3
  116. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +38 -0
  117. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +53 -0
  118. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +34 -0
  119. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +9 -49
  120. data/lib/new_relic/agent/instrumentation/excon.rb +4 -3
  121. data/lib/new_relic/agent/instrumentation/excon/connection.rb +8 -5
  122. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -2
  123. data/lib/new_relic/agent/instrumentation/grape.rb +14 -107
  124. data/lib/new_relic/agent/instrumentation/grape/chain.rb +25 -0
  125. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +100 -0
  126. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +17 -0
  127. data/lib/new_relic/agent/instrumentation/httpclient.rb +10 -30
  128. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +25 -0
  129. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +38 -0
  130. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +17 -0
  131. data/lib/new_relic/agent/instrumentation/httprb.rb +29 -0
  132. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +22 -0
  133. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +30 -0
  134. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +15 -0
  135. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
  136. data/lib/new_relic/agent/instrumentation/memcache.rb +55 -68
  137. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +16 -0
  138. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +39 -118
  139. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +56 -0
  140. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +88 -0
  141. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +88 -0
  142. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  143. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  144. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +4 -2
  145. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +20 -11
  146. data/lib/new_relic/agent/instrumentation/mongo.rb +17 -4
  147. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +36 -3
  148. data/lib/new_relic/agent/instrumentation/net_http.rb +44 -0
  149. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +25 -0
  150. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +40 -0
  151. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +21 -0
  152. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +100 -0
  153. data/lib/new_relic/agent/instrumentation/padrino.rb +19 -52
  154. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +34 -0
  155. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +27 -0
  156. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +20 -0
  157. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
  158. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
  159. data/lib/new_relic/agent/instrumentation/rack.rb +30 -138
  160. data/lib/new_relic/agent/instrumentation/rack/chain.rb +58 -0
  161. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +32 -0
  162. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +73 -0
  163. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +37 -0
  164. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +1 -1
  165. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  166. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
  167. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
  168. data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_cable.rb +6 -7
  169. data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_controller.rb +4 -4
  170. data/lib/new_relic/agent/instrumentation/{rails4 → rails_notifications}/action_view.rb +4 -4
  171. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +1 -1
  172. data/lib/new_relic/agent/instrumentation/rake.rb +14 -155
  173. data/lib/new_relic/agent/instrumentation/rake/chain.rb +25 -0
  174. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +144 -0
  175. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +14 -0
  176. data/lib/new_relic/agent/instrumentation/redis.rb +13 -102
  177. data/lib/new_relic/agent/instrumentation/redis/chain.rb +34 -0
  178. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +65 -0
  179. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +24 -0
  180. data/lib/new_relic/agent/instrumentation/resque.rb +22 -30
  181. data/lib/new_relic/agent/instrumentation/resque/chain.rb +22 -0
  182. data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
  183. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +35 -0
  184. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +16 -0
  185. data/lib/new_relic/agent/instrumentation/sequel.rb +2 -2
  186. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
  187. data/lib/new_relic/agent/instrumentation/sidekiq.rb +48 -24
  188. data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -160
  189. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +55 -0
  190. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +30 -35
  191. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +124 -0
  192. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +33 -0
  193. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
  194. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  195. data/lib/new_relic/agent/instrumentation/typhoeus.rb +12 -74
  196. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +22 -0
  197. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +82 -0
  198. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +14 -0
  199. data/lib/new_relic/agent/internal_agent_error.rb +1 -1
  200. data/lib/new_relic/agent/javascript_instrumentor.rb +15 -10
  201. data/lib/new_relic/agent/log_once.rb +1 -1
  202. data/lib/new_relic/agent/logging.rb +139 -0
  203. data/lib/new_relic/agent/memory_logger.rb +1 -1
  204. data/lib/new_relic/agent/messaging.rb +15 -82
  205. data/lib/new_relic/agent/method_tracer.rb +10 -8
  206. data/lib/new_relic/agent/method_tracer_helpers.rb +5 -5
  207. data/lib/new_relic/agent/monitors.rb +27 -0
  208. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
  209. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
  210. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +4 -4
  211. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +4 -7
  212. data/lib/new_relic/agent/new_relic_service.rb +106 -40
  213. data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
  214. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -2
  215. data/lib/new_relic/agent/new_relic_service/marshaller.rb +6 -27
  216. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -1
  217. data/lib/new_relic/agent/noticible_error.rb +22 -0
  218. data/lib/new_relic/agent/null_logger.rb +1 -1
  219. data/lib/new_relic/agent/obfuscator.rb +1 -1
  220. data/lib/new_relic/agent/parameter_filtering.rb +19 -6
  221. data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
  222. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  223. data/lib/new_relic/agent/pipe_service.rb +1 -1
  224. data/lib/new_relic/agent/prepend_supportability.rb +1 -1
  225. data/lib/new_relic/agent/priority_sampled_buffer.rb +9 -4
  226. data/lib/new_relic/agent/range_extensions.rb +1 -1
  227. data/lib/new_relic/agent/rules_engine.rb +1 -1
  228. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +1 -1
  229. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
  230. data/lib/new_relic/agent/sampler.rb +1 -1
  231. data/lib/new_relic/agent/sampler_collection.rb +1 -1
  232. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  233. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -1
  234. data/lib/new_relic/agent/samplers/memory_sampler.rb +2 -2
  235. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  236. data/lib/new_relic/agent/samplers/vm_sampler.rb +1 -1
  237. data/lib/new_relic/agent/span_event_aggregator.rb +3 -5
  238. data/lib/new_relic/agent/span_event_primitive.rb +129 -65
  239. data/lib/new_relic/agent/sql_sampler.rb +12 -12
  240. data/lib/new_relic/agent/stats.rb +1 -1
  241. data/lib/new_relic/agent/stats_engine.rb +3 -3
  242. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +2 -2
  243. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  244. data/lib/new_relic/agent/supported_versions.rb +3 -3
  245. data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -1
  246. data/lib/new_relic/agent/system_info.rb +18 -4
  247. data/lib/new_relic/agent/threading/agent_thread.rb +2 -2
  248. data/lib/new_relic/agent/threading/backtrace_node.rb +1 -1
  249. data/lib/new_relic/agent/threading/backtrace_service.rb +4 -4
  250. data/lib/new_relic/agent/threading/thread_profile.rb +10 -24
  251. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
  252. data/lib/new_relic/agent/tracer.rb +509 -0
  253. data/lib/new_relic/agent/transaction.rb +143 -171
  254. data/lib/new_relic/agent/transaction/abstract_segment.rb +33 -6
  255. data/lib/new_relic/agent/transaction/datastore_segment.rb +1 -3
  256. data/lib/new_relic/agent/transaction/distributed_tracer.rb +177 -0
  257. data/lib/new_relic/agent/transaction/distributed_tracing.rb +59 -149
  258. data/lib/new_relic/agent/transaction/external_request_segment.rb +32 -39
  259. data/lib/new_relic/agent/transaction/message_broker_segment.rb +5 -12
  260. data/lib/new_relic/agent/transaction/request_attributes.rb +1 -1
  261. data/lib/new_relic/agent/transaction/segment.rb +28 -2
  262. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
  263. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  264. data/lib/new_relic/agent/transaction/trace.rb +6 -13
  265. data/lib/new_relic/agent/transaction/trace_builder.rb +1 -2
  266. data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
  267. data/lib/new_relic/agent/transaction/trace_node.rb +12 -8
  268. data/lib/new_relic/agent/transaction/tracing.rb +1 -100
  269. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
  270. data/lib/new_relic/agent/transaction_error_primitive.rb +11 -16
  271. data/lib/new_relic/agent/transaction_event_aggregator.rb +1 -1
  272. data/lib/new_relic/agent/transaction_event_primitive.rb +29 -40
  273. data/lib/new_relic/agent/transaction_event_recorder.rb +4 -4
  274. data/lib/new_relic/agent/transaction_metrics.rb +1 -1
  275. data/lib/new_relic/agent/transaction_sampler.rb +2 -6
  276. data/lib/new_relic/agent/transaction_time_aggregator.rb +50 -26
  277. data/lib/new_relic/agent/utilization/aws.rb +1 -1
  278. data/lib/new_relic/agent/utilization/azure.rb +1 -1
  279. data/lib/new_relic/agent/utilization/gcp.rb +1 -1
  280. data/lib/new_relic/agent/utilization/pcf.rb +1 -1
  281. data/lib/new_relic/agent/utilization/vendor.rb +1 -1
  282. data/lib/new_relic/agent/utilization_data.rb +37 -2
  283. data/lib/new_relic/agent/vm.rb +1 -1
  284. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
  285. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  286. data/lib/new_relic/agent/vm/mri_vm.rb +7 -5
  287. data/lib/new_relic/agent/vm/snapshot.rb +1 -1
  288. data/lib/new_relic/agent/worker_loop.rb +1 -1
  289. data/lib/new_relic/cli/command.rb +1 -1
  290. data/lib/new_relic/cli/commands/deployments.rb +2 -3
  291. data/lib/new_relic/cli/commands/install.rb +4 -3
  292. data/lib/new_relic/coerce.rb +32 -7
  293. data/lib/new_relic/collection_helper.rb +1 -1
  294. data/lib/new_relic/constants.rb +42 -0
  295. data/lib/new_relic/control.rb +1 -1
  296. data/lib/new_relic/control/class_methods.rb +8 -2
  297. data/lib/new_relic/control/frameworks.rb +1 -1
  298. data/lib/new_relic/control/frameworks/external.rb +1 -1
  299. data/lib/new_relic/control/frameworks/merb.rb +1 -1
  300. data/lib/new_relic/control/frameworks/rails.rb +12 -10
  301. data/lib/new_relic/control/frameworks/rails3.rb +1 -1
  302. data/lib/new_relic/control/frameworks/rails4.rb +1 -1
  303. data/lib/new_relic/control/frameworks/{rails5.rb → rails_notifications.rb} +2 -2
  304. data/lib/new_relic/control/frameworks/ruby.rb +1 -1
  305. data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
  306. data/lib/new_relic/control/instance_methods.rb +12 -2
  307. data/lib/new_relic/control/instrumentation.rb +1 -1
  308. data/lib/new_relic/control/server_methods.rb +1 -1
  309. data/lib/new_relic/delayed_job_injection.rb +1 -1
  310. data/lib/new_relic/dependency_detection.rb +124 -14
  311. data/lib/new_relic/environment_report.rb +2 -4
  312. data/lib/new_relic/helper.rb +1 -1
  313. data/lib/new_relic/language_support.rb +1 -1
  314. data/lib/new_relic/latest_changes.rb +4 -4
  315. data/lib/new_relic/local_environment.rb +1 -1
  316. data/lib/new_relic/metric_data.rb +1 -1
  317. data/lib/new_relic/metric_spec.rb +1 -1
  318. data/lib/new_relic/noticed_error.rb +38 -21
  319. data/lib/new_relic/rack.rb +1 -1
  320. data/lib/new_relic/rack/agent_hooks.rb +1 -1
  321. data/lib/new_relic/rack/agent_middleware.rb +2 -2
  322. data/lib/new_relic/rack/browser_monitoring.rb +16 -9
  323. data/lib/new_relic/recipes.rb +1 -1
  324. data/lib/new_relic/recipes/capistrano3.rb +1 -1
  325. data/lib/new_relic/recipes/capistrano_legacy.rb +1 -1
  326. data/lib/new_relic/supportability_helper.rb +16 -1
  327. data/lib/new_relic/version.rb +3 -3
  328. data/lib/newrelic_rpm.rb +1 -1
  329. data/lib/sequel/extensions/newrelic_instrumentation.rb +1 -1
  330. data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
  331. data/lib/tasks/all.rb +1 -1
  332. data/lib/tasks/config.html.erb +14 -25
  333. data/lib/tasks/config.rake +9 -9
  334. data/lib/tasks/multiverse.rb +35 -1
  335. data/lib/tasks/newrelic.rb +1 -1
  336. data/lib/tasks/tests.rake +6 -1
  337. data/newrelic_rpm.gemspec +22 -17
  338. data/recipes/newrelic.rb +1 -1
  339. data/test/agent_helper.rb +358 -78
  340. metadata +151 -66
  341. data/.travis.yml +0 -201
  342. data/cert/cacert.pem +0 -1177
  343. data/lib/new_relic/agent/commands/xray_session.rb +0 -55
  344. data/lib/new_relic/agent/commands/xray_session_collection.rb +0 -161
  345. data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
  346. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -41
  347. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
  348. data/lib/new_relic/agent/instrumentation/active_record_4.rb +0 -42
  349. data/lib/new_relic/agent/instrumentation/active_record_5.rb +0 -41
  350. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +0 -104
  351. data/lib/new_relic/agent/instrumentation/http.rb +0 -46
  352. data/lib/new_relic/agent/instrumentation/net.rb +0 -50
  353. data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +0 -32
  354. data/lib/new_relic/agent/instrumentation/rails5/action_view.rb +0 -27
  355. data/lib/new_relic/agent/transaction/attributes.rb +0 -154
  356. data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +0 -64
  357. data/lib/new_relic/agent/transaction_state.rb +0 -186
  358. data/lib/new_relic/build.rb +0 -2
  359. data/lib/new_relic/metrics.rb +0 -13
  360. data/lib/tasks/versions.html.erb +0 -28
  361. data/lib/tasks/versions.postface.html +0 -8
  362. data/lib/tasks/versions.preface.html +0 -9
  363. data/lib/tasks/versions.rake +0 -65
  364. data/lib/tasks/versions.txt.erb +0 -14
data/bin/nrdebug CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # encoding: utf-8
4
4
  # This file is distributed under New Relic's license terms.
5
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
5
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
6
6
 
7
7
  require 'tempfile'
8
8
  require 'rbconfig'
data/config.dot CHANGED
@@ -18,6 +18,7 @@ digraph AgentEnabled {
18
18
  "[error_collector.capture_source]"
19
19
  "[error_collector.enabled]"
20
20
  "[error_collector.ignore_errors]"
21
+ "[error_collector.max_backtrace_frames]"
21
22
  "[browser_monitoring.auto_instrument]"
22
23
  "[license_key]"
23
24
  "[verify_certificate]"
data/init.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  # This is the initialization for the New Relic Ruby Agent when used as
6
6
  # a plugin
data/install.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  if __FILE__ == $0 || $0 =~ /script\/plugin/ || File.basename($0) == 'rake'
6
6
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  require 'forwardable'
6
6
 
@@ -26,16 +26,15 @@ module NewRelic
26
26
 
27
27
  require 'new_relic/version'
28
28
  require 'new_relic/local_environment'
29
- require 'new_relic/metrics'
30
29
  require 'new_relic/metric_spec'
31
30
  require 'new_relic/metric_data'
32
31
  require 'new_relic/noticed_error'
32
+ require 'new_relic/agent/noticible_error'
33
33
  require 'new_relic/supportability_helper'
34
34
 
35
35
  require 'new_relic/agent/encoding_normalizer'
36
36
  require 'new_relic/agent/stats'
37
37
  require 'new_relic/agent/chained_call'
38
- require 'new_relic/agent/cross_app_monitor'
39
38
  require 'new_relic/agent/agent'
40
39
  require 'new_relic/agent/method_tracer'
41
40
  require 'new_relic/agent/worker_loop'
@@ -45,8 +44,10 @@ module NewRelic
45
44
  require 'new_relic/agent/sql_sampler'
46
45
  require 'new_relic/agent/commands/thread_profiler_session'
47
46
  require 'new_relic/agent/error_collector'
47
+ require 'new_relic/agent/error_filter'
48
48
  require 'new_relic/agent/sampler'
49
49
  require 'new_relic/agent/database'
50
+ require 'new_relic/agent/database_adapter'
50
51
  require 'new_relic/agent/datastores'
51
52
  require 'new_relic/agent/pipe_channel_manager'
52
53
  require 'new_relic/agent/configuration'
@@ -55,6 +56,9 @@ module NewRelic
55
56
  require 'new_relic/agent/system_info'
56
57
  require 'new_relic/agent/external'
57
58
  require 'new_relic/agent/deprecator'
59
+ require 'new_relic/agent/logging'
60
+ require 'new_relic/agent/distributed_tracing'
61
+ require 'new_relic/agent/attribute_processing'
58
62
 
59
63
  require 'new_relic/agent/instrumentation/controller_instrumentation'
60
64
 
@@ -76,7 +80,11 @@ module NewRelic
76
80
  class ForceDisconnectException < StandardError; end
77
81
 
78
82
  # An exception that forces an agent to restart.
79
- class ForceRestartException < StandardError; end
83
+ class ForceRestartException < StandardError
84
+ def message
85
+ "#{super}, restarting."
86
+ end
87
+ end
80
88
 
81
89
  # Used to blow out of a periodic task without logging a an error, such as for routine
82
90
  # failures.
@@ -276,12 +284,6 @@ module NewRelic
276
284
  def notice_error(exception, options={})
277
285
  record_api_supportability_metric(:notice_error)
278
286
 
279
- if options.has_key?(:trace_only)
280
- NewRelic::Agent.logger.log_once(:warn, :trace_only_deprecated,
281
- 'Passing the :trace_only option to NewRelic::Agent.notice_error is deprecated. Please use :expected instead.')
282
- options[:expected] = options.delete(:trace_only)
283
- end
284
-
285
287
  Transaction.notice_error(exception, options)
286
288
  nil # don't return a noticed error datastructure. it can only hurt.
287
289
  end
@@ -346,10 +348,9 @@ module NewRelic
346
348
  # @api public
347
349
  #
348
350
  def manual_start(options={})
349
- record_api_supportability_metric(:manual_start)
350
-
351
351
  raise "Options must be a hash" unless Hash === options
352
352
  NewRelic::Control.instance.init_plugin({ :agent_enabled => true, :sync_startup => true }.merge(options))
353
+ record_api_supportability_metric(:manual_start)
353
354
  end
354
355
 
355
356
  # Register this method as a callback for processes that fork
@@ -487,7 +488,7 @@ module NewRelic
487
488
  # Yield to the block without collecting any metrics or traces in
488
489
  # any of the subsequent calls. If executed recursively, will keep
489
490
  # track of the first entry point and turn on tracing again after
490
- # leaving that block. This uses the thread local TransactionState.
491
+ # leaving that block. This uses the thread local Tracer::State.
491
492
  #
492
493
  # @api public
493
494
  #
@@ -544,13 +545,13 @@ module NewRelic
544
545
 
545
546
  # Check to see if we are capturing metrics currently on this thread.
546
547
  def tl_is_execution_traced?
547
- NewRelic::Agent::TransactionState.tl_get.is_execution_traced?
548
+ NewRelic::Agent::Tracer.state.is_execution_traced?
548
549
  end
549
550
 
550
551
  # helper method to check the thread local to determine whether sql
551
552
  # is being recorded or not
552
553
  def tl_is_sql_recorded?
553
- NewRelic::Agent::TransactionState.tl_get.is_sql_recorded?
554
+ NewRelic::Agent::Tracer.state.is_sql_recorded?
554
555
  end
555
556
 
556
557
  # @!group Adding custom attributes to traces
@@ -563,6 +564,12 @@ module NewRelic
563
564
  # these custom attributes will also be present in the script injected into
564
565
  # the response body, making them available on Insights PageView events.
565
566
  #
567
+ #
568
+ # @param [Hash] params A Hash of attributes to be attached to the transaction event.
569
+ # Keys should be strings or symbols, and values
570
+ # may be strings, symbols, numeric values or
571
+ # booleans.
572
+ #
566
573
  # @api public
567
574
  #
568
575
  def add_custom_attributes(params) #THREAD_LOCAL_ACCESS
@@ -571,11 +578,43 @@ module NewRelic
571
578
  if params.is_a? Hash
572
579
  txn = Transaction.tl_current
573
580
  txn.add_custom_attributes(params) if txn
581
+
582
+ segment = ::NewRelic::Agent::Tracer.current_segment
583
+ if segment
584
+ # Make sure not to override existing segment-level custom attributes
585
+ segment_custom_keys = segment.attributes.custom_attributes.keys.map(&:to_sym)
586
+ segment.add_custom_attributes(params.reject { |k, _v| segment_custom_keys.include?(k.to_sym) })
587
+ end
574
588
  else
575
589
  ::NewRelic::Agent.logger.warn("Bad argument passed to #add_custom_attributes. Expected Hash but got #{params.class}")
576
590
  end
577
591
  end
578
592
 
593
+ # Add custom attributes to the span event for the current span. Attributes will be visible on spans in the
594
+ # New Relic Distributed Tracing UI and on span events in New Relic Insights.
595
+ #
596
+ # Custom attributes will not be transmitted when +high_security+ setting is enabled or
597
+ # +custom_attributes+ setting is disabled.
598
+ #
599
+ # @param [Hash] params A Hash of attributes to be attached to the span event.
600
+ # Keys should be strings or symbols, and values
601
+ # may be strings, symbols, numeric values or
602
+ # booleans.
603
+ #
604
+ # @see https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary#span
605
+ # @api public
606
+ def add_custom_span_attributes params
607
+ record_api_supportability_metric :add_custom_span_attributes
608
+
609
+ if params.is_a? Hash
610
+ if segment = NewRelic::Agent::Tracer.current_segment
611
+ segment.add_custom_attributes params
612
+ end
613
+ else
614
+ ::NewRelic::Agent.logger.warn "Bad argument passed to #add_custom_span_attributes. Expected Hash but got #{params.class}"
615
+ end
616
+ end
617
+
579
618
  # @!endgroup
580
619
 
581
620
  # @!group Transaction naming
@@ -584,7 +623,9 @@ module NewRelic
584
623
  # apply a reasonable default based on framework routing, but in
585
624
  # cases where this is insufficient, this can be used to manually
586
625
  # control the name of the transaction.
587
- # The category of transaction can be specified via the +:category+ option:
626
+ #
627
+ # The category of transaction can be specified via the +:category+ option.
628
+ # The following are the only valid categories:
588
629
  #
589
630
  # * <tt>:category => :controller</tt> indicates that this is a
590
631
  # controller action and will appear with all the other actions.
@@ -634,8 +675,8 @@ module NewRelic
634
675
  # @param [String] method the name of the finder method or other method to
635
676
  # identify the operation with.
636
677
  #
637
- def with_database_metric_name(model, method = nil, product = nil, &block) #THREAD_LOCAL_ACCESS
638
- if txn = Transaction.tl_current
678
+ def with_database_metric_name(model, method = nil, product = nil, &block)
679
+ if txn = Tracer.current_transaction
639
680
  txn.with_database_metric_name(model, method, product, &block)
640
681
  else
641
682
  yield
@@ -656,6 +697,54 @@ module NewRelic
656
697
  NewRelic::Agent.logger.debug "Ignoring exception during %p event notification" % [event_type]
657
698
  end
658
699
 
700
+ # @!group Trace and Entity metadata
701
+
702
+ TRACE_ID_KEY = 'trace.id'.freeze
703
+ SPAN_ID_KEY = 'span.id'.freeze
704
+ ENTITY_NAME_KEY = 'entity.name'.freeze
705
+ ENTITY_TYPE_KEY = 'entity.type'.freeze
706
+ ENTITY_GUID_KEY = 'entity.guid'.freeze
707
+ HOSTNAME_KEY = 'hostname'.freeze
708
+
709
+ ENTITY_TYPE = 'SERVICE'.freeze
710
+
711
+ # Returns a new hash containing trace and entity metadata that can be used
712
+ # to relate data to a trace or to an entity in APM.
713
+ #
714
+ # This hash includes:
715
+ # * trace.id - The current trace id, if there is a current trace id. This
716
+ # value may be omitted.
717
+ # * span.id - The current span id, if there is a current span. This
718
+ # value may be omitted.
719
+ # * entity.name - The name of the current application. This is read from
720
+ # the +app_name+ key in your config. If there are multiple application
721
+ # names, the first one is used.
722
+ # * entity.type - The entity type is hardcoded to the string +'SERVICE'+.
723
+ # * entity.guid - The guid of the current entity.
724
+ # * hostname - The fully qualified hostname.
725
+ #
726
+ # @api public
727
+ def linking_metadata
728
+ metadata = Hash.new
729
+ metadata[ENTITY_NAME_KEY] = config[:app_name][0]
730
+ metadata[ENTITY_TYPE_KEY] = ENTITY_TYPE
731
+ metadata[HOSTNAME_KEY] = Hostname.get
732
+
733
+ if entity_guid = config[:entity_guid]
734
+ metadata[ENTITY_GUID_KEY] = entity_guid
735
+ end
736
+
737
+ if trace_id = Tracer.current_trace_id
738
+ metadata[TRACE_ID_KEY] = trace_id
739
+ end
740
+ if span_id = Tracer.current_span_id
741
+ metadata[SPAN_ID_KEY] = span_id
742
+ end
743
+ metadata
744
+ end
745
+
746
+ #@!endgroup
747
+
659
748
  # @!group Manual browser monitoring configuration
660
749
 
661
750
  # This method returns a string suitable for inclusion in a page - known as
@@ -670,13 +759,15 @@ module NewRelic
670
759
  # In previous agents there was a corresponding footer required, but all the
671
760
  # work is now done by this single method.
672
761
  #
762
+ # @param [String] nonce The nonce to use in the javascript tag for browser instrumentation
763
+ #
673
764
  # @api public
674
765
  #
675
- def browser_timing_header
766
+ def browser_timing_header(nonce=nil)
676
767
  record_api_supportability_metric(:browser_timing_header)
677
768
 
678
769
  return "" unless agent
679
- agent.javascript_instrumentor.browser_timing_header
770
+ agent.javascript_instrumentor.browser_timing_header(nonce)
680
771
  end
681
772
 
682
773
  # @!endgroup
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  module NewRelic
6
6
  module Agent
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
5
  require 'socket'
6
6
  require 'net/https'
@@ -8,6 +8,8 @@ require 'net/http'
8
8
  require 'logger'
9
9
  require 'zlib'
10
10
  require 'stringio'
11
+ require 'new_relic/constants'
12
+ require 'new_relic/coerce'
11
13
  require 'new_relic/agent/autostart'
12
14
  require 'new_relic/agent/harvester'
13
15
  require 'new_relic/agent/hostname'
@@ -15,11 +17,11 @@ require 'new_relic/agent/new_relic_service'
15
17
  require 'new_relic/agent/pipe_service'
16
18
  require 'new_relic/agent/configuration/manager'
17
19
  require 'new_relic/agent/database'
20
+ require 'new_relic/agent/instrumentation/resque/helper'
18
21
  require 'new_relic/agent/commands/agent_command_router'
19
22
  require 'new_relic/agent/event_listener'
20
- require 'new_relic/agent/cross_app_monitor'
21
- require 'new_relic/agent/distributed_trace_monitor'
22
- require 'new_relic/agent/synthetics_monitor'
23
+ require 'new_relic/agent/distributed_tracing'
24
+ require 'new_relic/agent/monitors'
23
25
  require 'new_relic/agent/transaction_event_recorder'
24
26
  require 'new_relic/agent/custom_event_aggregator'
25
27
  require 'new_relic/agent/span_event_aggregator'
@@ -30,6 +32,8 @@ require 'new_relic/agent/utilization_data'
30
32
  require 'new_relic/environment_report'
31
33
  require 'new_relic/agent/attribute_filter'
32
34
  require 'new_relic/agent/adaptive_sampler'
35
+ require 'new_relic/agent/connect/request_builder'
36
+ require 'new_relic/agent/connect/response_handler'
33
37
 
34
38
  module NewRelic
35
39
  module Agent
@@ -46,35 +50,33 @@ module NewRelic
46
50
  def initialize
47
51
  @started = false
48
52
  @event_loop = nil
53
+ @worker_thread = nil
49
54
 
50
55
  @service = NewRelicService.new
51
56
 
52
- @events = NewRelic::Agent::EventListener.new
53
- @stats_engine = NewRelic::Agent::StatsEngine.new
54
- @transaction_sampler = NewRelic::Agent::TransactionSampler.new
55
- @sql_sampler = NewRelic::Agent::SqlSampler.new
56
- @agent_command_router = NewRelic::Agent::Commands::AgentCommandRouter.new(@events)
57
- @cross_app_monitor = NewRelic::Agent::CrossAppMonitor.new(@events)
58
- @distributed_trace_monitor = NewRelic::Agent::DistributedTraceMonitor.new(@events)
59
- @synthetics_monitor = NewRelic::Agent::SyntheticsMonitor.new(@events)
60
- @error_collector = NewRelic::Agent::ErrorCollector.new
61
- @transaction_rules = NewRelic::Agent::RulesEngine.new
62
- @harvest_samplers = NewRelic::Agent::SamplerCollection.new(@events)
63
- @monotonic_gc_profiler = NewRelic::Agent::VM::MonotonicGCProfiler.new
64
- @javascript_instrumentor = NewRelic::Agent::JavascriptInstrumentor.new(@events)
65
- @adaptive_sampler = NewRelic::Agent::AdaptiveSampler.new(self.class.config[:sampling_target],
66
- self.class.config[:sampling_target_period_in_seconds])
67
-
68
- @harvester = NewRelic::Agent::Harvester.new(@events)
57
+ @events = EventListener.new
58
+ @stats_engine = StatsEngine.new
59
+ @transaction_sampler = TransactionSampler.new
60
+ @sql_sampler = SqlSampler.new
61
+ @agent_command_router = Commands::AgentCommandRouter.new @events
62
+ @monitors = Monitors.new @events
63
+ @error_collector = ErrorCollector.new @events
64
+ @transaction_rules = RulesEngine.new
65
+ @harvest_samplers = SamplerCollection.new @events
66
+ @monotonic_gc_profiler = VM::MonotonicGCProfiler.new
67
+ @javascript_instrumentor = JavascriptInstrumentor.new @events
68
+ @adaptive_sampler = AdaptiveSampler.new(Agent.config[:sampling_target],
69
+ Agent.config[:sampling_target_period_in_seconds])
70
+
71
+ @harvester = Harvester.new @events
69
72
  @after_fork_lock = Mutex.new
70
73
 
71
- @transaction_event_recorder = NewRelic::Agent::TransactionEventRecorder.new
72
- @custom_event_aggregator = NewRelic::Agent::CustomEventAggregator.new
73
- @span_event_aggregator = NewRelic::Agent::SpanEventAggregator.new
74
+ @transaction_event_recorder = TransactionEventRecorder.new @events
75
+ @custom_event_aggregator = CustomEventAggregator.new @events
76
+ @span_event_aggregator = SpanEventAggregator.new @events
74
77
 
75
78
  @connect_state = :pending
76
79
  @connect_attempts = 0
77
- @environment_report = nil
78
80
  @waited_on_connect = nil
79
81
  @connected_pid = nil
80
82
 
@@ -87,13 +89,13 @@ module NewRelic
87
89
  def setup_attribute_filter
88
90
  refresh_attribute_filter
89
91
 
90
- @events.subscribe(:finished_configuring) do
92
+ @events.subscribe(:initial_configuration_complete) do
91
93
  refresh_attribute_filter
92
94
  end
93
95
  end
94
96
 
95
97
  def refresh_attribute_filter
96
- @attribute_filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config)
98
+ @attribute_filter = AttributeFilter.new(Agent.config)
97
99
  end
98
100
 
99
101
  # contains all the class-level methods for NewRelic::Agent::Agent
@@ -126,17 +128,20 @@ module NewRelic
126
128
  # cross application tracing ids and encoding
127
129
  attr_reader :cross_process_id
128
130
  attr_reader :cross_app_encoding_bytes
129
- attr_reader :cross_app_monitor
130
131
  # service for communicating with collector
131
132
  attr_accessor :service
132
133
  # Global events dispatcher. This will provides our primary mechanism
133
134
  # for agent-wide events, such as finishing configuration, error notification
134
135
  # and request before/after from Rack.
135
136
  attr_reader :events
137
+
138
+ # listens and responds to events that need to process headers
139
+ # for synthetics and distributed tracing
140
+ attr_reader :monitors
136
141
  # Transaction and metric renaming rules as provided by the
137
142
  # collector on connect. The former are applied during txns,
138
143
  # the latter during harvest.
139
- attr_reader :transaction_rules
144
+ attr_accessor :transaction_rules
140
145
  # Responsbile for restarting the harvest thread
141
146
  attr_reader :harvester
142
147
  # GC::Profiler.total_time is not monotonic so we wrap it.
@@ -146,6 +151,7 @@ module NewRelic
146
151
  attr_reader :transaction_event_recorder
147
152
  attr_reader :attribute_filter
148
153
  attr_reader :adaptive_sampler
154
+ attr_reader :environment_report
149
155
 
150
156
  def transaction_event_aggregator
151
157
  @transaction_event_recorder.transaction_event_aggregator
@@ -155,6 +161,10 @@ module NewRelic
155
161
  @transaction_event_recorder.synthetics_event_aggregator
156
162
  end
157
163
 
164
+ def agent_id=(agent_id)
165
+ @service.agent_id = agent_id
166
+ end
167
+
158
168
  # This method should be called in a forked process after a fork.
159
169
  # It assumes the parent process initialized the agent, but does
160
170
  # not assume the agent started.
@@ -200,7 +210,7 @@ module NewRelic
200
210
  end
201
211
 
202
212
  def install_pipe_service(channel_id)
203
- @service = NewRelic::Agent::PipeService.new(channel_id)
213
+ @service = PipeService.new(channel_id)
204
214
  if connected?
205
215
  @connected_pid = Process.pid
206
216
  else
@@ -231,12 +241,25 @@ module NewRelic
231
241
  end
232
242
 
233
243
  def revert_to_default_configuration
234
- NewRelic::Agent.config.remove_config_type(:manual)
235
- NewRelic::Agent.config.remove_config_type(:server)
244
+ Agent.config.remove_config_type(:manual)
245
+ Agent.config.remove_config_type(:server)
236
246
  end
237
247
 
248
+ # If the @worker_thread encounters an error during the attempt to connect to the collector
249
+ # then the connect attempts enter an exponential backoff retry loop. To avoid potential
250
+ # race conditions with shutting down while also attempting to reconnect, we join the
251
+ # @worker_thread with a timeout threshold. This allows potentially connecting and flushing
252
+ # pending data to the server, but without waiting indefinitely for a reconnect to succeed.
253
+ # The use-case where this typically arises is in cronjob scheduled rake tasks where there's
254
+ # also some network stability/latency issues happening.
238
255
  def stop_event_loop
239
256
  @event_loop.stop if @event_loop
257
+ # Wait the end of the event loop thread.
258
+ if @worker_thread
259
+ unless @worker_thread.join(3)
260
+ ::NewRelic::Agent.logger.debug "Event loop thread did not stop within 3 seconds"
261
+ end
262
+ end
240
263
  end
241
264
 
242
265
  def trap_signals_for_litespeed
@@ -262,7 +285,7 @@ module NewRelic
262
285
  # should not record sql in the current thread. Returns the
263
286
  # previous value, if there is one
264
287
  def set_record_sql(should_record) #THREAD_LOCAL_ACCESS
265
- state = TransactionState.tl_get
288
+ state = Tracer.state
266
289
  prev = state.record_sql
267
290
  state.record_sql = should_record
268
291
  prev.nil? || prev
@@ -273,13 +296,13 @@ module NewRelic
273
296
  # children of a transaction without affecting the tracing of
274
297
  # the whole transaction
275
298
  def push_trace_execution_flag(should_trace=false) #THREAD_LOCAL_ACCESS
276
- TransactionState.tl_get.push_traced(should_trace)
299
+ Tracer.state.push_traced(should_trace)
277
300
  end
278
301
 
279
302
  # Pop the current trace execution status. Restore trace execution status
280
303
  # to what it was before we pushed the current flag.
281
304
  def pop_trace_execution_flag #THREAD_LOCAL_ACCESS
282
- TransactionState.tl_get.pop_traced
305
+ Tracer.state.pop_traced
283
306
  end
284
307
 
285
308
  # Herein lies the corpse of the former 'start' method. May
@@ -327,7 +350,7 @@ module NewRelic
327
350
  end
328
351
 
329
352
  def log_app_name
330
- ::NewRelic::Agent.logger.info "Application: #{Agent.config.app_names.join(", ")}"
353
+ ::NewRelic::Agent.logger.info "Application: #{Agent.config[:app_name].join(", ")}"
331
354
  end
332
355
 
333
356
  def log_ignore_url_regexes
@@ -340,7 +363,7 @@ module NewRelic
340
363
 
341
364
  # Logs the configured application names
342
365
  def app_name_configured?
343
- names = Agent.config.app_names
366
+ names = Agent.config[:app_name]
344
367
  return names.respond_to?(:any?) && names.any?
345
368
  end
346
369
 
@@ -373,10 +396,8 @@ module NewRelic
373
396
  end
374
397
 
375
398
  def should_install_exit_handler?
376
- (
377
- Agent.config[:send_data_on_exit] &&
378
- !sinatra_classic_app?
379
- )
399
+ return false unless Agent.config[:send_data_on_exit]
400
+ !sinatra_classic_app? || Agent.config[:force_install_exit_handler]
380
401
  end
381
402
 
382
403
  def install_exit_handler
@@ -450,12 +471,12 @@ module NewRelic
450
471
  # before Resque calls Process.daemon (Jira RUBY-857)
451
472
  def defer_for_resque?
452
473
  NewRelic::Agent.config[:dispatcher] == :resque &&
453
- NewRelic::LanguageSupport.can_fork? &&
454
- !NewRelic::Agent::PipeChannelManager.listener.started?
474
+ NewRelic::Agent::Instrumentation::Resque::Helper.resque_fork_per_job? &&
475
+ !PipeChannelManager.listener.started?
455
476
  end
456
477
 
457
478
  def in_resque_child_process?
458
- defined?(@service) && @service.is_a?(NewRelic::Agent::PipeService)
479
+ defined?(@service) && @service.is_a?(PipeService)
459
480
  end
460
481
 
461
482
  # Sanity-check the agent configuration and start the agent,
@@ -476,8 +497,8 @@ module NewRelic
476
497
  @harvester.mark_started
477
498
 
478
499
  unless in_resque_child_process?
479
- generate_environment_report
480
500
  install_exit_handler
501
+ environment_for_connect
481
502
  @harvest_samplers.load_samplers unless Agent.config[:disable_samplers]
482
503
  end
483
504
 
@@ -527,7 +548,7 @@ module NewRelic
527
548
  check_config_and_start_agent
528
549
  log_version_and_pid
529
550
 
530
- events.subscribe(:finished_configuring) do
551
+ events.subscribe(:initial_configuration_complete) do
531
552
  log_ignore_url_regexes
532
553
  end
533
554
  end
@@ -543,7 +564,7 @@ module NewRelic
543
564
  @sql_sampler.reset!
544
565
 
545
566
  if Agent.config[:clear_transaction_state_after_fork]
546
- TransactionState.tl_clear
567
+ Tracer.clear_state
547
568
  end
548
569
  end
549
570
 
@@ -551,13 +572,16 @@ module NewRelic
551
572
  # This is necessary for cases where we're in a forked child and Ruby
552
573
  # might be holding locks for background thread that aren't there anymore.
553
574
  def reset_objects_with_locks
554
- @stats_engine = NewRelic::Agent::StatsEngine.new
575
+ @stats_engine = StatsEngine.new
555
576
  end
556
577
 
557
578
  def flush_pipe_data
558
- if connected? && @service.is_a?(::NewRelic::Agent::PipeService)
579
+ if connected? && @service.is_a?(PipeService)
559
580
  transmit_data
560
- transmit_event_data
581
+ transmit_analytic_event_data
582
+ transmit_custom_event_data
583
+ transmit_error_event_data
584
+ transmit_span_event_data
561
585
  end
562
586
  end
563
587
 
@@ -571,40 +595,48 @@ module NewRelic
571
595
  EventLoop.new
572
596
  end
573
597
 
574
- # Never allow any data type to be reported more frequently than once
575
- # per second.
576
- MIN_ALLOWED_REPORT_PERIOD = 1.0
598
+ LOG_ONCE_KEYS_RESET_PERIOD = 60.0
577
599
 
578
- def report_period_for(method)
579
- config_key = "data_report_periods.#{method}".to_sym
580
- period = Agent.config[config_key]
581
- if !period
582
- period = Agent.config[:data_report_period]
583
- ::NewRelic::Agent.logger.warn("Could not find configured period for #{method}, falling back to data_report_period (#{period} s)")
584
- end
585
- if period < MIN_ALLOWED_REPORT_PERIOD
586
- ::NewRelic::Agent.logger.warn("Configured #{config_key} was #{period}, but minimum allowed is #{MIN_ALLOWED_REPORT_PERIOD}, using #{MIN_ALLOWED_REPORT_PERIOD}.")
587
- period = MIN_ALLOWED_REPORT_PERIOD
588
- end
589
- period
600
+ # Certain event types may sometimes need to be on the same interval as metrics,
601
+ # so we will check config assigned in EventHarvestConfig to determine the interval
602
+ # on which to report them
603
+ def interval_for event_type
604
+ interval = Agent.config[:"event_report_period.#{event_type}"]
605
+ :"#{interval}_second_harvest"
590
606
  end
591
607
 
592
- LOG_ONCE_KEYS_RESET_PERIOD = 60.0
608
+ ANALYTIC_EVENT_DATA = "analytic_event_data".freeze
609
+ CUSTOM_EVENT_DATA = "custom_event_data".freeze
610
+ ERROR_EVENT_DATA = "error_event_data".freeze
611
+ SPAN_EVENT_DATA = "span_event_data".freeze
593
612
 
594
613
  def create_and_run_event_loop
614
+ data_harvest = :"#{Agent.config[:data_report_period]}_second_harvest"
615
+ event_harvest = :"#{Agent.config[:event_report_period]}_second_harvest"
616
+
595
617
  @event_loop = create_event_loop
596
- @event_loop.on(:report_data) do
618
+ @event_loop.on(data_harvest) do
597
619
  transmit_data
598
620
  end
599
- @event_loop.on(:report_event_data) do
600
- transmit_event_data
621
+
622
+ @event_loop.on(interval_for ANALYTIC_EVENT_DATA) do
623
+ transmit_analytic_event_data
624
+ end
625
+ @event_loop.on(interval_for CUSTOM_EVENT_DATA) do
626
+ transmit_custom_event_data
627
+ end
628
+ @event_loop.on(interval_for ERROR_EVENT_DATA) do
629
+ transmit_error_event_data
630
+ end
631
+ @event_loop.on(interval_for SPAN_EVENT_DATA) do
632
+ transmit_span_event_data
601
633
  end
602
634
  @event_loop.on(:reset_log_once_keys) do
603
635
  ::NewRelic::Agent.logger.clear_already_logged
604
636
  end
605
- @event_loop.fire_every(Agent.config[:data_report_period], :report_data)
606
- @event_loop.fire_every(report_period_for(:analytic_event_data), :report_event_data)
607
- @event_loop.fire_every(LOG_ONCE_KEYS_RESET_PERIOD, :reset_log_once_keys)
637
+ @event_loop.fire_every(Agent.config[:data_report_period], data_harvest)
638
+ @event_loop.fire_every(Agent.config[:event_report_period], event_harvest)
639
+ @event_loop.fire_every(LOG_ONCE_KEYS_RESET_PERIOD, :reset_log_once_keys)
608
640
 
609
641
  @event_loop.run
610
642
  end
@@ -624,7 +656,7 @@ module NewRelic
624
656
  # is the worker thread that gathers data and talks to the
625
657
  # server.
626
658
  def handle_force_disconnect(error)
627
- ::NewRelic::Agent.logger.warn "New Relic forced this agent to disconnect (#{error.message})"
659
+ ::NewRelic::Agent.logger.warn "Agent received a ForceDisconnectException from the server, disconnecting. (#{error.message})"
628
660
  disconnect
629
661
  end
630
662
 
@@ -632,7 +664,7 @@ module NewRelic
632
664
  # it and disconnecting the agent, since we are now in an
633
665
  # unknown state.
634
666
  def handle_other_error(error)
635
- ::NewRelic::Agent.logger.error "Unhandled error in worker thread, disconnecting this agent process:"
667
+ ::NewRelic::Agent.logger.error "Unhandled error in worker thread, disconnecting."
636
668
  # These errors are fatal (that is, they will prevent the agent from
637
669
  # reporting entirely), so we really want backtraces when they happen
638
670
  ::NewRelic::Agent.logger.log_exception(:error, error)
@@ -688,7 +720,7 @@ module NewRelic
688
720
  end
689
721
 
690
722
  ::NewRelic::Agent.logger.debug "Creating Ruby Agent worker thread."
691
- @worker_thread = NewRelic::Agent::Threading::AgentThread.create('Worker Loop') do
723
+ @worker_thread = Threading::AgentThread.create('Worker Loop') do
692
724
  deferred_work!(connection_options)
693
725
  end
694
726
  end
@@ -727,12 +759,12 @@ module NewRelic
727
759
  force || (!connected? && !disconnected?)
728
760
  end
729
761
 
730
- # Retry period is a minute for each failed attempt that
731
- # we've made. This should probably do some sort of sane TCP
732
- # backoff to prevent hammering the server, but a minute for
733
- # each attempt seems to work reasonably well.
762
+ # Per the spec at
763
+ # /agents/agent-specs/Collector-Response-Handling.md, retry
764
+ # connections after a specific backoff sequence to prevent
765
+ # hammering the server.
734
766
  def connect_retry_period
735
- [600, connect_attempts * 60].min
767
+ NewRelic::CONNECT_RETRY_PERIODS[connect_attempts] || NewRelic::MAX_RETRY_PERIOD
736
768
  end
737
769
 
738
770
  def note_connect_failure
@@ -766,106 +798,59 @@ module NewRelic
766
798
  shutdown
767
799
  end
768
800
 
769
- def generate_environment_report
770
- @environment_report = environment_for_connect
771
- end
772
-
773
801
  # Checks whether we should send environment info, and if so,
774
802
  # returns the snapshot from the local environment.
775
803
  # Generating the EnvironmentReport has the potential to trigger
776
804
  # require calls in Rails environments, so this method should only
777
805
  # be called synchronously from on the main thread.
778
806
  def environment_for_connect
779
- Agent.config[:send_environment_info] ? Array(EnvironmentReport.new) : []
807
+ @environment_report ||= Agent.config[:send_environment_info] ? Array(EnvironmentReport.new) : []
780
808
  end
781
809
 
782
- # We've seen objects in the environment report (Rails.env in
783
- # particular) that can't seralize to JSON. Cope with that here and
784
- # clear out so downstream code doesn't have to check again.
785
- def sanitize_environment_report
786
- if !@service.valid_to_marshal?(@environment_report)
787
- @environment_report = []
788
- end
810
+ # Constructs and memoizes an event_harvest_config hash to be used in
811
+ # the payload sent during connect (and reconnect)
812
+ def event_harvest_config
813
+ @event_harvest_config ||= Configuration::EventHarvestConfig.from_config(Agent.config)
789
814
  end
790
815
 
791
- # Initializes the hash of settings that we send to the
792
- # server. Returns a literal hash containing the options
793
- def connect_settings
794
- sanitize_environment_report
795
-
796
- {
797
- :pid => $$,
798
- :host => local_host,
799
- :display_host => Agent.config[:'process_host.display_name'],
800
- :app_name => Agent.config.app_names,
801
- :language => 'ruby',
802
- :labels => Agent.config.parsed_labels,
803
- :agent_version => NewRelic::VERSION::STRING,
804
- :environment => @environment_report,
805
- :settings => Agent.config.to_collector_hash,
806
- :high_security => Agent.config[:high_security],
807
- :utilization => UtilizationData.new.to_collector_hash,
808
- :identifier => "ruby:#{local_host}:#{Agent.config.app_names.sort.join(',')}"
809
- }
810
- end
811
-
812
- # Returns connect data passed back from the server
816
+ # Builds the payload to send to the connect service,
817
+ # connects, then configures the agent using the response from
818
+ # the connect service
813
819
  def connect_to_server
814
- @service.connect(connect_settings)
815
- end
820
+ request_builder = ::NewRelic::Agent::Connect::RequestBuilder.new \
821
+ @service,
822
+ Agent.config,
823
+ event_harvest_config,
824
+ environment_for_connect
825
+ connect_response = @service.connect request_builder.connect_payload
816
826
 
817
- # apdex_f is always 4 times the apdex_t
818
- def apdex_f
819
- (4 * Agent.config[:apdex_t]).to_f
820
- end
827
+ response_handler = ::NewRelic::Agent::Connect::ResponseHandler.new(self, Agent.config)
828
+ response_handler.configure_agent(connect_response)
821
829
 
822
- # Sets the collector host and connects to the server, then
823
- # invokes the final configuration with the returned data
824
- def query_server_for_configuration
825
- finish_setup(connect_to_server)
830
+ log_connection connect_response if connect_response
831
+ connect_response
826
832
  end
827
833
 
828
- # Takes a hash of configuration data returned from the
829
- # server and uses it to set local variables and to
830
- # initialize various parts of the agent that are configured
831
- # separately.
832
- #
833
- # Can accommodate most arbitrary data - anything extra is
834
- # ignored unless we say to do something with it here.
835
- def finish_setup(config_data)
836
- return if config_data == nil
837
-
838
- @service.agent_id = config_data['agent_run_id']
839
-
840
- security_policies = config_data.delete('security_policies')
841
-
842
- add_server_side_config(config_data)
843
- add_security_policy_config(security_policies) if security_policies
844
-
845
- log_connection!(config_data)
846
- @transaction_rules = RulesEngine.create_transaction_rules(config_data)
847
- @stats_engine.metric_rules = RulesEngine.create_metric_rules(config_data)
848
-
849
- # If you're adding something else here to respond to the server-side config,
850
- # use Agent.instance.events.subscribe(:finished_configuring) callback instead!
834
+ # Logs when we connect to the server, for debugging purposes
835
+ # - makes sure we know if an agent has not connected
836
+ def log_connection(config_data)
837
+ ::NewRelic::Agent.logger.debug "Connected to NewRelic Service at #{@service.collector.name}"
838
+ ::NewRelic::Agent.logger.debug "Agent Run = #{@service.agent_id}."
839
+ ::NewRelic::Agent.logger.debug "Connection data = #{config_data.inspect}"
840
+ if config_data['messages'] && config_data['messages'].any?
841
+ log_collector_messages(config_data['messages'])
842
+ end
851
843
  end
852
844
 
853
- def add_server_side_config(config_data)
854
- if config_data['agent_config']
855
- ::NewRelic::Agent.logger.debug "Using config from server"
845
+ def log_collector_messages(messages)
846
+ messages.each do |message|
847
+ ::NewRelic::Agent.logger.send(message['level'].downcase, message['message'])
856
848
  end
857
-
858
- ::NewRelic::Agent.logger.debug "Server provided config: #{config_data.inspect}"
859
- server_config = NewRelic::Agent::Configuration::ServerSource.new(config_data, Agent.config)
860
- Agent.config.replace_or_add_config(server_config)
861
849
  end
862
850
 
863
- def add_security_policy_config(security_policies)
864
- ::NewRelic::Agent.logger.info 'Installing security policies'
865
- security_policy_source = NewRelic::Agent::Configuration::SecurityPolicySource.new(security_policies)
866
- Agent.config.replace_or_add_config(security_policy_source)
867
- # drop data collected before applying security policies
868
- drop_buffered_data
851
+ # apdex_f is always 4 times the apdex_t
852
+ def apdex_f
853
+ (4 * Agent.config[:apdex_t]).to_f
869
854
  end
870
855
 
871
856
  class WaitOnConnectTimeout < StandardError
@@ -897,22 +882,6 @@ module NewRelic
897
882
  end
898
883
  end
899
884
 
900
- # Logs when we connect to the server, for debugging purposes
901
- # - makes sure we know if an agent has not connected
902
- def log_connection!(config_data)
903
- ::NewRelic::Agent.logger.debug "Connected to NewRelic Service at #{@service.collector.name}"
904
- ::NewRelic::Agent.logger.debug "Agent Run = #{@service.agent_id}."
905
- ::NewRelic::Agent.logger.debug "Connection data = #{config_data.inspect}"
906
- if config_data['messages'] && config_data['messages'].any?
907
- log_collector_messages(config_data['messages'])
908
- end
909
- end
910
-
911
- def log_collector_messages(messages)
912
- messages.each do |message|
913
- ::NewRelic::Agent.logger.send(message['level'].downcase, message['message'])
914
- end
915
- end
916
885
  end
917
886
  include Connect
918
887
 
@@ -972,7 +941,7 @@ module NewRelic
972
941
  return unless should_connect?(opts[:force_reconnect])
973
942
 
974
943
  ::NewRelic::Agent.logger.debug "Connecting Process to New Relic: #$0"
975
- query_server_for_configuration
944
+ connect_to_server
976
945
  @connected_pid = $$
977
946
  @connect_state = :connected
978
947
  signal_connected
@@ -983,6 +952,10 @@ module NewRelic
983
952
  rescue NewRelic::Agent::UnrecoverableAgentException => e
984
953
  handle_unrecoverable_agent_error(e)
985
954
  rescue StandardError, Timeout::Error, NewRelic::Agent::ServerConnectionException => e
955
+ # Allow a killed (aborting) thread to continue exiting during shutdown.
956
+ # See: https://github.com/newrelic/newrelic-ruby-agent/issues/340
957
+ raise if Thread.current.status == 'aborting'
958
+
986
959
  log_error(e)
987
960
  if opts[:keep_retrying]
988
961
  note_connect_failure
@@ -996,15 +969,6 @@ module NewRelic
996
969
  raise
997
970
  end
998
971
 
999
- # Who am I? Well, this method can tell you your hostname.
1000
- def determine_host
1001
- NewRelic::Agent::Hostname.get
1002
- end
1003
-
1004
- def local_host
1005
- @local_host ||= determine_host
1006
- end
1007
-
1008
972
  # Delegates to the control class to determine the root
1009
973
  # directory of this project
1010
974
  def determine_home_directory
@@ -1075,7 +1039,7 @@ module NewRelic
1075
1039
  end
1076
1040
 
1077
1041
  def harvest_and_send_timeslice_data
1078
- NewRelic::Agent::TransactionTimeAggregator.harvest!
1042
+ TransactionTimeAggregator.harvest!
1079
1043
  harvest_and_send_from_container(@stats_engine, :metric_data)
1080
1044
  end
1081
1045
 
@@ -1104,19 +1068,27 @@ module NewRelic
1104
1068
  def harvest_and_send_analytic_event_data
1105
1069
  harvest_and_send_from_container(transaction_event_aggregator, :analytic_event_data)
1106
1070
  harvest_and_send_from_container(synthetics_event_aggregator, :analytic_event_data)
1107
- harvest_and_send_from_container(@custom_event_aggregator, :custom_event_data)
1108
- harvest_and_send_from_container(span_event_aggregator, :span_event_data)
1071
+ end
1072
+
1073
+ def harvest_and_send_custom_event_data
1074
+ harvest_and_send_from_container(@custom_event_aggregator, :custom_event_data)
1109
1075
  end
1110
1076
 
1111
1077
  def harvest_and_send_error_event_data
1112
1078
  harvest_and_send_from_container @error_collector.error_event_aggregator, :error_event_data
1113
1079
  end
1114
1080
 
1081
+ def harvest_and_send_span_event_data
1082
+ harvest_and_send_from_container(span_event_aggregator, :span_event_data)
1083
+ end
1084
+
1115
1085
  def check_for_and_handle_agent_commands
1116
1086
  begin
1117
1087
  @agent_command_router.check_for_and_handle_agent_commands
1118
1088
  rescue ForceRestartException, ForceDisconnectException
1119
1089
  raise
1090
+ rescue UnrecoverableServerException => e
1091
+ NewRelic::Agent.logger.warn("get_agent_commands message was rejected by remote service, discarding. Error: ", e)
1120
1092
  rescue ServerConnectionException => e
1121
1093
  log_remote_unavailable(:get_agent_commands, e)
1122
1094
  rescue => e
@@ -1130,18 +1102,30 @@ module NewRelic
1130
1102
  NewRelic::Agent.record_metric("Supportability/remote_unavailable/#{endpoint.to_s}", 0.0)
1131
1103
  end
1132
1104
 
1133
- def transmit_event_data
1134
- transmit_single_data_type(:harvest_and_send_analytic_event_data, "TransactionEvent")
1105
+ TRANSACTION_EVENT = "TransactionEvent".freeze
1106
+ def transmit_analytic_event_data
1107
+ transmit_single_data_type(:harvest_and_send_analytic_event_data, TRANSACTION_EVENT)
1108
+ end
1109
+
1110
+ CUSTOM_EVENT = "CustomEvent".freeze
1111
+ def transmit_custom_event_data
1112
+ transmit_single_data_type(:harvest_and_send_custom_event_data, CUSTOM_EVENT)
1113
+ end
1114
+
1115
+ ERROR_EVENT = "ErrorEvent".freeze
1116
+ def transmit_error_event_data
1117
+ transmit_single_data_type(:harvest_and_send_error_event_data, ERROR_EVENT)
1135
1118
  end
1136
1119
 
1120
+ SPAN_EVENT = "SpanEvent".freeze
1137
1121
  def transmit_span_event_data
1138
- transmit_single_data_type(:harvest_and_send_span_event_data, "SpanEvent")
1122
+ transmit_single_data_type(:harvest_and_send_span_event_data, SPAN_EVENT)
1139
1123
  end
1140
1124
 
1141
1125
  def transmit_single_data_type(harvest_method, supportability_name)
1142
1126
  now = Time.now
1143
1127
 
1144
- msg = "Sending #{harvest_method.to_s.gsub("harvest_and_send_", "")} to New Relic Service"
1128
+ msg = "Sending #{supportability_name} data to New Relic Service"
1145
1129
  ::NewRelic::Agent.logger.debug msg
1146
1130
 
1147
1131
  @service.session do # use http keep-alive
@@ -1163,6 +1147,7 @@ module NewRelic
1163
1147
  harvest_and_send_transaction_traces
1164
1148
  harvest_and_send_slowest_sql
1165
1149
  harvest_and_send_timeslice_data
1150
+ harvest_and_send_span_event_data
1166
1151
 
1167
1152
  check_for_and_handle_agent_commands
1168
1153
  harvest_and_send_for_agent_commands
@@ -1187,7 +1172,10 @@ module NewRelic
1187
1172
 
1188
1173
  @events.notify(:before_shutdown)
1189
1174
  transmit_data
1190
- transmit_event_data
1175
+ transmit_analytic_event_data
1176
+ transmit_custom_event_data
1177
+ transmit_error_event_data
1178
+ transmit_span_event_data
1191
1179
 
1192
1180
  if @connected_pid == $$ && !@service.kind_of?(NewRelic::Agent::NewRelicService)
1193
1181
  ::NewRelic::Agent.logger.debug "Sending New Relic service agent run shutdown message"