newrelic_rpm 4.8.0.341 → 6.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (343) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +31 -0
  3. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
  5. data/.github/actions/annotate/README.md +79 -0
  6. data/.github/actions/annotate/action.yml +6 -0
  7. data/.github/actions/annotate/dist/index.js +433 -0
  8. data/.github/actions/annotate/index.js +25 -0
  9. data/.github/actions/annotate/package-lock.json +172 -0
  10. data/.github/actions/annotate/package.json +30 -0
  11. data/.github/actions/annotate/pre-commit +5 -0
  12. data/.github/actions/build-ruby/README.md +79 -0
  13. data/.github/actions/build-ruby/action.yml +15 -0
  14. data/.github/actions/build-ruby/dist/index.js +52683 -0
  15. data/.github/actions/build-ruby/index.js +514 -0
  16. data/.github/actions/build-ruby/package-lock.json +581 -0
  17. data/.github/actions/build-ruby/package.json +32 -0
  18. data/.github/actions/build-ruby/pre-commit +5 -0
  19. data/.github/pull_request_template.md +16 -0
  20. data/.github/workflows/ci.yml +212 -0
  21. data/.github/workflows/pr_review_checklist.yml +22 -0
  22. data/.github/workflows/release.yml +78 -0
  23. data/.github/workflows/scripts/rubygems-authenticate.py +13 -0
  24. data/.github/workflows/scripts/rubygems-publish.rb +32 -0
  25. data/.github/workflows/snyk.yml +27 -0
  26. data/.github/workflows/stale.yml +21 -0
  27. data/.gitignore +9 -0
  28. data/.yardopts +4 -1
  29. data/CHANGELOG.md +868 -3
  30. data/CONTRIBUTING.md +106 -19
  31. data/Gemfile +6 -2
  32. data/Guardfile +18 -1
  33. data/LICENSE +208 -38
  34. data/README.md +81 -88
  35. data/ROADMAP.md +24 -0
  36. data/Rakefile +2 -0
  37. data/THIRD_PARTY_NOTICES.md +213 -0
  38. data/bin/nrdebug +1 -1
  39. data/config.dot +3 -12
  40. data/init.rb +1 -1
  41. data/install.rb +1 -1
  42. data/lib/new_relic/agent.rb +145 -31
  43. data/lib/new_relic/agent/adaptive_sampler.rb +104 -0
  44. data/lib/new_relic/agent/agent.rb +192 -190
  45. data/lib/new_relic/agent/agent_logger.rb +5 -1
  46. data/lib/new_relic/agent/attribute_filter.rb +85 -25
  47. data/lib/new_relic/agent/attribute_processing.rb +1 -1
  48. data/lib/new_relic/agent/attributes.rb +152 -0
  49. data/lib/new_relic/agent/audit_logger.rb +1 -1
  50. data/lib/new_relic/agent/autostart.rb +20 -15
  51. data/lib/new_relic/agent/chained_call.rb +1 -1
  52. data/lib/new_relic/agent/commands/agent_command.rb +1 -1
  53. data/lib/new_relic/agent/commands/agent_command_router.rb +3 -22
  54. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
  55. data/lib/new_relic/agent/configuration.rb +1 -1
  56. data/lib/new_relic/agent/configuration/default_source.rb +375 -67
  57. data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -1
  58. data/lib/new_relic/agent/configuration/environment_source.rb +5 -3
  59. data/lib/new_relic/agent/configuration/event_harvest_config.rb +45 -0
  60. data/lib/new_relic/agent/configuration/high_security_source.rb +2 -3
  61. data/lib/new_relic/agent/configuration/manager.rb +54 -43
  62. data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
  63. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
  64. data/lib/new_relic/agent/configuration/security_policy_source.rb +238 -0
  65. data/lib/new_relic/agent/configuration/server_source.rb +46 -5
  66. data/lib/new_relic/agent/configuration/yaml_source.rb +12 -7
  67. data/lib/new_relic/agent/connect/request_builder.rb +61 -0
  68. data/lib/new_relic/agent/connect/response_handler.rb +61 -0
  69. data/lib/new_relic/agent/custom_event_aggregator.rb +17 -6
  70. data/lib/new_relic/agent/database.rb +21 -3
  71. data/lib/new_relic/agent/database/explain_plan_helpers.rb +12 -1
  72. data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
  73. data/lib/new_relic/agent/database/obfuscator.rb +1 -1
  74. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
  75. data/lib/new_relic/agent/datastores.rb +12 -11
  76. data/lib/new_relic/agent/datastores/metric_helper.rb +2 -3
  77. data/lib/new_relic/agent/datastores/mongo.rb +2 -2
  78. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +3 -3
  79. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
  80. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +9 -9
  81. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +1 -1
  82. data/lib/new_relic/agent/datastores/redis.rb +1 -1
  83. data/lib/new_relic/agent/deprecator.rb +1 -1
  84. data/lib/new_relic/agent/distributed_tracing.rb +216 -0
  85. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +44 -0
  86. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +248 -0
  87. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +84 -0
  88. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  89. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +165 -0
  90. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
  91. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
  92. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
  93. data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
  94. data/lib/new_relic/agent/error_collector.rb +51 -20
  95. data/lib/new_relic/agent/error_event_aggregator.rb +14 -7
  96. data/lib/new_relic/agent/error_trace_aggregator.rb +2 -1
  97. data/lib/new_relic/agent/event_aggregator.rb +34 -15
  98. data/lib/new_relic/agent/event_buffer.rb +1 -1
  99. data/lib/new_relic/agent/event_listener.rb +1 -1
  100. data/lib/new_relic/agent/event_loop.rb +1 -1
  101. data/lib/new_relic/agent/external.rb +31 -29
  102. data/lib/new_relic/agent/guid_generator.rb +28 -0
  103. data/lib/new_relic/agent/harvester.rb +1 -1
  104. data/lib/new_relic/agent/heap.rb +140 -0
  105. data/lib/new_relic/agent/hostname.rb +16 -2
  106. data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
  107. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +25 -20
  108. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +29 -14
  109. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +18 -22
  110. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +11 -12
  111. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +17 -5
  112. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +5 -7
  113. data/lib/new_relic/agent/http_clients/uri_util.rb +12 -11
  114. data/lib/new_relic/agent/instrumentation.rb +1 -1
  115. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +26 -43
  116. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +56 -74
  117. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +82 -56
  118. data/lib/new_relic/agent/instrumentation/active_job.rb +19 -17
  119. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  120. data/lib/new_relic/agent/instrumentation/active_record.rb +85 -38
  121. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +82 -24
  122. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +168 -0
  123. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +102 -31
  124. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +47 -57
  125. data/lib/new_relic/agent/instrumentation/active_storage.rb +23 -0
  126. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +63 -0
  127. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +24 -8
  128. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  129. data/lib/new_relic/agent/instrumentation/bunny.rb +115 -44
  130. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +18 -12
  131. data/lib/new_relic/agent/instrumentation/curb.rb +121 -35
  132. data/lib/new_relic/agent/instrumentation/data_mapper.rb +6 -4
  133. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +61 -25
  134. data/lib/new_relic/agent/instrumentation/excon.rb +2 -2
  135. data/lib/new_relic/agent/instrumentation/excon/connection.rb +8 -5
  136. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +4 -3
  137. data/lib/new_relic/agent/instrumentation/grape.rb +46 -35
  138. data/lib/new_relic/agent/instrumentation/http.rb +8 -5
  139. data/lib/new_relic/agent/instrumentation/httpclient.rb +7 -5
  140. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
  141. data/lib/new_relic/agent/instrumentation/memcache.rb +5 -3
  142. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +10 -6
  143. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  144. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  145. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +13 -5
  146. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +20 -11
  147. data/lib/new_relic/agent/instrumentation/mongo.rb +11 -5
  148. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +39 -7
  149. data/lib/new_relic/agent/instrumentation/net.rb +60 -23
  150. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +100 -0
  151. data/lib/new_relic/agent/instrumentation/padrino.rb +40 -16
  152. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
  153. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
  154. data/lib/new_relic/agent/instrumentation/rack.rb +36 -13
  155. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +1 -1
  156. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  157. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
  158. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
  159. data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_cable.rb +8 -5
  160. data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_controller.rb +4 -4
  161. data/lib/new_relic/agent/instrumentation/{rails4 → rails_notifications}/action_view.rb +4 -4
  162. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +1 -1
  163. data/lib/new_relic/agent/instrumentation/rake.rb +56 -22
  164. data/lib/new_relic/agent/instrumentation/redis.rb +141 -56
  165. data/lib/new_relic/agent/instrumentation/resque.rb +21 -37
  166. data/lib/new_relic/agent/instrumentation/sequel.rb +2 -3
  167. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
  168. data/lib/new_relic/agent/instrumentation/sidekiq.rb +48 -24
  169. data/lib/new_relic/agent/instrumentation/sinatra.rb +62 -23
  170. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
  171. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
  172. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  173. data/lib/new_relic/agent/instrumentation/typhoeus.rb +27 -10
  174. data/lib/new_relic/agent/internal_agent_error.rb +1 -1
  175. data/lib/new_relic/agent/javascript_instrumentor.rb +19 -16
  176. data/lib/new_relic/agent/log_once.rb +1 -1
  177. data/lib/new_relic/agent/logging.rb +139 -0
  178. data/lib/new_relic/agent/memory_logger.rb +1 -1
  179. data/lib/new_relic/agent/messaging.rb +15 -59
  180. data/lib/new_relic/agent/method_tracer.rb +42 -25
  181. data/lib/new_relic/agent/method_tracer_helpers.rb +5 -5
  182. data/lib/new_relic/agent/monitors.rb +27 -0
  183. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
  184. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
  185. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +4 -4
  186. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +4 -7
  187. data/lib/new_relic/agent/new_relic_service.rb +174 -63
  188. data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
  189. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -2
  190. data/lib/new_relic/agent/new_relic_service/marshaller.rb +6 -27
  191. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +61 -0
  192. data/lib/new_relic/agent/noticible_error.rb +22 -0
  193. data/lib/new_relic/agent/null_logger.rb +1 -1
  194. data/lib/new_relic/agent/obfuscator.rb +1 -1
  195. data/lib/new_relic/agent/parameter_filtering.rb +19 -6
  196. data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
  197. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  198. data/lib/new_relic/agent/pipe_service.rb +5 -1
  199. data/lib/new_relic/agent/prepend_supportability.rb +1 -1
  200. data/lib/new_relic/agent/priority_sampled_buffer.rb +95 -0
  201. data/lib/new_relic/agent/range_extensions.rb +1 -1
  202. data/lib/new_relic/agent/rules_engine.rb +1 -1
  203. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +1 -1
  204. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
  205. data/lib/new_relic/agent/sampler.rb +1 -1
  206. data/lib/new_relic/agent/sampler_collection.rb +1 -1
  207. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  208. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -1
  209. data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
  210. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  211. data/lib/new_relic/agent/samplers/vm_sampler.rb +1 -1
  212. data/lib/new_relic/agent/span_event_aggregator.rb +49 -0
  213. data/lib/new_relic/agent/span_event_primitive.rb +206 -0
  214. data/lib/new_relic/agent/sql_sampler.rb +23 -7
  215. data/lib/new_relic/agent/stats.rb +1 -1
  216. data/lib/new_relic/agent/stats_engine.rb +4 -4
  217. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  218. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  219. data/lib/new_relic/agent/supported_versions.rb +3 -3
  220. data/lib/new_relic/agent/synthetics_event_aggregator.rb +6 -13
  221. data/lib/new_relic/agent/system_info.rb +18 -8
  222. data/lib/new_relic/agent/threading/agent_thread.rb +6 -4
  223. data/lib/new_relic/agent/threading/backtrace_node.rb +1 -1
  224. data/lib/new_relic/agent/threading/backtrace_service.rb +4 -4
  225. data/lib/new_relic/agent/threading/thread_profile.rb +10 -24
  226. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +19 -0
  227. data/lib/new_relic/agent/tracer.rb +509 -0
  228. data/lib/new_relic/agent/transaction.rb +191 -278
  229. data/lib/new_relic/agent/transaction/abstract_segment.rb +38 -5
  230. data/lib/new_relic/agent/transaction/datastore_segment.rb +30 -5
  231. data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
  232. data/lib/new_relic/agent/transaction/distributed_tracing.rb +123 -71
  233. data/lib/new_relic/agent/transaction/external_request_segment.rb +41 -89
  234. data/lib/new_relic/agent/transaction/message_broker_segment.rb +7 -8
  235. data/lib/new_relic/agent/transaction/request_attributes.rb +1 -1
  236. data/lib/new_relic/agent/transaction/segment.rb +42 -2
  237. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
  238. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  239. data/lib/new_relic/agent/transaction/trace.rb +7 -23
  240. data/lib/new_relic/agent/transaction/trace_builder.rb +1 -2
  241. data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
  242. data/lib/new_relic/agent/transaction/trace_node.rb +12 -8
  243. data/lib/new_relic/agent/transaction/tracing.rb +2 -100
  244. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
  245. data/lib/new_relic/agent/transaction_error_primitive.rb +13 -22
  246. data/lib/new_relic/agent/transaction_event_aggregator.rb +7 -16
  247. data/lib/new_relic/agent/transaction_event_primitive.rb +31 -42
  248. data/lib/new_relic/agent/transaction_event_recorder.rb +8 -16
  249. data/lib/new_relic/agent/transaction_metrics.rb +1 -1
  250. data/lib/new_relic/agent/transaction_sampler.rb +3 -14
  251. data/lib/new_relic/agent/transaction_time_aggregator.rb +155 -0
  252. data/lib/new_relic/agent/utilization/aws.rb +1 -1
  253. data/lib/new_relic/agent/utilization/azure.rb +1 -1
  254. data/lib/new_relic/agent/utilization/gcp.rb +1 -1
  255. data/lib/new_relic/agent/utilization/pcf.rb +1 -1
  256. data/lib/new_relic/agent/utilization/vendor.rb +1 -1
  257. data/lib/new_relic/agent/utilization_data.rb +37 -2
  258. data/lib/new_relic/agent/vm.rb +1 -1
  259. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
  260. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  261. data/lib/new_relic/agent/vm/mri_vm.rb +1 -1
  262. data/lib/new_relic/agent/vm/snapshot.rb +1 -1
  263. data/lib/new_relic/agent/worker_loop.rb +1 -1
  264. data/lib/new_relic/cli/command.rb +1 -1
  265. data/lib/new_relic/cli/commands/deployments.rb +2 -2
  266. data/lib/new_relic/cli/commands/install.rb +4 -3
  267. data/lib/new_relic/coerce.rb +32 -7
  268. data/lib/new_relic/collection_helper.rb +1 -1
  269. data/lib/new_relic/constants.rb +38 -0
  270. data/lib/new_relic/control.rb +1 -1
  271. data/lib/new_relic/control/class_methods.rb +8 -2
  272. data/lib/new_relic/control/frameworks.rb +1 -1
  273. data/lib/new_relic/control/frameworks/external.rb +1 -1
  274. data/lib/new_relic/control/frameworks/merb.rb +1 -1
  275. data/lib/new_relic/control/frameworks/rails.rb +1 -1
  276. data/lib/new_relic/control/frameworks/rails3.rb +1 -1
  277. data/lib/new_relic/control/frameworks/rails4.rb +1 -1
  278. data/lib/new_relic/control/frameworks/{rails5.rb → rails_notifications.rb} +2 -2
  279. data/lib/new_relic/control/frameworks/ruby.rb +1 -1
  280. data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
  281. data/lib/new_relic/control/instance_methods.rb +30 -4
  282. data/lib/new_relic/control/instrumentation.rb +1 -1
  283. data/lib/new_relic/control/server_methods.rb +1 -1
  284. data/lib/new_relic/delayed_job_injection.rb +1 -1
  285. data/lib/new_relic/dependency_detection.rb +5 -5
  286. data/lib/new_relic/environment_report.rb +6 -2
  287. data/lib/new_relic/helper.rb +1 -1
  288. data/lib/new_relic/language_support.rb +1 -1
  289. data/lib/new_relic/latest_changes.rb +4 -4
  290. data/lib/new_relic/local_environment.rb +1 -1
  291. data/lib/new_relic/metric_data.rb +1 -1
  292. data/lib/new_relic/metric_spec.rb +1 -1
  293. data/lib/new_relic/noticed_error.rb +39 -18
  294. data/lib/new_relic/rack.rb +1 -1
  295. data/lib/new_relic/rack/agent_hooks.rb +1 -1
  296. data/lib/new_relic/rack/agent_middleware.rb +2 -2
  297. data/lib/new_relic/rack/browser_monitoring.rb +16 -9
  298. data/lib/new_relic/recipes.rb +1 -1
  299. data/lib/new_relic/recipes/capistrano3.rb +6 -3
  300. data/lib/new_relic/recipes/capistrano_legacy.rb +1 -1
  301. data/lib/new_relic/supportability_helper.rb +15 -1
  302. data/lib/new_relic/version.rb +4 -4
  303. data/lib/newrelic_rpm.rb +1 -1
  304. data/lib/sequel/extensions/newrelic_instrumentation.rb +3 -3
  305. data/lib/sequel/plugins/newrelic_instrumentation.rb +2 -2
  306. data/lib/tasks/all.rb +1 -1
  307. data/lib/tasks/config.rake +1 -2
  308. data/lib/tasks/multiverse.rb +35 -1
  309. data/lib/tasks/newrelic.rb +1 -1
  310. data/lib/tasks/tests.rake +6 -1
  311. data/newrelic_rpm.gemspec +23 -17
  312. data/recipes/newrelic.rb +1 -1
  313. data/test/agent_helper.rb +357 -78
  314. metadata +154 -60
  315. data/.travis.yml +0 -173
  316. data/lib/new_relic/agent/busy_calculator.rb +0 -117
  317. data/lib/new_relic/agent/commands/xray_session.rb +0 -55
  318. data/lib/new_relic/agent/commands/xray_session_collection.rb +0 -161
  319. data/lib/new_relic/agent/cross_app_monitor.rb +0 -140
  320. data/lib/new_relic/agent/cross_app_tracing.rb +0 -143
  321. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -29
  322. data/lib/new_relic/agent/distributed_trace_payload.rb +0 -223
  323. data/lib/new_relic/agent/distributed_trace_priority_sampled_buffer.rb +0 -72
  324. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
  325. data/lib/new_relic/agent/instrumentation/active_record_4.rb +0 -42
  326. data/lib/new_relic/agent/instrumentation/active_record_5.rb +0 -36
  327. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +0 -104
  328. data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +0 -32
  329. data/lib/new_relic/agent/instrumentation/rails5/action_view.rb +0 -27
  330. data/lib/new_relic/agent/sampled_buffer.rb +0 -68
  331. data/lib/new_relic/agent/sized_buffer.rb +0 -23
  332. data/lib/new_relic/agent/synthetics_event_buffer.rb +0 -40
  333. data/lib/new_relic/agent/throughput_monitor.rb +0 -59
  334. data/lib/new_relic/agent/transaction/attributes.rb +0 -153
  335. data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +0 -64
  336. data/lib/new_relic/agent/transaction_state.rb +0 -145
  337. data/lib/new_relic/agent/transaction_timings.rb +0 -57
  338. data/lib/new_relic/metrics.rb +0 -13
  339. data/lib/tasks/versions.html.erb +0 -28
  340. data/lib/tasks/versions.postface.html +0 -8
  341. data/lib/tasks/versions.preface.html +0 -9
  342. data/lib/tasks/versions.rake +0 -65
  343. data/lib/tasks/versions.txt.erb +0 -14
@@ -1,16 +1,18 @@
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
+ # frozen_string_literal: true
4
5
 
5
- require 'new_relic/agent/transaction_timings'
6
6
  require 'new_relic/agent/instrumentation/queue_time'
7
7
  require 'new_relic/agent/transaction_metrics'
8
8
  require 'new_relic/agent/method_tracer_helpers'
9
- require 'new_relic/agent/transaction/attributes'
9
+ require 'new_relic/agent/attributes'
10
10
  require 'new_relic/agent/transaction/request_attributes'
11
11
  require 'new_relic/agent/transaction/tracing'
12
- require 'new_relic/agent/transaction/distributed_tracing'
13
- require 'new_relic/agent/cross_app_tracing'
12
+ require 'new_relic/agent/transaction/distributed_tracer'
13
+ require 'new_relic/agent/transaction_time_aggregator'
14
+ require 'new_relic/agent/deprecator'
15
+ require 'new_relic/agent/guid_generator'
14
16
 
15
17
  module NewRelic
16
18
  module Agent
@@ -20,25 +22,38 @@ module NewRelic
20
22
  # @api public
21
23
  class Transaction
22
24
  include Tracing
23
- include DistributedTracing
24
25
 
25
26
  # for nested transactions
26
- SUBTRANSACTION_PREFIX = 'Nested/'.freeze
27
- CONTROLLER_PREFIX = 'Controller/'.freeze
28
- MIDDLEWARE_PREFIX = 'Middleware/Rack/'.freeze
29
- TASK_PREFIX = 'OtherTransaction/Background/'.freeze
30
- RAKE_PREFIX = 'OtherTransaction/Rake/'.freeze
31
- MESSAGE_PREFIX = 'OtherTransaction/Message/'.freeze
32
- RACK_PREFIX = 'Controller/Rack/'.freeze
33
- SINATRA_PREFIX = 'Controller/Sinatra/'.freeze
34
- GRAPE_PREFIX = 'Controller/Grape/'.freeze
35
- ACTION_CABLE_PREFIX = 'Controller/ActionCable/'.freeze
36
- OTHER_TRANSACTION_PREFIX = 'OtherTransaction/'.freeze
37
-
38
- WEB_TRANSACTION_CATEGORIES = [:controller, :uri, :rack, :sinatra, :grape, :middleware, :action_cable].freeze
27
+ NESTED_TRANSACTION_PREFIX = "Nested/"
28
+ CONTROLLER_PREFIX = "Controller/"
29
+ MIDDLEWARE_PREFIX = "Middleware/Rack/"
30
+ OTHER_TRANSACTION_PREFIX = "OtherTransaction/"
31
+ TASK_PREFIX = "#{OTHER_TRANSACTION_PREFIX}Background/"
32
+ RAKE_PREFIX = "#{OTHER_TRANSACTION_PREFIX}Rake/"
33
+ MESSAGE_PREFIX = "#{OTHER_TRANSACTION_PREFIX}Message/"
34
+ RACK_PREFIX = "#{CONTROLLER_PREFIX}Rack/"
35
+ SINATRA_PREFIX = "#{CONTROLLER_PREFIX}Sinatra/"
36
+ GRAPE_PREFIX = "#{CONTROLLER_PREFIX}Grape/"
37
+ ACTION_CABLE_PREFIX = "#{CONTROLLER_PREFIX}ActionCable/"
38
+
39
+ WEB_TRANSACTION_CATEGORIES = [:web, :controller, :uri, :rack, :sinatra, :grape, :middleware, :action_cable].freeze
39
40
  TRANSACTION_NAMING_SOURCES = [:child, :api].freeze
40
41
 
41
- MIDDLEWARE_SUMMARY_METRICS = ['Middleware/all'.freeze].freeze
42
+ MIDDLEWARE_SUMMARY_METRICS = ["Middleware/all"].freeze
43
+ WEB_SUMMARY_METRIC = "HttpDispatcher"
44
+ OTHER_SUMMARY_METRIC = "#{OTHER_TRANSACTION_PREFIX}all"
45
+ QUEUE_TIME_METRIC = "WebFrontend/QueueTime"
46
+
47
+ APDEX_S = "S"
48
+ APDEX_T = "T"
49
+ APDEX_F = "F"
50
+ APDEX_ALL_METRIC = "ApdexAll"
51
+ APDEX_METRIC = "Apdex"
52
+ APDEX_OTHER_METRIC = "ApdexOther"
53
+ APDEX_TXN_METRIC_PREFIX = "Apdex/"
54
+ APDEX_OTHER_TXN_METRIC_PREFIX = "ApdexOther/Transaction/"
55
+
56
+ JRUBY_CPU_TIME_ERROR = "Error calculating JRuby CPU Time"
42
57
 
43
58
  # reference to the transaction state managing this transaction
44
59
  attr_accessor :state
@@ -58,19 +73,21 @@ module NewRelic
58
73
  :http_response_code,
59
74
  :response_content_length,
60
75
  :response_content_type,
61
- :sampled
76
+ :parent_span_id
62
77
 
63
78
  attr_reader :guid,
64
79
  :metrics,
65
80
  :gc_start_snapshot,
66
81
  :category,
67
- :frame_stack,
68
- :cat_path_hashes,
69
82
  :attributes,
70
83
  :payload,
71
84
  :nesting_max_depth,
72
85
  :segments,
73
- :end_time
86
+ :end_time,
87
+ :duration
88
+
89
+ attr_writer :sampled,
90
+ :priority
74
91
 
75
92
  # Populated with the trace sample once this transaction is completed.
76
93
  attr_reader :transaction_trace
@@ -80,28 +97,37 @@ module NewRelic
80
97
 
81
98
  # Return the currently active transaction, or nil.
82
99
  def self.tl_current
83
- TransactionState.tl_get.current_transaction
100
+ Tracer.current_transaction
84
101
  end
85
102
 
86
- def self.set_default_transaction_name(name, category = nil, node_name = nil) #THREAD_LOCAL_ACCESS
103
+ def self.set_default_transaction_name(partial_name, category = nil) #THREAD_LOCAL_ACCESS
87
104
  txn = tl_current
88
- name = txn.make_transaction_name(name, category)
89
- txn.name_last_frame(node_name || name)
105
+ name = name_from_partial(partial_name, category || txn.category)
90
106
  txn.set_default_transaction_name(name, category)
91
107
  end
92
108
 
93
- def self.set_overriding_transaction_name(name, category = nil) #THREAD_LOCAL_ACCESS
109
+ def self.set_overriding_transaction_name(partial_name, category = nil) #THREAD_LOCAL_ACCESS
94
110
  txn = tl_current
95
111
  return unless txn
96
112
 
97
- name = txn.make_transaction_name(name, category)
98
-
99
- txn.name_last_frame(name)
113
+ name = name_from_partial(partial_name, category || txn.category)
100
114
  txn.set_overriding_transaction_name(name, category)
101
115
  end
102
116
 
117
+ def self.name_from_partial(partial_name, category)
118
+ namer = Instrumentation::ControllerInstrumentation::TransactionNamer
119
+ "#{namer.prefix_for_category(self, category)}#{partial_name}"
120
+ end
121
+
103
122
  def self.wrap(state, name, category, options = {})
104
- Transaction.start(state, category, options.merge(:transaction_name => name))
123
+ Deprecator.deprecate 'Transaction.wrap',
124
+ 'Tracer#in_transaction'
125
+
126
+ finishable = Tracer.start_transaction_or_segment(
127
+ name: name,
128
+ category: category,
129
+ options: options
130
+ )
105
131
 
106
132
  begin
107
133
  # We shouldn't raise from Transaction.start, but only wrap the yield
@@ -111,81 +137,36 @@ module NewRelic
111
137
  Transaction.notice_error(e)
112
138
  raise e
113
139
  ensure
114
- Transaction.stop(state)
140
+ finishable.finish if finishable
115
141
  end
116
142
  end
117
143
 
118
- def self.start(state, category, options)
119
- category ||= :controller
120
- txn = state.current_transaction
121
-
122
- if txn
123
- txn.create_nested_frame(state, category, options)
124
- else
125
- txn = start_new_transaction(state, category, options)
126
- end
127
-
128
- txn
129
- rescue => e
130
- NewRelic::Agent.logger.error("Exception during Transaction.start", e)
131
- nil
132
- end
133
-
134
144
  def self.start_new_transaction(state, category, options)
135
145
  txn = Transaction.new(category, options)
136
146
  state.reset(txn)
137
147
  txn.state = state
138
- txn.start(state)
148
+ txn.start
139
149
  txn
140
150
  end
141
151
 
142
- FAILED_TO_STOP_MESSAGE = "Failed during Transaction.stop because there is no current transaction"
143
-
144
- def self.stop(state, end_time=Time.now)
145
- txn = state.current_transaction
146
-
147
- if txn.nil?
148
- NewRelic::Agent.logger.error(FAILED_TO_STOP_MESSAGE)
149
- return
150
- end
151
-
152
- nested_frame = txn.frame_stack.pop
153
-
154
- if txn.frame_stack.empty?
155
- txn.stop(state, end_time, nested_frame)
156
- state.reset
157
- else
158
- nested_frame.finish
159
- end
160
-
161
- :transaction_stopped
162
- rescue => e
163
- state.reset
164
- NewRelic::Agent.logger.error("Exception during Transaction.stop", e)
165
- nil
166
- end
167
-
168
152
  def self.nested_transaction_name(name)
169
153
  if name.start_with?(CONTROLLER_PREFIX) || name.start_with?(OTHER_TRANSACTION_PREFIX)
170
- "#{SUBTRANSACTION_PREFIX}#{name}"
154
+ "#{NESTED_TRANSACTION_PREFIX}#{name}"
171
155
  else
172
156
  name
173
157
  end
174
158
  end
175
159
 
176
- # Indicate that you don't want to keep the currently saved transaction
177
- # information
178
- def self.abort_transaction! #THREAD_LOCAL_ACCESS
179
- state = NewRelic::Agent::TransactionState.tl_get
180
- txn = state.current_transaction
181
- txn.abort_transaction!(state) if txn
160
+ # discards the currently saved transaction information
161
+ def self.abort_transaction!
162
+ if txn = Tracer.current_transaction
163
+ txn.abort_transaction!
164
+ end
182
165
  end
183
166
 
184
167
  # See NewRelic::Agent.notice_error for options and commentary
185
- def self.notice_error(e, options={}) #THREAD_LOCAL_ACCESS
186
- state = NewRelic::Agent::TransactionState.tl_get
187
- txn = state.current_transaction
188
- if txn
168
+ def self.notice_error(e, options={})
169
+ if txn = Tracer.current_transaction
189
170
  txn.notice_error(e, options)
190
171
  elsif NewRelic::Agent.instance
191
172
  NewRelic::Agent.instance.error_collector.notice_error(e, options)
@@ -227,6 +208,7 @@ module NewRelic
227
208
 
228
209
  def add_agent_attribute(key, value, default_destinations)
229
210
  @attributes.add_agent_attribute(key, value, default_destinations)
211
+ current_segment.add_agent_attribute(key, value) if current_segment
230
212
  end
231
213
 
232
214
  def self.merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
@@ -239,6 +221,7 @@ module NewRelic
239
221
 
240
222
  def merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
241
223
  @attributes.merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
224
+ current_segment.merge_untrusted_agent_attributes(attributes, prefix, default_destinations) if current_segment
242
225
  end
243
226
 
244
227
  @@java_classes_loaded = false
@@ -257,7 +240,6 @@ module NewRelic
257
240
  @nesting_max_depth = 0
258
241
  @current_segment = nil
259
242
  @segments = []
260
- @frame_stack = []
261
243
 
262
244
  self.default_name = options[:transaction_name]
263
245
  @overridden_name = nil
@@ -266,6 +248,7 @@ module NewRelic
266
248
  @category = category
267
249
  @start_time = Time.now
268
250
  @end_time = nil
251
+ @duration = nil
269
252
  @apdex_start = options[:apdex_start_time] || @start_time
270
253
  @jruby_cpu_start = jruby_cpu_time
271
254
  @process_cpu_start = process_cpu
@@ -274,19 +257,17 @@ module NewRelic
274
257
 
275
258
  @exceptions = {}
276
259
  @metrics = TransactionMetrics.new
277
- @guid = generate_guid
278
- @cat_path_hashes = nil
260
+ @guid = NewRelic::Agent::GuidGenerator.generate_guid
279
261
 
280
262
  @ignore_this_transaction = false
281
263
  @ignore_apdex = options.fetch(:ignore_apdex, false)
282
264
  @ignore_enduser = options.fetch(:ignore_enduser, false)
283
265
  @ignore_trace = false
284
266
 
285
- if Agent.config[:'distributed_tracing.enabled']
286
- @sampled = NewRelic::Agent.instance.throughput_monitor.sampled?
287
- else
288
- @sampled = nil
289
- end
267
+ @sampled = nil
268
+ @priority = nil
269
+
270
+ @starting_thread_id = Thread.current.object_id
290
271
 
291
272
  @attributes = Attributes.new(NewRelic::Agent.instance.attribute_filter)
292
273
 
@@ -299,10 +280,30 @@ module NewRelic
299
280
  end
300
281
  end
301
282
 
283
+ def distributed_tracer
284
+ @distributed_tracer ||= DistributedTracer.new(self)
285
+ end
286
+
302
287
  def sampled?
288
+ return unless Agent.config[:'distributed_tracing.enabled']
289
+ if @sampled.nil?
290
+ @sampled = NewRelic::Agent.instance.adaptive_sampler.sampled?
291
+ end
303
292
  @sampled
304
293
  end
305
294
 
295
+ def trace_id
296
+ @trace_id ||= NewRelic::Agent::GuidGenerator.generate_guid 32
297
+ end
298
+
299
+ def trace_id=(value)
300
+ @trace_id = value
301
+ end
302
+
303
+ def priority
304
+ @priority ||= (sampled? ? 1.0 + rand : rand).round(NewRelic::PRIORITY_PRECISION)
305
+ end
306
+
306
307
  def referer
307
308
  @request_attributes && @request_attributes.referer
308
309
  end
@@ -345,11 +346,6 @@ module NewRelic
345
346
  merge_untrusted_agent_attributes(params, :'request.parameters', AttributeFilter::DST_NONE)
346
347
  end
347
348
 
348
- def make_transaction_name(name, category=nil)
349
- namer = Instrumentation::ControllerInstrumentation::TransactionNamer
350
- "#{namer.prefix_for_category(self, category)}#{name}"
351
- end
352
-
353
349
  def set_default_transaction_name(name, category)
354
350
  return log_frozen_name(name) if name_frozen?
355
351
  if influences_transaction_name?(category)
@@ -366,39 +362,26 @@ module NewRelic
366
362
  end
367
363
  end
368
364
 
369
- def name_last_frame(name)
370
- name = self.class.nested_transaction_name(name) if nesting_max_depth > 1
371
- frame_stack.last.name = name
372
- end
373
-
374
365
  def log_frozen_name(name)
375
366
  NewRelic::Agent.logger.warn("Attempted to rename transaction to '#{name}' after transaction name was already frozen as '#{@frozen_name}'.")
376
367
  nil
377
368
  end
378
369
 
379
370
  def influences_transaction_name?(category)
380
- !category || frame_stack.size == 1 || similar_category?(category)
371
+ !category || nesting_max_depth == 1 || similar_category?(category)
381
372
  end
382
373
 
383
374
  def best_name
384
- @frozen_name || @overridden_name ||
385
- @default_name || NewRelic::Agent::UNKNOWN_METRIC
375
+ @frozen_name ||
376
+ @overridden_name ||
377
+ @default_name ||
378
+ NewRelic::Agent::UNKNOWN_METRIC
386
379
  end
387
380
 
388
381
  # For common interface with Trace
389
382
  alias_method :transaction_name, :best_name
390
-
391
- attr_accessor :xray_session_id
392
-
393
- def duration
394
- (@end_time - @start_time).to_f
395
- end
396
383
  # End common interface
397
384
 
398
- def name_set?
399
- (@overridden_name || @default_name) ? true : false
400
- end
401
-
402
385
  def promoted_transaction_name(name)
403
386
  if name.start_with?(MIDDLEWARE_PREFIX)
404
387
  "#{CONTROLLER_PREFIX}#{name}"
@@ -430,23 +413,27 @@ module NewRelic
430
413
  @frozen_name ? true : false
431
414
  end
432
415
 
433
- def start(state)
416
+ def start
434
417
  return if !state.is_execution_traced?
435
418
 
436
419
  sql_sampler.on_start_transaction(state, start_time, request_path)
437
420
  NewRelic::Agent.instance.events.notify(:start_transaction)
438
- NewRelic::Agent::BusyCalculator.dispatcher_start(start_time)
421
+ NewRelic::Agent::TransactionTimeAggregator.transaction_start(start_time)
439
422
 
440
423
  ignore! if user_defined_rules_ignore?
441
424
 
442
- create_initial_segment @default_name
425
+ create_initial_segment
426
+ Segment.merge_untrusted_agent_attributes \
427
+ @filtered_params,
428
+ :'request.parameters',
429
+ AttributeFilter::DST_SPAN_EVENTS
443
430
  end
444
431
 
445
432
  def initial_segment
446
433
  segments.first
447
434
  end
448
435
 
449
- def create_initial_segment name
436
+ def create_initial_segment
450
437
  segment = create_segment @default_name
451
438
  segment.record_scoped_metric = false
452
439
  end
@@ -460,16 +447,15 @@ module NewRelic
460
447
 
461
448
  @nesting_max_depth += 1
462
449
 
463
- segment = self.class.start_segment(
450
+ segment = Tracer.start_segment(
464
451
  name: name,
465
452
  unscoped_metrics: summary_metrics
466
453
  )
467
454
 
468
- frame_stack.push segment
469
455
  segment
470
456
  end
471
457
 
472
- def create_nested_frame(state, category, options)
458
+ def create_nested_segment(category, options)
473
459
  if options[:filtered_params] && !options[:filtered_params].empty?
474
460
  @filtered_params = options[:filtered_params]
475
461
  merge_request_parameters(options[:filtered_params])
@@ -480,8 +466,9 @@ module NewRelic
480
466
 
481
467
  nest_initial_segment if nesting_max_depth == 1
482
468
  nested_name = self.class.nested_transaction_name options[:transaction_name]
483
- create_segment nested_name
469
+ segment = create_segment nested_name
484
470
  set_default_transaction_name(options[:transaction_name], category)
471
+ segment
485
472
  end
486
473
 
487
474
  def nest_initial_segment
@@ -491,13 +478,10 @@ module NewRelic
491
478
 
492
479
  # Call this to ensure that the current transaction trace is not saved
493
480
  # To fully ignore all metrics and errors, use ignore! instead.
494
- def abort_transaction!(state)
481
+ def abort_transaction!
495
482
  @ignore_trace = true
496
483
  end
497
484
 
498
- WEB_SUMMARY_METRIC = 'HttpDispatcher'.freeze
499
- OTHER_SUMMARY_METRIC = 'OtherTransaction/all'.freeze
500
-
501
485
  def summary_metrics
502
486
  if @frozen_name.start_with?(CONTROLLER_PREFIX)
503
487
  [WEB_SUMMARY_METRIC]
@@ -519,21 +503,29 @@ module NewRelic
519
503
  name.start_with?(MIDDLEWARE_PREFIX)
520
504
  end
521
505
 
522
- def stop(state, end_time, outermost_frame)
523
- return if !state.is_execution_traced?
524
-
525
- @end_time = end_time
506
+ def finish
507
+ return unless state.is_execution_traced?
508
+ @end_time = Time.now
509
+ @duration = @end_time.to_f - @start_time.to_f
526
510
  freeze_name_and_execute_if_not_ignored
527
511
 
528
512
  if nesting_max_depth == 1
529
- outermost_frame.name = @frozen_name
513
+ initial_segment.name = @frozen_name
530
514
  end
531
515
 
532
- outermost_frame.finish
516
+ initial_segment.transaction_name = @frozen_name
517
+ assign_segment_dt_attributes
518
+ assign_agent_attributes
519
+ initial_segment.finish
533
520
 
534
- NewRelic::Agent::BusyCalculator.dispatcher_finish(end_time)
521
+ NewRelic::Agent::TransactionTimeAggregator.transaction_stop(@end_time, @starting_thread_id)
535
522
 
536
- commit!(state, end_time, outermost_frame.name) unless @ignore_this_transaction
523
+ commit!(initial_segment.name) unless @ignore_this_transaction
524
+ rescue => e
525
+ NewRelic::Agent.logger.error("Exception during Transaction#finish", e)
526
+ nil
527
+ ensure
528
+ state.reset
537
529
  end
538
530
 
539
531
  def user_defined_rules_ignore?
@@ -545,22 +537,20 @@ module NewRelic
545
537
  end
546
538
  end
547
539
 
548
- def commit!(state, end_time, outermost_node_name)
549
- generate_payload(state, start_time, end_time)
550
-
551
- assign_agent_attributes
552
- assign_intrinsics(state)
540
+ def commit!(outermost_node_name)
541
+ generate_payload
542
+ assign_intrinsics
553
543
 
554
544
  finalize_segments
555
545
 
556
- @transaction_trace = transaction_sampler.on_finishing_transaction(state, self, end_time)
546
+ @transaction_trace = transaction_sampler.on_finishing_transaction(self)
557
547
  sql_sampler.on_finishing_transaction(state, @frozen_name)
558
548
 
559
- record_summary_metrics(outermost_node_name, end_time)
549
+ record_summary_metrics(outermost_node_name)
560
550
  record_total_time_metrics
561
- record_apdex(state, end_time) unless ignore_apdex?
551
+ record_apdex unless ignore_apdex?
562
552
  record_queue_time
563
- record_client_application_metric state
553
+ distributed_tracer.record_metrics
564
554
 
565
555
  record_exceptions
566
556
  record_transaction_event
@@ -568,6 +558,13 @@ module NewRelic
568
558
  send_transaction_finished_event
569
559
  end
570
560
 
561
+ def assign_segment_dt_attributes
562
+ dt_payload = distributed_tracer.trace_state_payload || distributed_tracer.distributed_trace_payload
563
+ parent_attributes = {}
564
+ DistributedTraceAttributes.copy_parent_attributes self, dt_payload, parent_attributes
565
+ parent_attributes.each { |k, v| initial_segment.add_agent_attribute k, v }
566
+ end
567
+
571
568
  def assign_agent_attributes
572
569
  default_destinations = AttributeFilter::DST_TRANSACTION_TRACER |
573
570
  AttributeFilter::DST_TRANSACTION_EVENTS |
@@ -575,6 +572,9 @@ module NewRelic
575
572
 
576
573
  if http_response_code
577
574
  add_agent_attribute(:httpResponseCode, http_response_code.to_s, default_destinations)
575
+ # Sending status code as an int with http.statusCode key is correct
576
+ # The above attribute is deprecated and should be removed in agent version 7.0.0
577
+ add_agent_attribute(:'http.statusCode', http_response_code, default_destinations)
578
578
  end
579
579
 
580
580
  if response_content_length
@@ -595,8 +595,8 @@ module NewRelic
595
595
  end
596
596
  end
597
597
 
598
- def assign_intrinsics(state)
599
- attributes.add_intrinsic_attribute :'nr.sampled', sampled?
598
+ def assign_intrinsics
599
+ attributes.add_intrinsic_attribute(:priority, priority)
600
600
 
601
601
  if gc_time = calculate_gc_time
602
602
  attributes.add_intrinsic_attribute(:gc_time, gc_time)
@@ -612,12 +612,7 @@ module NewRelic
612
612
  attributes.add_intrinsic_attribute(:synthetics_monitor_id, synthetics_monitor_id)
613
613
  end
614
614
 
615
- if distributed_trace_payload || order > 0
616
- assign_distributed_tracing_intrinsics
617
- elsif state.is_cross_app?
618
- attributes.add_intrinsic_attribute(:trip_id, cat_trip_id)
619
- attributes.add_intrinsic_attribute(:path_hash, cat_path_hash)
620
- end
615
+ distributed_tracer.assign_intrinsics
621
616
  end
622
617
 
623
618
  def calculate_gc_time
@@ -625,12 +620,22 @@ module NewRelic
625
620
  NewRelic::Agent::StatsEngine::GCProfiler.record_delta(gc_start_snapshot, gc_stop_snapshot)
626
621
  end
627
622
 
623
+ # This method returns transport_duration in seconds. Transport duration
624
+ # is stored in milliseconds on the payload, but it's needed in seconds
625
+ # for metrics and intrinsics.
626
+ def calculate_transport_duration distributed_trace_payload
627
+ return unless distributed_trace_payload
628
+
629
+ duration = (start_time.to_f * 1000 - distributed_trace_payload.timestamp) / 1000
630
+ duration < 0 ? 0 : duration
631
+ end
632
+
628
633
  # The summary metrics recorded by this method all end up with a duration
629
634
  # equal to the transaction itself, and an exclusive time of zero.
630
- def record_summary_metrics(outermost_node_name, end_time)
635
+ def record_summary_metrics(outermost_node_name)
631
636
  metrics = summary_metrics
632
637
  metrics << @frozen_name unless @frozen_name == outermost_node_name
633
- @metrics.record_unscoped(metrics, end_time.to_f - start_time.to_f, 0)
638
+ @metrics.record_unscoped(metrics, duration, 0)
634
639
  end
635
640
 
636
641
  # This event is fired when the transaction is fully completed. The metric
@@ -639,8 +644,7 @@ module NewRelic
639
644
  agent.events.notify(:transaction_finished, payload)
640
645
  end
641
646
 
642
- def generate_payload(state, start_time, end_time)
643
- duration = end_time.to_f - start_time.to_f
647
+ def generate_payload
644
648
  @payload = {
645
649
  :name => @frozen_name,
646
650
  :bucket => recording_web_transaction? ? :request : :background,
@@ -648,43 +652,17 @@ module NewRelic
648
652
  :duration => duration,
649
653
  :metrics => @metrics,
650
654
  :attributes => @attributes,
651
- :error => false
655
+ :error => false,
656
+ :priority => priority
652
657
  }
653
658
 
654
- @payload[:'nr.sampled'] = sampled? if Agent.config[:'distributed_tracing.enabled']
655
-
656
- append_cat_info(state, duration, @payload)
657
- append_distributed_tracing_info(@payload)
658
- append_apdex_perf_zone(duration, @payload)
659
- append_synthetics_to(state, @payload)
660
- append_referring_transaction_guid_to(state, @payload)
661
- end
662
-
663
- def include_guid?(state, duration)
664
- state.is_cross_app? || is_synthetics_request?
665
- end
666
-
667
- def cat_trip_id
668
- NewRelic::Agent.instance.cross_app_monitor.client_referring_transaction_trip_id(state) || guid
659
+ distributed_tracer.append_payload(@payload)
660
+ append_apdex_perf_zone(@payload)
661
+ append_synthetics_to(@payload)
669
662
  end
670
663
 
671
- def cat_path_hash
672
- referring_path_hash = cat_referring_path_hash(state) || '0'
673
- seed = referring_path_hash.to_i(16)
674
- result = NewRelic::Agent.instance.cross_app_monitor.path_hash(best_name, seed)
675
- record_cat_path_hash(result)
676
- result
677
- end
678
-
679
- def record_cat_path_hash(hash)
680
- @cat_path_hashes ||= []
681
- if @cat_path_hashes.size < 10 && !@cat_path_hashes.include?(hash)
682
- @cat_path_hashes << hash
683
- end
684
- end
685
-
686
- def cat_referring_path_hash(state)
687
- NewRelic::Agent.instance.cross_app_monitor.client_referring_transaction_path_hash(state)
664
+ def include_guid?
665
+ distributed_tracer.is_cross_app? || is_synthetics_request?
688
666
  end
689
667
 
690
668
  def is_synthetics_request?
@@ -716,11 +694,7 @@ module NewRelic
716
694
  info[4]
717
695
  end
718
696
 
719
- APDEX_S = 'S'.freeze
720
- APDEX_T = 'T'.freeze
721
- APDEX_F = 'F'.freeze
722
-
723
- def append_apdex_perf_zone(duration, payload)
697
+ def append_apdex_perf_zone(payload)
724
698
  if recording_web_transaction?
725
699
  bucket = apdex_bucket(duration, apdex_t)
726
700
  elsif background_apdex_t = transaction_specific_apdex_t
@@ -738,29 +712,7 @@ module NewRelic
738
712
  payload[:apdex_perf_zone] = bucket_str if bucket_str
739
713
  end
740
714
 
741
- def append_cat_info(state, duration, payload)
742
- return unless include_guid?(state, duration)
743
- payload[:guid] = guid
744
-
745
- return unless state.is_cross_app?
746
- trip_id = cat_trip_id
747
- path_hash = cat_path_hash
748
- referring_path_hash = cat_referring_path_hash(state)
749
-
750
- payload[:cat_trip_id] = trip_id if trip_id
751
- payload[:cat_referring_path_hash] = referring_path_hash if referring_path_hash
752
-
753
- if path_hash
754
- payload[:cat_path_hash] = path_hash
755
-
756
- alternate_path_hashes = cat_path_hashes - [path_hash]
757
- unless alternate_path_hashes.empty?
758
- payload[:cat_alternate_path_hashes] = alternate_path_hashes
759
- end
760
- end
761
- end
762
-
763
- def append_synthetics_to(state, payload)
715
+ def append_synthetics_to(payload)
764
716
  return unless is_synthetics_request?
765
717
 
766
718
  payload[:synthetics_resource_id] = synthetics_resource_id
@@ -768,13 +720,6 @@ module NewRelic
768
720
  payload[:synthetics_monitor_id] = synthetics_monitor_id
769
721
  end
770
722
 
771
- def append_referring_transaction_guid_to(state, payload)
772
- referring_guid = NewRelic::Agent.instance.cross_app_monitor.client_referring_transaction_guid(state)
773
- if referring_guid
774
- payload[:referring_transaction_guid] = referring_guid
775
- end
776
- end
777
-
778
723
  def merge_metrics
779
724
  NewRelic::Agent.instance.stats_engine.merge_transaction_metrics!(@metrics, best_name)
780
725
  end
@@ -787,13 +732,21 @@ module NewRelic
787
732
  options[:metric] = best_name
788
733
  options[:attributes] = @attributes
789
734
 
790
- error_recorded = !!agent.error_collector.notice_error(exception, options) || error_recorded
735
+ span_id = options.delete :span_id
736
+ error_recorded = !!agent.error_collector.notice_error(exception, options, span_id) || error_recorded
791
737
  end
792
738
  payload[:error] = error_recorded if payload
793
739
  end
794
740
 
795
741
  # Do not call this. Invoke the class method instead.
796
742
  def notice_error(error, options={}) # :nodoc:
743
+
744
+ # Only the last error is kept
745
+ if @current_segment
746
+ @current_segment.notice_error error, expected: options[:expected]
747
+ options[:span_id] = @current_segment.guid
748
+ end
749
+
797
750
  if @exceptions[error]
798
751
  @exceptions[error].merge! options
799
752
  else
@@ -805,8 +758,6 @@ module NewRelic
805
758
  agent.transaction_event_recorder.record payload
806
759
  end
807
760
 
808
- QUEUE_TIME_METRIC = 'WebFrontend/QueueTime'.freeze
809
-
810
761
  def queue_time
811
762
  @apdex_start ? @start_time - @apdex_start : 0
812
763
  end
@@ -822,23 +773,9 @@ module NewRelic
822
773
  end
823
774
  end
824
775
 
825
- def record_client_application_metric state
826
- if id = state.client_cross_app_id
827
- NewRelic::Agent.record_metric "ClientApplication/#{id}/all", state.timings.app_time_in_seconds
828
- end
829
- end
830
-
831
- APDEX_ALL_METRIC = 'ApdexAll'.freeze
832
-
833
- APDEX_METRIC = 'Apdex'.freeze
834
- APDEX_OTHER_METRIC = 'ApdexOther'.freeze
835
-
836
- APDEX_TXN_METRIC_PREFIX = 'Apdex/'.freeze
837
- APDEX_OTHER_TXN_METRIC_PREFIX = 'ApdexOther/Transaction/'.freeze
838
-
839
776
  def had_error_affecting_apdex?
840
777
  @exceptions.each do |exception, options|
841
- ignored = NewRelic::Agent.instance.error_collector.error_is_ignored?(exception)
778
+ ignored = NewRelic::Agent.instance.error_collector.error_is_ignored?(exception)
842
779
  expected = options[:expected]
843
780
 
844
781
  return true unless ignored || expected
@@ -850,28 +787,26 @@ module NewRelic
850
787
  self.class.apdex_bucket(duration, had_error_affecting_apdex?, current_apdex_t)
851
788
  end
852
789
 
853
- def record_apdex(state, end_time=Time.now)
790
+ def record_apdex
854
791
  return unless state.is_execution_traced?
855
792
 
856
793
  freeze_name_and_execute_if_not_ignored do
857
- total_duration = end_time - apdex_start
858
- action_duration = end_time - start_time
859
-
860
794
  if recording_web_transaction?
861
- record_apdex_metrics(APDEX_METRIC, APDEX_TXN_METRIC_PREFIX,
862
- total_duration, action_duration, apdex_t)
795
+ record_apdex_metrics(APDEX_METRIC, APDEX_TXN_METRIC_PREFIX, apdex_t)
863
796
  else
864
- record_apdex_metrics(APDEX_OTHER_METRIC, APDEX_OTHER_TXN_METRIC_PREFIX,
865
- total_duration, action_duration, transaction_specific_apdex_t)
797
+ record_apdex_metrics(APDEX_OTHER_METRIC,
798
+ APDEX_OTHER_TXN_METRIC_PREFIX,
799
+ transaction_specific_apdex_t)
866
800
  end
867
801
  end
868
802
  end
869
803
 
870
- def record_apdex_metrics(rollup_metric, transaction_prefix, total_duration, action_duration, current_apdex_t)
804
+ def record_apdex_metrics(rollup_metric, transaction_prefix, current_apdex_t)
871
805
  return unless current_apdex_t
872
806
 
807
+ total_duration = end_time - apdex_start
873
808
  apdex_bucket_global = apdex_bucket(total_duration, current_apdex_t)
874
- apdex_bucket_txn = apdex_bucket(action_duration, current_apdex_t)
809
+ apdex_bucket_txn = apdex_bucket(duration, current_apdex_t)
875
810
 
876
811
  @metrics.record_unscoped(rollup_metric, apdex_bucket_global, current_apdex_t)
877
812
  @metrics.record_unscoped(APDEX_ALL_METRIC, apdex_bucket_global, current_apdex_t)
@@ -971,15 +906,6 @@ module NewRelic
971
906
  @ignore_trace
972
907
  end
973
908
 
974
- def add_message_cat_headers headers
975
- state.is_cross_app_caller = true
976
- CrossAppTracing.insert_message_headers headers,
977
- guid,
978
- cat_trip_id,
979
- cat_path_hash,
980
- raw_synthetics_header
981
- end
982
-
983
909
  private
984
910
 
985
911
  def process_cpu
@@ -988,7 +914,6 @@ module NewRelic
988
914
  p.stime + p.utime
989
915
  end
990
916
 
991
- JRUBY_CPU_TIME_ERROR = "Error calculating JRuby CPU Time".freeze
992
917
  def jruby_cpu_time
993
918
  return nil unless @@java_classes_loaded
994
919
  threadMBean = Java::JavaLangManagement::ManagementFactory.getThreadMXBean()
@@ -1014,18 +939,6 @@ module NewRelic
1014
939
  def sql_sampler
1015
940
  agent.sql_sampler
1016
941
  end
1017
-
1018
- HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
1019
- GUID_LENGTH = 16
1020
-
1021
- # generate a random 64 bit uuid
1022
- def generate_guid
1023
- guid = ''
1024
- GUID_LENGTH.times do |a|
1025
- guid << HEX_DIGITS[rand(16)]
1026
- end
1027
- guid
1028
- end
1029
942
  end
1030
943
  end
1031
944
  end