newrelic_rpm 5.7.0.350 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (476) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -1
  3. data/.rubocop.yml +1919 -0
  4. data/.rubocop_todo.yml +100 -0
  5. data/.simplecov +15 -0
  6. data/.snyk +11 -0
  7. data/.yardopts +2 -0
  8. data/Brewfile +12 -0
  9. data/CHANGELOG.md +4056 -2339
  10. data/CONTRIBUTING.md +132 -19
  11. data/DOCKER.md +167 -0
  12. data/Dockerfile +10 -0
  13. data/Gemfile +5 -2
  14. data/Guardfile +22 -4
  15. data/LICENSE +202 -38
  16. data/README.md +87 -87
  17. data/Rakefile +27 -27
  18. data/THIRD_PARTY_NOTICES.md +28 -0
  19. data/Thorfile +5 -0
  20. data/bin/newrelic +3 -2
  21. data/bin/newrelic_cmd +1 -0
  22. data/bin/nrdebug +77 -54
  23. data/config.dot +5 -5
  24. data/docker-compose.yml +107 -0
  25. data/init.rb +5 -7
  26. data/install.rb +3 -3
  27. data/lefthook.yml +9 -0
  28. data/lib/new_relic/agent/adaptive_sampler.rb +14 -10
  29. data/lib/new_relic/agent/agent.rb +125 -969
  30. data/lib/new_relic/agent/agent_helpers/connect.rb +227 -0
  31. data/lib/new_relic/agent/agent_helpers/harvest.rb +153 -0
  32. data/lib/new_relic/agent/agent_helpers/shutdown.rb +72 -0
  33. data/lib/new_relic/agent/agent_helpers/special_startup.rb +74 -0
  34. data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +167 -0
  35. data/lib/new_relic/agent/agent_helpers/startup.rb +202 -0
  36. data/lib/new_relic/agent/agent_helpers/transmit.rb +76 -0
  37. data/lib/new_relic/agent/agent_logger.rb +26 -18
  38. data/lib/new_relic/agent/attribute_filter.rb +69 -52
  39. data/lib/new_relic/agent/attribute_processing.rb +8 -8
  40. data/lib/new_relic/agent/attributes.rb +153 -0
  41. data/lib/new_relic/agent/audit_logger.rb +19 -4
  42. data/lib/new_relic/agent/autostart.rb +34 -28
  43. data/lib/new_relic/agent/chained_call.rb +2 -2
  44. data/lib/new_relic/agent/commands/agent_command.rb +4 -4
  45. data/lib/new_relic/agent/commands/agent_command_router.rb +15 -33
  46. data/lib/new_relic/agent/commands/thread_profiler_session.rb +13 -11
  47. data/lib/new_relic/agent/configuration/default_source.rb +1480 -1053
  48. data/lib/new_relic/agent/configuration/dotted_hash.rb +7 -6
  49. data/lib/new_relic/agent/configuration/environment_source.rb +15 -11
  50. data/lib/new_relic/agent/configuration/event_harvest_config.rb +68 -0
  51. data/lib/new_relic/agent/configuration/high_security_source.rb +9 -9
  52. data/lib/new_relic/agent/configuration/manager.rb +96 -79
  53. data/lib/new_relic/agent/configuration/manual_source.rb +2 -2
  54. data/lib/new_relic/agent/configuration/mask_defaults.rb +4 -4
  55. data/lib/new_relic/agent/configuration/security_policy_source.rb +83 -86
  56. data/lib/new_relic/agent/configuration/server_source.rb +49 -12
  57. data/lib/new_relic/agent/configuration/yaml_source.rb +42 -13
  58. data/lib/new_relic/agent/configuration.rb +2 -2
  59. data/lib/new_relic/agent/connect/request_builder.rb +61 -0
  60. data/lib/new_relic/agent/connect/response_handler.rb +58 -0
  61. data/lib/new_relic/agent/custom_event_aggregator.rb +15 -15
  62. data/lib/new_relic/agent/database/explain_plan_helpers.rb +5 -6
  63. data/lib/new_relic/agent/database/obfuscation_helpers.rb +16 -15
  64. data/lib/new_relic/agent/database/obfuscator.rb +3 -3
  65. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +4 -4
  66. data/lib/new_relic/agent/database.rb +44 -53
  67. data/lib/new_relic/agent/database_adapter.rb +35 -0
  68. data/lib/new_relic/agent/datastores/metric_helper.rb +18 -20
  69. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +9 -8
  70. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +7 -11
  71. data/lib/new_relic/agent/datastores/mongo.rb +7 -12
  72. data/lib/new_relic/agent/datastores/nosql_obfuscator.rb +41 -0
  73. data/lib/new_relic/agent/datastores/redis.rb +6 -12
  74. data/lib/new_relic/agent/datastores.rb +19 -23
  75. data/lib/new_relic/agent/deprecator.rb +2 -2
  76. data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +13 -12
  77. data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +87 -66
  78. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +84 -0
  79. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  80. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +163 -0
  81. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +38 -0
  82. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +245 -0
  83. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +127 -0
  84. data/lib/new_relic/agent/distributed_tracing.rb +113 -32
  85. data/lib/new_relic/agent/encoding_normalizer.rb +5 -3
  86. data/lib/new_relic/agent/error_collector.rb +99 -63
  87. data/lib/new_relic/agent/error_event_aggregator.rb +10 -8
  88. data/lib/new_relic/agent/error_filter.rb +174 -0
  89. data/lib/new_relic/agent/error_trace_aggregator.rb +6 -4
  90. data/lib/new_relic/agent/event_aggregator.rb +43 -48
  91. data/lib/new_relic/agent/event_buffer.rb +8 -9
  92. data/lib/new_relic/agent/event_listener.rb +2 -3
  93. data/lib/new_relic/agent/event_loop.rb +27 -25
  94. data/lib/new_relic/agent/external.rb +20 -51
  95. data/lib/new_relic/agent/guid_generator.rb +30 -0
  96. data/lib/new_relic/agent/harvester.rb +5 -6
  97. data/lib/new_relic/agent/heap.rb +8 -10
  98. data/lib/new_relic/agent/hostname.rb +26 -5
  99. data/lib/new_relic/agent/http_clients/abstract.rb +81 -0
  100. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +26 -26
  101. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +31 -17
  102. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +18 -23
  103. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +12 -15
  104. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +24 -8
  105. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +9 -12
  106. data/lib/new_relic/agent/http_clients/uri_util.rb +12 -13
  107. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +22 -52
  108. data/lib/new_relic/agent/instrumentation/action_controller_other_subscriber.rb +39 -0
  109. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +59 -72
  110. data/lib/new_relic/agent/instrumentation/action_dispatch.rb +31 -0
  111. data/lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb +64 -0
  112. data/lib/new_relic/agent/instrumentation/action_mailbox.rb +30 -0
  113. data/lib/new_relic/agent/instrumentation/action_mailbox_subscriber.rb +33 -0
  114. data/lib/new_relic/agent/instrumentation/action_mailer.rb +30 -0
  115. data/lib/new_relic/agent/instrumentation/action_mailer_subscriber.rb +85 -0
  116. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +86 -62
  117. data/lib/new_relic/agent/instrumentation/active_job.rb +38 -19
  118. data/lib/new_relic/agent/instrumentation/active_job_subscriber.rb +41 -0
  119. data/lib/new_relic/agent/instrumentation/active_merchant.rb +21 -7
  120. data/lib/new_relic/agent/instrumentation/active_record.rb +95 -46
  121. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +82 -61
  122. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +155 -0
  123. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +36 -12
  124. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +69 -64
  125. data/lib/new_relic/agent/instrumentation/active_storage.rb +8 -4
  126. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +11 -32
  127. data/lib/new_relic/agent/instrumentation/active_support.rb +27 -0
  128. data/lib/new_relic/agent/instrumentation/active_support_logger/chain.rb +23 -0
  129. data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +20 -0
  130. data/lib/new_relic/agent/instrumentation/active_support_logger/prepend.rb +12 -0
  131. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +24 -0
  132. data/lib/new_relic/agent/instrumentation/active_support_subscriber.rb +41 -0
  133. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +45 -0
  134. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +150 -0
  135. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +35 -0
  136. data/lib/new_relic/agent/instrumentation/bunny.rb +14 -134
  137. data/lib/new_relic/agent/instrumentation/concurrent_ruby/chain.rb +36 -0
  138. data/lib/new_relic/agent/instrumentation/concurrent_ruby/instrumentation.rb +21 -0
  139. data/lib/new_relic/agent/instrumentation/concurrent_ruby/prepend.rb +27 -0
  140. data/lib/new_relic/agent/instrumentation/concurrent_ruby.rb +31 -0
  141. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +77 -61
  142. data/lib/new_relic/agent/instrumentation/curb/chain.rb +91 -0
  143. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +221 -0
  144. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +61 -0
  145. data/lib/new_relic/agent/instrumentation/curb.rb +15 -187
  146. data/lib/new_relic/agent/instrumentation/custom_events.rb +12 -0
  147. data/lib/new_relic/agent/instrumentation/custom_events_subscriber.rb +37 -0
  148. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +35 -0
  149. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +48 -0
  150. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +33 -0
  151. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +30 -52
  152. data/lib/new_relic/agent/instrumentation/elasticsearch/chain.rb +29 -0
  153. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +66 -0
  154. data/lib/new_relic/agent/instrumentation/elasticsearch/prepend.rb +13 -0
  155. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +31 -0
  156. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +8 -7
  157. data/lib/new_relic/agent/instrumentation/excon.rb +29 -31
  158. data/lib/new_relic/agent/instrumentation/fiber/chain.rb +20 -0
  159. data/lib/new_relic/agent/instrumentation/fiber/instrumentation.rb +24 -0
  160. data/lib/new_relic/agent/instrumentation/fiber/prepend.rb +18 -0
  161. data/lib/new_relic/agent/instrumentation/fiber.rb +25 -0
  162. data/lib/new_relic/agent/instrumentation/grape/chain.rb +24 -0
  163. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +100 -0
  164. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +17 -0
  165. data/lib/new_relic/agent/instrumentation/grape.rb +16 -121
  166. data/lib/new_relic/agent/instrumentation/grpc/client/chain.rb +97 -0
  167. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +89 -0
  168. data/lib/new_relic/agent/instrumentation/grpc/client/prepend.rb +111 -0
  169. data/lib/new_relic/agent/instrumentation/grpc/client/request_wrapper.rb +30 -0
  170. data/lib/new_relic/agent/instrumentation/grpc/helper.rb +32 -0
  171. data/lib/new_relic/agent/instrumentation/grpc/server/chain.rb +69 -0
  172. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +134 -0
  173. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_desc_prepend.rb +35 -0
  174. data/lib/new_relic/agent/instrumentation/grpc/server/rpc_server_prepend.rb +26 -0
  175. data/lib/new_relic/agent/instrumentation/grpc_client.rb +23 -0
  176. data/lib/new_relic/agent/instrumentation/grpc_server.rb +25 -0
  177. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +24 -0
  178. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +37 -0
  179. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +15 -0
  180. data/lib/new_relic/agent/instrumentation/httpclient.rb +12 -32
  181. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +22 -0
  182. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +30 -0
  183. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +15 -0
  184. data/lib/new_relic/agent/instrumentation/httprb.rb +29 -0
  185. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +5 -6
  186. data/lib/new_relic/agent/instrumentation/logger/chain.rb +21 -0
  187. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +66 -0
  188. data/lib/new_relic/agent/instrumentation/logger/prepend.rb +13 -0
  189. data/lib/new_relic/agent/instrumentation/logger.rb +26 -0
  190. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +15 -0
  191. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +58 -125
  192. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +59 -0
  193. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +90 -0
  194. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +101 -0
  195. data/lib/new_relic/agent/instrumentation/memcache.rb +57 -71
  196. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +15 -14
  197. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +21 -14
  198. data/lib/new_relic/agent/instrumentation/mongo.rb +7 -132
  199. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +49 -13
  200. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +24 -0
  201. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +40 -0
  202. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +21 -0
  203. data/lib/new_relic/agent/instrumentation/net_http.rb +44 -0
  204. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +142 -0
  205. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +38 -0
  206. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +28 -0
  207. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +20 -0
  208. data/lib/new_relic/agent/instrumentation/padrino.rb +22 -58
  209. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +7 -7
  210. data/lib/new_relic/agent/instrumentation/queue_time.rb +9 -10
  211. data/lib/new_relic/agent/instrumentation/rack/chain.rb +66 -0
  212. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +33 -0
  213. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +75 -0
  214. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +43 -0
  215. data/lib/new_relic/agent/instrumentation/rack.rb +33 -141
  216. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +19 -55
  217. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +5 -5
  218. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +36 -0
  219. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +45 -0
  220. data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +30 -0
  221. data/lib/new_relic/agent/instrumentation/rails_notifications/custom_events.rb +30 -0
  222. data/lib/new_relic/agent/instrumentation/rake/chain.rb +20 -0
  223. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +142 -0
  224. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +14 -0
  225. data/lib/new_relic/agent/instrumentation/rake.rb +18 -159
  226. data/lib/new_relic/agent/instrumentation/redis/chain.rb +45 -0
  227. data/lib/new_relic/agent/instrumentation/redis/constants.rb +17 -0
  228. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +93 -0
  229. data/lib/new_relic/agent/instrumentation/redis/middleware.rb +16 -0
  230. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +29 -0
  231. data/lib/new_relic/agent/instrumentation/redis.rb +20 -103
  232. data/lib/new_relic/agent/instrumentation/resque/chain.rb +21 -0
  233. data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
  234. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +34 -0
  235. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +15 -0
  236. data/lib/new_relic/agent/instrumentation/resque.rb +33 -41
  237. data/lib/new_relic/agent/instrumentation/sequel.rb +17 -20
  238. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +3 -3
  239. data/lib/new_relic/agent/instrumentation/sidekiq/client.rb +20 -0
  240. data/lib/new_relic/agent/instrumentation/sidekiq/extensions/delayed_class.rb +30 -0
  241. data/lib/new_relic/agent/instrumentation/sidekiq/server.rb +37 -0
  242. data/lib/new_relic/agent/instrumentation/sidekiq.rb +29 -46
  243. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +55 -0
  244. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +31 -37
  245. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +125 -0
  246. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +33 -0
  247. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +3 -3
  248. data/lib/new_relic/agent/instrumentation/sinatra.rb +35 -165
  249. data/lib/new_relic/agent/instrumentation/thread/chain.rb +24 -0
  250. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +28 -0
  251. data/lib/new_relic/agent/instrumentation/thread/prepend.rb +22 -0
  252. data/lib/new_relic/agent/instrumentation/thread.rb +20 -0
  253. data/lib/new_relic/agent/instrumentation/tilt/chain.rb +24 -0
  254. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +41 -0
  255. data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +13 -0
  256. data/lib/new_relic/agent/instrumentation/tilt.rb +25 -0
  257. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +22 -0
  258. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +80 -0
  259. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +14 -0
  260. data/lib/new_relic/agent/instrumentation/typhoeus.rb +14 -76
  261. data/lib/new_relic/agent/instrumentation.rb +2 -2
  262. data/lib/new_relic/agent/internal_agent_error.rb +3 -3
  263. data/lib/new_relic/agent/javascript_instrumentor.rb +51 -45
  264. data/lib/new_relic/agent/linking_metadata.rb +44 -0
  265. data/lib/new_relic/agent/local_log_decorator.rb +37 -0
  266. data/lib/new_relic/agent/log_event_aggregator.rb +235 -0
  267. data/lib/new_relic/agent/log_once.rb +2 -2
  268. data/lib/new_relic/agent/log_priority.rb +20 -0
  269. data/lib/new_relic/agent/logging.rb +142 -0
  270. data/lib/new_relic/agent/memory_logger.rb +3 -3
  271. data/lib/new_relic/agent/messaging.rb +81 -164
  272. data/lib/new_relic/agent/method_tracer.rb +152 -145
  273. data/lib/new_relic/agent/method_tracer_helpers.rb +90 -13
  274. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +117 -0
  275. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +28 -0
  276. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +5 -6
  277. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +9 -15
  278. data/lib/new_relic/agent/monitors.rb +26 -0
  279. data/lib/new_relic/agent/new_relic_service/encoders.rb +7 -7
  280. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +6 -7
  281. data/lib/new_relic/agent/new_relic_service/marshaller.rb +8 -29
  282. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +5 -5
  283. data/lib/new_relic/agent/new_relic_service.rb +282 -166
  284. data/lib/new_relic/agent/noticeable_error.rb +19 -0
  285. data/lib/new_relic/agent/null_logger.rb +8 -4
  286. data/lib/new_relic/agent/obfuscator.rb +9 -11
  287. data/lib/new_relic/agent/parameter_filtering.rb +35 -8
  288. data/lib/new_relic/agent/payload_metric_mapping.rb +10 -11
  289. data/lib/new_relic/agent/pipe_channel_manager.rb +28 -18
  290. data/lib/new_relic/agent/pipe_service.rb +9 -6
  291. data/lib/new_relic/agent/prepend_supportability.rb +3 -3
  292. data/lib/new_relic/agent/priority_sampled_buffer.rb +16 -14
  293. data/lib/new_relic/agent/range_extensions.rb +9 -29
  294. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +12 -12
  295. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +13 -14
  296. data/lib/new_relic/agent/rules_engine.rb +6 -5
  297. data/lib/new_relic/agent/sampler.rb +4 -5
  298. data/lib/new_relic/agent/sampler_collection.rb +4 -5
  299. data/lib/new_relic/agent/samplers/cpu_sampler.rb +4 -3
  300. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +14 -11
  301. data/lib/new_relic/agent/samplers/memory_sampler.rb +26 -15
  302. data/lib/new_relic/agent/samplers/object_sampler.rb +2 -2
  303. data/lib/new_relic/agent/samplers/vm_sampler.rb +22 -20
  304. data/lib/new_relic/agent/span_event_aggregator.rb +14 -16
  305. data/lib/new_relic/agent/span_event_primitive.rb +118 -58
  306. data/lib/new_relic/agent/sql_sampler.rb +25 -25
  307. data/lib/new_relic/agent/stats.rb +79 -42
  308. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +11 -13
  309. data/lib/new_relic/agent/stats_engine/stats_hash.rb +13 -14
  310. data/lib/new_relic/agent/stats_engine.rb +11 -11
  311. data/lib/new_relic/agent/synthetics_event_aggregator.rb +8 -9
  312. data/lib/new_relic/agent/system_info.rb +100 -66
  313. data/lib/new_relic/agent/threading/agent_thread.rb +20 -16
  314. data/lib/new_relic/agent/threading/backtrace_node.rb +13 -14
  315. data/lib/new_relic/agent/threading/backtrace_service.rb +18 -18
  316. data/lib/new_relic/agent/threading/thread_profile.rb +31 -45
  317. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +2 -2
  318. data/lib/new_relic/agent/tracer.rb +513 -0
  319. data/lib/new_relic/agent/transaction/abstract_segment.rb +131 -41
  320. data/lib/new_relic/agent/transaction/datastore_segment.rb +22 -18
  321. data/lib/new_relic/agent/transaction/distributed_tracer.rb +184 -0
  322. data/lib/new_relic/agent/transaction/distributed_tracing.rb +72 -163
  323. data/lib/new_relic/agent/transaction/external_request_segment.rb +66 -63
  324. data/lib/new_relic/agent/transaction/message_broker_segment.rb +34 -46
  325. data/lib/new_relic/agent/transaction/request_attributes.rb +36 -36
  326. data/lib/new_relic/agent/transaction/segment.rb +46 -10
  327. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +2 -4
  328. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +2 -2
  329. data/lib/new_relic/agent/transaction/trace.rb +21 -24
  330. data/lib/new_relic/agent/transaction/trace_builder.rb +11 -12
  331. data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
  332. data/lib/new_relic/agent/transaction/trace_node.rb +31 -28
  333. data/lib/new_relic/agent/transaction/tracing.rb +15 -111
  334. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +6 -6
  335. data/lib/new_relic/agent/transaction.rb +252 -259
  336. data/lib/new_relic/agent/transaction_error_primitive.rb +34 -37
  337. data/lib/new_relic/agent/transaction_event_aggregator.rb +13 -13
  338. data/lib/new_relic/agent/transaction_event_primitive.rb +44 -56
  339. data/lib/new_relic/agent/transaction_event_recorder.rb +17 -16
  340. data/lib/new_relic/agent/transaction_metrics.rb +11 -10
  341. data/lib/new_relic/agent/transaction_sampler.rb +7 -12
  342. data/lib/new_relic/agent/transaction_time_aggregator.rb +41 -26
  343. data/lib/new_relic/agent/utilization/aws.rb +34 -4
  344. data/lib/new_relic/agent/utilization/azure.rb +4 -4
  345. data/lib/new_relic/agent/utilization/gcp.rb +8 -8
  346. data/lib/new_relic/agent/utilization/pcf.rb +6 -5
  347. data/lib/new_relic/agent/utilization/vendor.rb +44 -29
  348. data/lib/new_relic/agent/utilization_data.rb +43 -6
  349. data/lib/new_relic/agent/vm/jruby_vm.rb +2 -2
  350. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +3 -3
  351. data/lib/new_relic/agent/vm/mri_vm.rb +46 -19
  352. data/lib/new_relic/agent/vm/snapshot.rb +6 -6
  353. data/lib/new_relic/agent/vm.rb +2 -2
  354. data/lib/new_relic/agent/worker_loop.rb +11 -13
  355. data/lib/new_relic/agent.rb +151 -79
  356. data/lib/new_relic/cli/command.rb +21 -23
  357. data/lib/new_relic/cli/commands/deployments.rb +94 -45
  358. data/lib/new_relic/cli/commands/install.rb +24 -26
  359. data/lib/new_relic/coerce.rb +42 -15
  360. data/lib/new_relic/collection_helper.rb +51 -49
  361. data/lib/new_relic/constants.rb +39 -0
  362. data/lib/new_relic/control/class_methods.rb +11 -5
  363. data/lib/new_relic/control/frameworks/external.rb +3 -3
  364. data/lib/new_relic/control/frameworks/rails.rb +24 -18
  365. data/lib/new_relic/control/frameworks/rails3.rb +4 -5
  366. data/lib/new_relic/control/frameworks/rails4.rb +2 -2
  367. data/lib/new_relic/control/frameworks/rails_notifications.rb +14 -0
  368. data/lib/new_relic/control/frameworks/ruby.rb +4 -4
  369. data/lib/new_relic/control/frameworks/sinatra.rb +8 -2
  370. data/lib/new_relic/control/frameworks.rb +2 -2
  371. data/lib/new_relic/control/instance_methods.rb +33 -42
  372. data/lib/new_relic/control/instrumentation.rb +40 -12
  373. data/lib/new_relic/control/private_instance_methods.rb +48 -0
  374. data/lib/new_relic/control/server_methods.rb +4 -5
  375. data/lib/new_relic/control.rb +2 -3
  376. data/lib/new_relic/delayed_job_injection.rb +2 -2
  377. data/lib/new_relic/dependency_detection.rb +129 -18
  378. data/lib/new_relic/environment_report.rb +41 -35
  379. data/lib/new_relic/helper.rb +49 -8
  380. data/lib/new_relic/language_support.rb +30 -6
  381. data/lib/new_relic/latest_changes.rb +9 -8
  382. data/lib/new_relic/local_environment.rb +23 -27
  383. data/lib/new_relic/metric_data.rb +32 -27
  384. data/lib/new_relic/metric_spec.rb +9 -7
  385. data/lib/new_relic/noticed_error.rb +46 -33
  386. data/lib/new_relic/rack/agent_hooks.rb +2 -2
  387. data/lib/new_relic/rack/agent_middleware.rb +7 -5
  388. data/lib/new_relic/rack/browser_monitoring.rb +134 -117
  389. data/lib/new_relic/rack.rb +2 -2
  390. data/lib/new_relic/recipes/capistrano3.rb +4 -62
  391. data/lib/new_relic/recipes/capistrano_legacy.rb +24 -27
  392. data/lib/new_relic/recipes/helpers/send_deployment.rb +70 -0
  393. data/lib/new_relic/recipes.rb +2 -2
  394. data/lib/new_relic/supportability_helper.rb +21 -7
  395. data/lib/new_relic/traced_thread.rb +39 -0
  396. data/lib/new_relic/version.rb +7 -18
  397. data/lib/newrelic_rpm.rb +20 -33
  398. data/lib/sequel/extensions/{newrelic_instrumentation.rb → new_relic_instrumentation.rb} +16 -19
  399. data/lib/sequel/plugins/{newrelic_instrumentation.rb → new_relic_instrumentation.rb} +9 -15
  400. data/lib/tasks/all.rb +4 -4
  401. data/lib/tasks/config.rake +22 -118
  402. data/lib/tasks/coverage_report.rake +28 -0
  403. data/lib/tasks/helpers/config.html.erb +21 -0
  404. data/lib/tasks/helpers/format.rb +123 -0
  405. data/lib/tasks/helpers/matches.rb +12 -0
  406. data/lib/tasks/helpers/prompt.rb +24 -0
  407. data/lib/tasks/helpers/removers.rb +33 -0
  408. data/lib/tasks/install.rake +4 -0
  409. data/lib/tasks/instrumentation_generator/README.md +63 -0
  410. data/lib/tasks/instrumentation_generator/TODO.md +33 -0
  411. data/lib/tasks/instrumentation_generator/instrumentation.thor +121 -0
  412. data/lib/tasks/instrumentation_generator/templates/Envfile.tt +9 -0
  413. data/lib/tasks/instrumentation_generator/templates/chain.tt +22 -0
  414. data/lib/tasks/instrumentation_generator/templates/chain_method.tt +8 -0
  415. data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +29 -0
  416. data/lib/tasks/instrumentation_generator/templates/instrumentation.tt +13 -0
  417. data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +3 -0
  418. data/lib/tasks/instrumentation_generator/templates/newrelic.yml.tt +19 -0
  419. data/lib/tasks/instrumentation_generator/templates/prepend.tt +13 -0
  420. data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +3 -0
  421. data/lib/tasks/instrumentation_generator/templates/test.tt +15 -0
  422. data/lib/tasks/multiverse.rake +4 -0
  423. data/lib/tasks/multiverse.rb +12 -5
  424. data/lib/tasks/newrelic.rb +2 -2
  425. data/lib/tasks/tests.rake +14 -14
  426. data/newrelic.yml +672 -3
  427. data/newrelic_rpm.gemspec +40 -31
  428. data/recipes/newrelic.rb +3 -3
  429. data/test/agent_helper.rb +419 -98
  430. metadata +238 -127
  431. data/.travis.yml +0 -228
  432. data/bin/mongrel_rpm +0 -33
  433. data/cert/cacert.pem +0 -1177
  434. data/lib/new_relic/agent/commands/xray_session.rb +0 -55
  435. data/lib/new_relic/agent/commands/xray_session_collection.rb +0 -161
  436. data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
  437. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +0 -44
  438. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +0 -53
  439. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -41
  440. data/lib/new_relic/agent/distributed_trace_payload.rb +0 -246
  441. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
  442. data/lib/new_relic/agent/instrumentation/active_record_4.rb +0 -42
  443. data/lib/new_relic/agent/instrumentation/active_record_5.rb +0 -41
  444. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +0 -74
  445. data/lib/new_relic/agent/instrumentation/authlogic.rb +0 -25
  446. data/lib/new_relic/agent/instrumentation/data_mapper.rb +0 -202
  447. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +0 -104
  448. data/lib/new_relic/agent/instrumentation/excon/connection.rb +0 -46
  449. data/lib/new_relic/agent/instrumentation/http.rb +0 -46
  450. data/lib/new_relic/agent/instrumentation/merb/controller.rb +0 -44
  451. data/lib/new_relic/agent/instrumentation/merb/errors.rb +0 -33
  452. data/lib/new_relic/agent/instrumentation/net.rb +0 -50
  453. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +0 -125
  454. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +0 -46
  455. data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +0 -32
  456. data/lib/new_relic/agent/instrumentation/rails4/action_view.rb +0 -27
  457. data/lib/new_relic/agent/instrumentation/rails5/action_cable.rb +0 -36
  458. data/lib/new_relic/agent/instrumentation/rails5/action_controller.rb +0 -33
  459. data/lib/new_relic/agent/instrumentation/rails5/action_view.rb +0 -27
  460. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +0 -26
  461. data/lib/new_relic/agent/instrumentation/sunspot.rb +0 -33
  462. data/lib/new_relic/agent/supported_versions.rb +0 -275
  463. data/lib/new_relic/agent/transaction/attributes.rb +0 -154
  464. data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +0 -64
  465. data/lib/new_relic/agent/transaction_state.rb +0 -186
  466. data/lib/new_relic/build.rb +0 -2
  467. data/lib/new_relic/control/frameworks/merb.rb +0 -29
  468. data/lib/new_relic/control/frameworks/rails5.rb +0 -14
  469. data/lib/new_relic/metrics.rb +0 -13
  470. data/lib/tasks/config.html.erb +0 -32
  471. data/lib/tasks/versions.html.erb +0 -28
  472. data/lib/tasks/versions.postface.html +0 -8
  473. data/lib/tasks/versions.preface.html +0 -9
  474. data/lib/tasks/versions.rake +0 -65
  475. data/lib/tasks/versions.txt.erb +0 -14
  476. /data/lib/tasks/{config.text.erb → helpers/config.text.erb} +0 -0
@@ -1,16 +1,17 @@
1
- # encoding: utf-8
2
1
  # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
4
 
5
5
  require 'new_relic/agent/instrumentation/queue_time'
6
6
  require 'new_relic/agent/transaction_metrics'
7
7
  require 'new_relic/agent/method_tracer_helpers'
8
- require 'new_relic/agent/transaction/attributes'
8
+ require 'new_relic/agent/attributes'
9
9
  require 'new_relic/agent/transaction/request_attributes'
10
10
  require 'new_relic/agent/transaction/tracing'
11
- require 'new_relic/agent/transaction/distributed_tracing'
12
- require 'new_relic/agent/cross_app_tracing'
11
+ require 'new_relic/agent/transaction/distributed_tracer'
13
12
  require 'new_relic/agent/transaction_time_aggregator'
13
+ require 'new_relic/agent/deprecator'
14
+ require 'new_relic/agent/guid_generator'
14
15
 
15
16
  module NewRelic
16
17
  module Agent
@@ -20,29 +21,37 @@ module NewRelic
20
21
  # @api public
21
22
  class Transaction
22
23
  include Tracing
23
- include DistributedTracing
24
- include CrossAppTracing
25
24
 
26
25
  # for nested transactions
27
- SUBTRANSACTION_PREFIX = 'Nested/'.freeze
28
- CONTROLLER_PREFIX = 'Controller/'.freeze
29
- MIDDLEWARE_PREFIX = 'Middleware/Rack/'.freeze
30
- TASK_PREFIX = 'OtherTransaction/Background/'.freeze
31
- RAKE_PREFIX = 'OtherTransaction/Rake/'.freeze
32
- MESSAGE_PREFIX = 'OtherTransaction/Message/'.freeze
33
- RACK_PREFIX = 'Controller/Rack/'.freeze
34
- SINATRA_PREFIX = 'Controller/Sinatra/'.freeze
35
- GRAPE_PREFIX = 'Controller/Grape/'.freeze
36
- ACTION_CABLE_PREFIX = 'Controller/ActionCable/'.freeze
37
- OTHER_TRANSACTION_PREFIX = 'OtherTransaction/'.freeze
38
-
39
- WEB_TRANSACTION_CATEGORIES = [:controller, :uri, :rack, :sinatra, :grape, :middleware, :action_cable].freeze
40
- TRANSACTION_NAMING_SOURCES = [:child, :api].freeze
41
-
42
- MIDDLEWARE_SUMMARY_METRICS = ['Middleware/all'.freeze].freeze
43
-
44
- # reference to the transaction state managing this transaction
45
- attr_accessor :state
26
+ NESTED_TRANSACTION_PREFIX = "Nested/"
27
+ CONTROLLER_PREFIX = "Controller/"
28
+ MIDDLEWARE_PREFIX = "Middleware/Rack/"
29
+ OTHER_TRANSACTION_PREFIX = "OtherTransaction/"
30
+ TASK_PREFIX = "#{OTHER_TRANSACTION_PREFIX}Background/"
31
+ RAKE_PREFIX = "#{OTHER_TRANSACTION_PREFIX}Rake/"
32
+ MESSAGE_PREFIX = "#{OTHER_TRANSACTION_PREFIX}Message/"
33
+ RACK_PREFIX = "#{CONTROLLER_PREFIX}Rack/"
34
+ SINATRA_PREFIX = "#{CONTROLLER_PREFIX}Sinatra/"
35
+ GRAPE_PREFIX = "#{CONTROLLER_PREFIX}Grape/"
36
+ ACTION_CABLE_PREFIX = "#{CONTROLLER_PREFIX}ActionCable/"
37
+
38
+ WEB_TRANSACTION_CATEGORIES = [:web, :controller, :uri, :rack, :sinatra, :grape, :middleware, :action_cable].freeze
39
+
40
+ MIDDLEWARE_SUMMARY_METRICS = ["Middleware/all"].freeze
41
+ WEB_SUMMARY_METRIC = "HttpDispatcher"
42
+ OTHER_SUMMARY_METRIC = "#{OTHER_TRANSACTION_PREFIX}all"
43
+ QUEUE_TIME_METRIC = "WebFrontend/QueueTime"
44
+
45
+ APDEX_S = "S"
46
+ APDEX_T = "T"
47
+ APDEX_F = "F"
48
+ APDEX_ALL_METRIC = "ApdexAll"
49
+ APDEX_METRIC = "Apdex"
50
+ APDEX_OTHER_METRIC = "ApdexOther"
51
+ APDEX_TXN_METRIC_PREFIX = "Apdex/"
52
+ APDEX_OTHER_TXN_METRIC_PREFIX = "ApdexOther/Transaction/"
53
+
54
+ JRUBY_CPU_TIME_ERROR = "Error calculating JRuby CPU Time"
46
55
 
47
56
  # A Time instance for the start time, never nil
48
57
  attr_accessor :start_time
@@ -53,27 +62,28 @@ module NewRelic
53
62
  attr_accessor :apdex_start
54
63
 
55
64
  attr_accessor :exceptions,
56
- :filtered_params,
57
- :jruby_cpu_start,
58
- :process_cpu_start,
59
- :http_response_code,
60
- :response_content_length,
61
- :response_content_type
65
+ :filtered_params,
66
+ :jruby_cpu_start,
67
+ :process_cpu_start,
68
+ :http_response_code,
69
+ :response_content_length,
70
+ :response_content_type,
71
+ :parent_span_id
62
72
 
63
73
  attr_reader :guid,
64
- :metrics,
65
- :gc_start_snapshot,
66
- :category,
67
- :frame_stack,
68
- :attributes,
69
- :payload,
70
- :nesting_max_depth,
71
- :segments,
72
- :end_time,
73
- :duration
74
+ :metrics,
75
+ :logs,
76
+ :gc_start_snapshot,
77
+ :category,
78
+ :attributes,
79
+ :payload,
80
+ :nesting_max_depth,
81
+ :segments,
82
+ :end_time,
83
+ :duration
74
84
 
75
85
  attr_writer :sampled,
76
- :priority
86
+ :priority
77
87
 
78
88
  # Populated with the trace sample once this transaction is completed.
79
89
  attr_reader :transaction_trace
@@ -83,112 +93,53 @@ module NewRelic
83
93
 
84
94
  # Return the currently active transaction, or nil.
85
95
  def self.tl_current
86
- TransactionState.tl_get.current_transaction
96
+ Tracer.current_transaction
87
97
  end
88
98
 
89
- def self.set_default_transaction_name(name, category = nil, node_name = nil) #THREAD_LOCAL_ACCESS
90
- txn = tl_current
91
- name = txn.make_transaction_name(name, category)
92
- txn.name_last_frame(node_name || name)
99
+ def self.set_default_transaction_name(partial_name, category = nil) # THREAD_LOCAL_ACCESS
100
+ txn = tl_current
101
+ name = name_from_partial(partial_name, category || txn.category)
93
102
  txn.set_default_transaction_name(name, category)
94
103
  end
95
104
 
96
- def self.set_overriding_transaction_name(name, category = nil) #THREAD_LOCAL_ACCESS
105
+ def self.set_overriding_transaction_name(partial_name, category = nil) # THREAD_LOCAL_ACCESS
97
106
  txn = tl_current
98
107
  return unless txn
99
108
 
100
- name = txn.make_transaction_name(name, category)
101
-
102
- txn.name_last_frame(name)
109
+ name = name_from_partial(partial_name, category || txn.category)
103
110
  txn.set_overriding_transaction_name(name, category)
104
111
  end
105
112
 
106
- def self.wrap(state, name, category, options = {})
107
- Transaction.start(state, category, options.merge(:transaction_name => name))
108
-
109
- begin
110
- # We shouldn't raise from Transaction.start, but only wrap the yield
111
- # to be absolutely sure we don't report agent problems as app errors
112
- yield
113
- rescue => e
114
- Transaction.notice_error(e)
115
- raise e
116
- ensure
117
- Transaction.stop(state)
118
- end
119
- end
120
-
121
- def self.start(state, category, options)
122
- category ||= :controller
123
- txn = state.current_transaction
124
-
125
- if txn
126
- txn.create_nested_frame(category, options)
127
- else
128
- txn = start_new_transaction(state, category, options)
129
- end
130
-
131
- txn
132
- rescue => e
133
- NewRelic::Agent.logger.error("Exception during Transaction.start", e)
134
- nil
113
+ def self.name_from_partial(partial_name, category)
114
+ namer = Instrumentation::ControllerInstrumentation::TransactionNamer
115
+ "#{namer.prefix_for_category(self, category)}#{partial_name}"
135
116
  end
136
117
 
137
118
  def self.start_new_transaction(state, category, options)
138
119
  txn = Transaction.new(category, options)
139
120
  state.reset(txn)
140
- txn.state = state
141
- txn.start
121
+ txn.start(options)
142
122
  txn
143
123
  end
144
124
 
145
- FAILED_TO_STOP_MESSAGE = "Failed during Transaction.stop because there is no current transaction"
146
-
147
- def self.stop(state)
148
- txn = state.current_transaction
149
-
150
- if txn.nil?
151
- NewRelic::Agent.logger.error(FAILED_TO_STOP_MESSAGE)
152
- return
153
- end
154
-
155
- nested_frame = txn.frame_stack.pop
156
-
157
- if txn.frame_stack.empty?
158
- txn.stop(nested_frame) if nested_frame
159
- state.reset
160
- else
161
- nested_frame.finish
162
- end
163
-
164
- :transaction_stopped
165
- rescue => e
166
- state.reset
167
- NewRelic::Agent.logger.error("Exception during Transaction.stop", e)
168
- nil
169
- end
170
-
171
125
  def self.nested_transaction_name(name)
172
- if name.start_with?(CONTROLLER_PREFIX) || name.start_with?(OTHER_TRANSACTION_PREFIX)
173
- "#{SUBTRANSACTION_PREFIX}#{name}"
126
+ if name.start_with?(CONTROLLER_PREFIX, OTHER_TRANSACTION_PREFIX)
127
+ "#{NESTED_TRANSACTION_PREFIX}#{name}"
174
128
  else
175
129
  name
176
130
  end
177
131
  end
178
132
 
179
- # Indicate that you don't want to keep the currently saved transaction
180
- # information
181
- def self.abort_transaction! #THREAD_LOCAL_ACCESS
182
- state = NewRelic::Agent::TransactionState.tl_get
183
- txn = state.current_transaction
184
- txn.abort_transaction! if txn
133
+ # discards the currently saved transaction information
134
+ def self.abort_transaction!
135
+ if txn = Tracer.current_transaction
136
+ txn.abort_transaction!
137
+ end
185
138
  end
186
139
 
187
140
  # See NewRelic::Agent.notice_error for options and commentary
188
- def self.notice_error(e, options={}) #THREAD_LOCAL_ACCESS
189
- state = NewRelic::Agent::TransactionState.tl_get
190
- txn = state.current_transaction
191
- if txn
141
+ def self.notice_error(e, options = {})
142
+ if txn = Tracer.current_transaction
192
143
  txn.notice_error(e, options)
193
144
  elsif NewRelic::Agent.instance
194
145
  NewRelic::Agent.instance.error_collector.notice_error(e, options)
@@ -200,7 +151,7 @@ module NewRelic
200
151
  #
201
152
  # @api public
202
153
  #
203
- def self.recording_web_transaction? #THREAD_LOCAL_ACCESS
154
+ def self.recording_web_transaction? # THREAD_LOCAL_ACCESS
204
155
  NewRelic::Agent.record_api_supportability_metric(:recording_web_transaction?)
205
156
 
206
157
  txn = tl_current
@@ -213,7 +164,7 @@ module NewRelic
213
164
  :apdex_f
214
165
  when duration <= apdex_t
215
166
  :apdex_s
216
- when duration <= 4 * apdex_t
167
+ when duration <= apdex_t * 4
217
168
  :apdex_t
218
169
  else
219
170
  :apdex_f
@@ -224,24 +175,26 @@ module NewRelic
224
175
  if txn = tl_current
225
176
  txn.add_agent_attribute(key, value, default_destinations)
226
177
  else
227
- NewRelic::Agent.logger.debug "Attempted to add agent attribute: #{key} without transaction"
178
+ NewRelic::Agent.logger.debug("Attempted to add agent attribute: #{key} without transaction")
228
179
  end
229
180
  end
230
181
 
231
182
  def add_agent_attribute(key, value, default_destinations)
232
183
  @attributes.add_agent_attribute(key, value, default_destinations)
184
+ current_segment.add_agent_attribute(key, value) if current_segment
233
185
  end
234
186
 
235
187
  def self.merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
236
188
  if txn = tl_current
237
189
  txn.merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
238
190
  else
239
- NewRelic::Agent.logger.debug "Attempted to merge untrusted attributes without transaction"
191
+ NewRelic::Agent.logger.debug("Attempted to merge untrusted attributes without transaction")
240
192
  end
241
193
  end
242
194
 
243
195
  def merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
244
196
  @attributes.merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
197
+ current_segment.merge_untrusted_agent_attributes(attributes, prefix, default_destinations) if current_segment
245
198
  end
246
199
 
247
200
  @@java_classes_loaded = false
@@ -249,8 +202,8 @@ module NewRelic
249
202
  if defined? JRuby
250
203
  begin
251
204
  require 'java'
252
- java_import 'java.lang.management.ManagementFactory'
253
- java_import 'com.sun.management.OperatingSystemMXBean'
205
+ java_import('java.lang.management.ManagementFactory')
206
+ java_import('com.sun.management.OperatingSystemMXBean')
254
207
  @@java_classes_loaded = true
255
208
  rescue
256
209
  end
@@ -258,18 +211,19 @@ module NewRelic
258
211
 
259
212
  def initialize(category, options)
260
213
  @nesting_max_depth = 0
261
- @current_segment = nil
214
+ @current_segment_by_thread = {}
215
+ @current_segment_lock = Mutex.new
262
216
  @segments = []
263
- @frame_stack = []
264
217
 
265
218
  self.default_name = options[:transaction_name]
266
- @overridden_name = nil
267
- @frozen_name = nil
219
+ @overridden_name = nil
220
+ @frozen_name = nil
268
221
 
269
222
  @category = category
270
- @start_time = Time.now
223
+ @start_time = Process.clock_gettime(Process::CLOCK_REALTIME)
271
224
  @end_time = nil
272
225
  @duration = nil
226
+
273
227
  @apdex_start = options[:apdex_start_time] || @start_time
274
228
  @jruby_cpu_start = jruby_cpu_time
275
229
  @process_cpu_start = process_cpu
@@ -278,7 +232,8 @@ module NewRelic
278
232
 
279
233
  @exceptions = {}
280
234
  @metrics = TransactionMetrics.new
281
- @guid = generate_guid
235
+ @logs = PrioritySampledBuffer.new(NewRelic::Agent.instance.log_event_aggregator.capacity)
236
+ @guid = NewRelic::Agent::GuidGenerator.generate_guid
282
237
 
283
238
  @ignore_this_transaction = false
284
239
  @ignore_apdex = options.fetch(:ignore_apdex, false)
@@ -289,32 +244,68 @@ module NewRelic
289
244
  @priority = nil
290
245
 
291
246
  @starting_thread_id = Thread.current.object_id
247
+ @starting_segment_key = current_segment_key
292
248
 
293
249
  @attributes = Attributes.new(NewRelic::Agent.instance.attribute_filter)
294
250
 
295
251
  merge_request_parameters(@filtered_params)
296
252
 
297
253
  if request = options[:request]
298
- @request_attributes = RequestAttributes.new request
254
+ @request_attributes = RequestAttributes.new(request)
299
255
  else
300
256
  @request_attributes = nil
301
257
  end
302
258
  end
303
259
 
260
+ def state
261
+ NewRelic::Agent::Tracer.state
262
+ end
263
+
264
+ def current_segment_key
265
+ Tracer.current_segment_key
266
+ end
267
+
268
+ def parent_segment_key
269
+ (::Fiber.current.nr_parent_key if ::Fiber.current.respond_to?(:nr_parent_key)) || (::Thread.current.nr_parent_key if ::Thread.current.respond_to?(:nr_parent_key))
270
+ end
271
+
272
+ def current_segment
273
+ current_segment_by_thread[current_segment_key] ||
274
+ current_segment_by_thread[parent_segment_key] ||
275
+ current_segment_by_thread[@starting_segment_key]
276
+ end
277
+
278
+ def set_current_segment(new_segment)
279
+ @current_segment_lock.synchronize { current_segment_by_thread[current_segment_key] = new_segment }
280
+ end
281
+
282
+ def remove_current_segment_by_thread_id(id)
283
+ @current_segment_lock.synchronize { current_segment_by_thread.delete(id) }
284
+ end
285
+
286
+ def distributed_tracer
287
+ @distributed_tracer ||= DistributedTracer.new(self)
288
+ end
289
+
304
290
  def sampled?
305
291
  return unless Agent.config[:'distributed_tracing.enabled']
292
+
306
293
  if @sampled.nil?
307
294
  @sampled = NewRelic::Agent.instance.adaptive_sampler.sampled?
308
295
  end
309
296
  @sampled
310
297
  end
311
298
 
299
+ def trace_id
300
+ @trace_id ||= NewRelic::Agent::GuidGenerator.generate_guid(32)
301
+ end
302
+
303
+ def trace_id=(value)
304
+ @trace_id = value
305
+ end
306
+
312
307
  def priority
313
- if @priority.nil?
314
- @priority = rand.round(6)
315
- @priority += 1 if sampled?
316
- end
317
- @priority
308
+ @priority ||= (sampled? ? rand + 1.0 : rand).round(NewRelic::PRIORITY_PRECISION)
318
309
  end
319
310
 
320
311
  def referer
@@ -329,7 +320,7 @@ module NewRelic
329
320
  @request_attributes && @request_attributes.port
330
321
  end
331
322
 
332
- # This transaction-local hash may be used as temprory storage by
323
+ # This transaction-local hash may be used as temporary storage by
333
324
  # instrumentation that needs to pass data from one instrumentation point
334
325
  # to another.
335
326
  #
@@ -359,13 +350,9 @@ module NewRelic
359
350
  merge_untrusted_agent_attributes(params, :'request.parameters', AttributeFilter::DST_NONE)
360
351
  end
361
352
 
362
- def make_transaction_name(name, category=nil)
363
- namer = Instrumentation::ControllerInstrumentation::TransactionNamer
364
- "#{namer.prefix_for_category(self, category)}#{name}"
365
- end
366
-
367
353
  def set_default_transaction_name(name, category)
368
354
  return log_frozen_name(name) if name_frozen?
355
+
369
356
  if influences_transaction_name?(category)
370
357
  self.default_name = name
371
358
  @category = category if category
@@ -374,15 +361,9 @@ module NewRelic
374
361
 
375
362
  def set_overriding_transaction_name(name, category)
376
363
  return log_frozen_name(name) if name_frozen?
377
- if influences_transaction_name?(category)
378
- self.overridden_name = name
379
- @category = category if category
380
- end
381
- end
382
364
 
383
- def name_last_frame(name)
384
- name = self.class.nested_transaction_name(name) if nesting_max_depth > 1
385
- frame_stack.last.name = name
365
+ self.overridden_name = name
366
+ @category = category if category
386
367
  end
387
368
 
388
369
  def log_frozen_name(name)
@@ -391,24 +372,20 @@ module NewRelic
391
372
  end
392
373
 
393
374
  def influences_transaction_name?(category)
394
- !category || frame_stack.size == 1 || similar_category?(category)
375
+ !category || nesting_max_depth == 1 || similar_category?(category)
395
376
  end
396
377
 
397
378
  def best_name
398
- @frozen_name || @overridden_name ||
399
- @default_name || NewRelic::Agent::UNKNOWN_METRIC
379
+ @frozen_name ||
380
+ @overridden_name ||
381
+ @default_name ||
382
+ NewRelic::Agent::UNKNOWN_METRIC
400
383
  end
401
384
 
402
385
  # For common interface with Trace
403
386
  alias_method :transaction_name, :best_name
404
-
405
- attr_accessor :xray_session_id
406
387
  # End common interface
407
388
 
408
- def name_set?
409
- (@overridden_name || @default_name) ? true : false
410
- end
411
-
412
389
  def promoted_transaction_name(name)
413
390
  if name.start_with?(MIDDLEWARE_PREFIX)
414
391
  "#{CONTROLLER_PREFIX}#{name}"
@@ -440,28 +417,33 @@ module NewRelic
440
417
  @frozen_name ? true : false
441
418
  end
442
419
 
443
- def start
420
+ def start(options = {})
444
421
  return if !state.is_execution_traced?
445
422
 
446
- sql_sampler.on_start_transaction(state, start_time, request_path)
423
+ sql_sampler.on_start_transaction(state, request_path)
447
424
  NewRelic::Agent.instance.events.notify(:start_transaction)
448
425
  NewRelic::Agent::TransactionTimeAggregator.transaction_start(start_time)
449
426
 
450
427
  ignore! if user_defined_rules_ignore?
451
428
 
452
- create_initial_segment @default_name
429
+ create_initial_segment(options)
430
+ Segment.merge_untrusted_agent_attributes( \
431
+ @filtered_params,
432
+ :'request.parameters',
433
+ AttributeFilter::DST_SPAN_EVENTS
434
+ )
453
435
  end
454
436
 
455
437
  def initial_segment
456
438
  segments.first
457
439
  end
458
440
 
459
- def create_initial_segment name
460
- segment = create_segment @default_name
441
+ def create_initial_segment(options = {})
442
+ segment = create_segment(@default_name, options)
461
443
  segment.record_scoped_metric = false
462
444
  end
463
445
 
464
- def create_segment(name)
446
+ def create_segment(name, options = {})
465
447
  summary_metrics = nil
466
448
 
467
449
  if name.start_with?(MIDDLEWARE_PREFIX)
@@ -470,32 +452,37 @@ module NewRelic
470
452
 
471
453
  @nesting_max_depth += 1
472
454
 
473
- segment = self.class.start_segment(
455
+ segment = Tracer.start_segment(
474
456
  name: name,
475
457
  unscoped_metrics: summary_metrics
476
458
  )
477
459
 
478
- frame_stack.push segment
460
+ # #code_information will glean the code info out of the options hash
461
+ # if it exists or noop otherwise
462
+ segment.code_information = options
463
+
479
464
  segment
480
465
  end
481
466
 
482
- def create_nested_frame(category, options)
467
+ def create_nested_segment(category, options)
483
468
  if options[:filtered_params] && !options[:filtered_params].empty?
484
469
  @filtered_params = options[:filtered_params]
485
470
  merge_request_parameters(options[:filtered_params])
486
471
  end
487
472
 
488
- @ignore_apdex = options[:ignore_apdex] if options.key? :ignore_apdex
489
- @ignore_enduser = options[:ignore_enduser] if options.key? :ignore_enduser
473
+ @ignore_apdex = options[:ignore_apdex] if options.key?(:ignore_apdex)
474
+ @ignore_enduser = options[:ignore_enduser] if options.key?(:ignore_enduser)
490
475
 
491
- nest_initial_segment if nesting_max_depth == 1
492
- nested_name = self.class.nested_transaction_name options[:transaction_name]
493
- create_segment nested_name
476
+ nest_initial_segment if segments.length == 1
477
+ nested_name = self.class.nested_transaction_name(options[:transaction_name])
478
+
479
+ segment = create_segment(nested_name, options)
494
480
  set_default_transaction_name(options[:transaction_name], category)
481
+ segment
495
482
  end
496
483
 
497
484
  def nest_initial_segment
498
- self.initial_segment.name = self.class.nested_transaction_name initial_segment.name
485
+ self.initial_segment.name = self.class.nested_transaction_name(initial_segment.name)
499
486
  initial_segment.record_scoped_metric = true
500
487
  end
501
488
 
@@ -505,9 +492,6 @@ module NewRelic
505
492
  @ignore_trace = true
506
493
  end
507
494
 
508
- WEB_SUMMARY_METRIC = 'HttpDispatcher'.freeze
509
- OTHER_SUMMARY_METRIC = 'OtherTransaction/all'.freeze
510
-
511
495
  def summary_metrics
512
496
  if @frozen_name.start_with?(CONTROLLER_PREFIX)
513
497
  [WEB_SUMMARY_METRIC]
@@ -529,23 +513,30 @@ module NewRelic
529
513
  name.start_with?(MIDDLEWARE_PREFIX)
530
514
  end
531
515
 
532
- def stop(outermost_frame = nil)
533
- return if !state.is_execution_traced?
534
- return self.class.stop(state) unless outermost_frame
516
+ def finish
517
+ return unless state.is_execution_traced?
535
518
 
536
- @end_time = Time.now
537
- @duration = @end_time.to_f - @start_time.to_f
519
+ @end_time = Process.clock_gettime(Process::CLOCK_REALTIME)
520
+ @duration = @end_time - @start_time
538
521
  freeze_name_and_execute_if_not_ignored
539
522
 
540
523
  if nesting_max_depth == 1
541
- outermost_frame.name = @frozen_name
524
+ initial_segment.name = @frozen_name
542
525
  end
543
526
 
544
- outermost_frame.finish
527
+ initial_segment.transaction_name = @frozen_name
528
+ assign_segment_dt_attributes
529
+ assign_agent_attributes
530
+ initial_segment.finish
545
531
 
546
532
  NewRelic::Agent::TransactionTimeAggregator.transaction_stop(@end_time, @starting_thread_id)
547
533
 
548
- commit!(outermost_frame.name) unless @ignore_this_transaction
534
+ commit!(initial_segment.name) unless @ignore_this_transaction
535
+ rescue => e
536
+ NewRelic::Agent.logger.error("Exception during Transaction#finish", e)
537
+ nil
538
+ ensure
539
+ state.reset
549
540
  end
550
541
 
551
542
  def user_defined_rules_ignore?
@@ -559,8 +550,6 @@ module NewRelic
559
550
 
560
551
  def commit!(outermost_node_name)
561
552
  generate_payload
562
-
563
- assign_agent_attributes
564
553
  assign_intrinsics
565
554
 
566
555
  finalize_segments
@@ -572,22 +561,29 @@ module NewRelic
572
561
  record_total_time_metrics
573
562
  record_apdex unless ignore_apdex?
574
563
  record_queue_time
575
- record_cross_app_metrics
576
- record_distributed_tracing_metrics
564
+ distributed_tracer.record_metrics
577
565
 
578
566
  record_exceptions
579
567
  record_transaction_event
568
+ record_log_events
580
569
  merge_metrics
581
570
  send_transaction_finished_event
582
571
  end
583
572
 
573
+ def assign_segment_dt_attributes
574
+ dt_payload = distributed_tracer.trace_state_payload || distributed_tracer.distributed_trace_payload
575
+ parent_attributes = {}
576
+ DistributedTraceAttributes.copy_parent_attributes(self, dt_payload, parent_attributes)
577
+ parent_attributes.each { |k, v| initial_segment.add_agent_attribute(k, v) }
578
+ end
579
+
584
580
  def assign_agent_attributes
585
581
  default_destinations = AttributeFilter::DST_TRANSACTION_TRACER |
586
- AttributeFilter::DST_TRANSACTION_EVENTS |
587
- AttributeFilter::DST_ERROR_COLLECTOR
582
+ AttributeFilter::DST_TRANSACTION_EVENTS |
583
+ AttributeFilter::DST_ERROR_COLLECTOR
588
584
 
589
585
  if http_response_code
590
- add_agent_attribute(:httpResponseCode, http_response_code.to_s, default_destinations)
586
+ add_agent_attribute(:'http.statusCode', http_response_code, default_destinations)
591
587
  end
592
588
 
593
589
  if response_content_length
@@ -599,7 +595,7 @@ module NewRelic
599
595
  end
600
596
 
601
597
  if @request_attributes
602
- @request_attributes.assign_agent_attributes self
598
+ @request_attributes.assign_agent_attributes(self)
603
599
  end
604
600
 
605
601
  display_host = Agent.config[:'process_host.display_name']
@@ -625,11 +621,7 @@ module NewRelic
625
621
  attributes.add_intrinsic_attribute(:synthetics_monitor_id, synthetics_monitor_id)
626
622
  end
627
623
 
628
- if Agent.config[:'distributed_tracing.enabled']
629
- assign_distributed_trace_intrinsics
630
- elsif is_cross_app?
631
- assign_cross_app_intrinsics
632
- end
624
+ distributed_tracer.assign_intrinsics
633
625
  end
634
626
 
635
627
  def calculate_gc_time
@@ -637,6 +629,16 @@ module NewRelic
637
629
  NewRelic::Agent::StatsEngine::GCProfiler.record_delta(gc_start_snapshot, gc_stop_snapshot)
638
630
  end
639
631
 
632
+ # This method returns transport_duration in seconds. Transport duration
633
+ # is stored in milliseconds on the payload, but it's needed in seconds
634
+ # for metrics and intrinsics.
635
+ def calculate_transport_duration(distributed_trace_payload)
636
+ return unless distributed_trace_payload
637
+
638
+ duration = start_time - (distributed_trace_payload.timestamp / 1000.0)
639
+ [duration, 0].max
640
+ end
641
+
640
642
  # The summary metrics recorded by this method all end up with a duration
641
643
  # equal to the transaction itself, and an exclusive time of zero.
642
644
  def record_summary_metrics(outermost_node_name)
@@ -653,28 +655,27 @@ module NewRelic
653
655
 
654
656
  def generate_payload
655
657
  @payload = {
656
- :name => @frozen_name,
657
- :bucket => recording_web_transaction? ? :request : :background,
658
- :start_timestamp => start_time.to_f,
659
- :duration => duration,
660
- :metrics => @metrics,
661
- :attributes => @attributes,
662
- :error => false,
663
- :priority => priority
658
+ :name => @frozen_name,
659
+ :bucket => recording_web_transaction? ? :request : :background,
660
+ :start_timestamp => start_time,
661
+ :duration => duration,
662
+ :metrics => @metrics,
663
+ :attributes => @attributes,
664
+ :error => false,
665
+ :priority => priority
664
666
  }
665
667
 
666
- append_cat_info(@payload)
667
- append_distributed_trace_info(@payload)
668
+ distributed_tracer.append_payload(@payload)
668
669
  append_apdex_perf_zone(@payload)
669
670
  append_synthetics_to(@payload)
670
671
  end
671
672
 
672
673
  def include_guid?
673
- is_cross_app? || is_synthetics_request?
674
+ distributed_tracer.is_cross_app? || is_synthetics_request?
674
675
  end
675
676
 
676
677
  def is_synthetics_request?
677
- synthetics_payload != nil && raw_synthetics_header != nil
678
+ !synthetics_payload.nil? && !raw_synthetics_header.nil?
678
679
  end
679
680
 
680
681
  def synthetics_version
@@ -702,10 +703,6 @@ module NewRelic
702
703
  info[4]
703
704
  end
704
705
 
705
- APDEX_S = 'S'.freeze
706
- APDEX_T = 'T'.freeze
707
- APDEX_F = 'F'.freeze
708
-
709
706
  def append_apdex_perf_zone(payload)
710
707
  if recording_web_transaction?
711
708
  bucket = apdex_bucket(duration, apdex_t)
@@ -719,7 +716,6 @@ module NewRelic
719
716
  when :apdex_s then APDEX_S
720
717
  when :apdex_t then APDEX_T
721
718
  when :apdex_f then APDEX_F
722
- else nil
723
719
  end
724
720
  payload[:apdex_perf_zone] = bucket_str if bucket_str
725
721
  end
@@ -728,8 +724,8 @@ module NewRelic
728
724
  return unless is_synthetics_request?
729
725
 
730
726
  payload[:synthetics_resource_id] = synthetics_resource_id
731
- payload[:synthetics_job_id] = synthetics_job_id
732
- payload[:synthetics_monitor_id] = synthetics_monitor_id
727
+ payload[:synthetics_job_id] = synthetics_job_id
728
+ payload[:synthetics_monitor_id] = synthetics_monitor_id
733
729
  end
734
730
 
735
731
  def merge_metrics
@@ -739,30 +735,39 @@ module NewRelic
739
735
  def record_exceptions
740
736
  error_recorded = false
741
737
  @exceptions.each do |exception, options|
742
- options[:uri] ||= request_path if request_path
743
- options[:port] = request_port if request_port
744
- options[:metric] = best_name
738
+ options[:uri] ||= request_path if request_path
739
+ options[:port] = request_port if request_port
740
+ options[:metric] = best_name
745
741
  options[:attributes] = @attributes
746
742
 
747
- error_recorded = !!agent.error_collector.notice_error(exception, options) || error_recorded
743
+ span_id = options.delete(:span_id)
744
+ error_recorded = !!agent.error_collector.notice_error(exception, options, span_id) || error_recorded
748
745
  end
749
746
  payload[:error] = error_recorded if payload
750
747
  end
751
748
 
752
749
  # Do not call this. Invoke the class method instead.
753
- def notice_error(error, options={}) # :nodoc:
750
+ def notice_error(error, options = {}) # :nodoc:
751
+ # Only the last error is kept
752
+ if current_segment
753
+ current_segment.notice_error(error, expected: options[:expected])
754
+ options[:span_id] = current_segment.guid
755
+ end
756
+
754
757
  if @exceptions[error]
755
- @exceptions[error].merge! options
758
+ @exceptions[error].merge!(options)
756
759
  else
757
760
  @exceptions[error] = options
758
761
  end
759
762
  end
760
763
 
761
764
  def record_transaction_event
762
- agent.transaction_event_recorder.record payload
765
+ agent.transaction_event_recorder.record(payload)
763
766
  end
764
767
 
765
- QUEUE_TIME_METRIC = 'WebFrontend/QueueTime'.freeze
768
+ def record_log_events
769
+ agent.log_event_aggregator.record_batch(self, @logs.to_a)
770
+ end
766
771
 
767
772
  def queue_time
768
773
  @apdex_start ? @start_time - @apdex_start : 0
@@ -779,17 +784,9 @@ module NewRelic
779
784
  end
780
785
  end
781
786
 
782
- APDEX_ALL_METRIC = 'ApdexAll'.freeze
783
-
784
- APDEX_METRIC = 'Apdex'.freeze
785
- APDEX_OTHER_METRIC = 'ApdexOther'.freeze
786
-
787
- APDEX_TXN_METRIC_PREFIX = 'Apdex/'.freeze
788
- APDEX_OTHER_TXN_METRIC_PREFIX = 'ApdexOther/Transaction/'.freeze
789
-
790
787
  def had_error_affecting_apdex?
791
788
  @exceptions.each do |exception, options|
792
- ignored = NewRelic::Agent.instance.error_collector.error_is_ignored?(exception)
789
+ ignored = NewRelic::Agent.instance.error_collector.error_is_ignored?(exception)
793
790
  expected = options[:expected]
794
791
 
795
792
  return true unless ignored || expected
@@ -809,8 +806,8 @@ module NewRelic
809
806
  record_apdex_metrics(APDEX_METRIC, APDEX_TXN_METRIC_PREFIX, apdex_t)
810
807
  else
811
808
  record_apdex_metrics(APDEX_OTHER_METRIC,
812
- APDEX_OTHER_TXN_METRIC_PREFIX,
813
- transaction_specific_apdex_t)
809
+ APDEX_OTHER_TXN_METRIC_PREFIX,
810
+ transaction_specific_apdex_t)
814
811
  end
815
812
  end
816
813
  end
@@ -818,9 +815,9 @@ module NewRelic
818
815
  def record_apdex_metrics(rollup_metric, transaction_prefix, current_apdex_t)
819
816
  return unless current_apdex_t
820
817
 
821
- total_duration = end_time - apdex_start
818
+ total_duration = end_time - apdex_start
822
819
  apdex_bucket_global = apdex_bucket(total_duration, current_apdex_t)
823
- apdex_bucket_txn = apdex_bucket(duration, current_apdex_t)
820
+ apdex_bucket_txn = apdex_bucket(duration, current_apdex_t)
824
821
 
825
822
  @metrics.record_unscoped(rollup_metric, apdex_bucket_global, current_apdex_t)
826
823
  @metrics.record_unscoped(APDEX_ALL_METRIC, apdex_bucket_global, current_apdex_t)
@@ -838,7 +835,7 @@ module NewRelic
838
835
  end
839
836
 
840
837
  def threshold
841
- source_class = Agent.config.source(:'transaction_tracer.transaction_threshold').class
838
+ source_class = Agent.config.source(:'transaction_tracer.transaction_threshold').class
842
839
  if source_class == Configuration::DefaultSource
843
840
  apdex_t * 4
844
841
  else
@@ -846,7 +843,7 @@ module NewRelic
846
843
  end
847
844
  end
848
845
 
849
- def with_database_metric_name(model, method, product=nil)
846
+ def with_database_metric_name(model, method, product = nil)
850
847
  previous = self.instrumentation_state[:datastore_override]
851
848
  model_name = case model
852
849
  when Class
@@ -855,7 +852,7 @@ module NewRelic
855
852
  model
856
853
  else
857
854
  model.to_s
858
- end
855
+ end
859
856
  self.instrumentation_state[:datastore_override] = [method, model_name, product]
860
857
  yield
861
858
  ensure
@@ -866,6 +863,10 @@ module NewRelic
866
863
  attributes.merge_custom_attributes(p)
867
864
  end
868
865
 
866
+ def add_log_event(event)
867
+ logs.append(event: event)
868
+ end
869
+
869
870
  def recording_web_transaction?
870
871
  web_category?(@category)
871
872
  end
@@ -884,11 +885,13 @@ module NewRelic
884
885
 
885
886
  def normal_cpu_burn
886
887
  return unless @process_cpu_start
888
+
887
889
  process_cpu - @process_cpu_start
888
890
  end
889
891
 
890
892
  def jruby_cpu_burn
891
893
  return unless @jruby_cpu_start
894
+
892
895
  jruby_cpu_time - @jruby_cpu_start
893
896
  end
894
897
 
@@ -924,19 +927,21 @@ module NewRelic
924
927
 
925
928
  def process_cpu
926
929
  return nil if defined? JRuby
930
+
927
931
  p = Process.times
928
932
  p.stime + p.utime
929
933
  end
930
934
 
931
- JRUBY_CPU_TIME_ERROR = "Error calculating JRuby CPU Time".freeze
932
935
  def jruby_cpu_time
933
936
  return nil unless @@java_classes_loaded
937
+
934
938
  threadMBean = Java::JavaLangManagement::ManagementFactory.getThreadMXBean()
935
939
 
936
940
  return nil unless threadMBean.isCurrentThreadCpuTimeSupported
937
- java_utime = threadMBean.getCurrentThreadUserTime() # ns
938
941
 
939
- -1 == java_utime ? 0.0 : java_utime/1e9
942
+ java_utime = threadMBean.getCurrentThreadUserTime() # ns
943
+
944
+ -1 == java_utime ? 0.0 : java_utime / 1e9
940
945
  rescue => e
941
946
  ::NewRelic::Agent.logger.log_once(:warn, :jruby_cpu_time, JRUBY_CPU_TIME_ERROR, e)
942
947
  ::NewRelic::Agent.logger.debug(JRUBY_CPU_TIME_ERROR, e)
@@ -954,18 +959,6 @@ module NewRelic
954
959
  def sql_sampler
955
960
  agent.sql_sampler
956
961
  end
957
-
958
- HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
959
- GUID_LENGTH = 16
960
-
961
- # generate a random 64 bit uuid
962
- def generate_guid
963
- guid = ''
964
- GUID_LENGTH.times do |a|
965
- guid << HEX_DIGITS[rand(16)]
966
- end
967
- guid
968
- end
969
962
  end
970
963
  end
971
964
  end