newrelic_rpm 3.6.6.147 → 3.6.7.152

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +0 -1
  3. data/CHANGELOG +55 -17
  4. data/Guardfile +7 -0
  5. data/Rakefile +6 -0
  6. data/bin/mongrel_rpm +33 -0
  7. data/bin/newrelic +13 -0
  8. data/bin/newrelic_cmd +5 -0
  9. data/bin/nrdebug +273 -0
  10. data/install.rb +3 -3
  11. data/lib/new_relic/agent.rb +4 -6
  12. data/lib/new_relic/agent/agent.rb +76 -72
  13. data/lib/new_relic/agent/autostart.rb +18 -5
  14. data/lib/new_relic/agent/browser_monitoring.rb +41 -35
  15. data/lib/new_relic/agent/browser_token.rb +38 -0
  16. data/lib/new_relic/agent/busy_calculator.rb +7 -5
  17. data/lib/new_relic/agent/commands/agent_command.rb +19 -0
  18. data/lib/new_relic/agent/commands/agent_command_router.rb +88 -0
  19. data/lib/new_relic/agent/commands/thread_profiler.rb +80 -0
  20. data/lib/new_relic/agent/configuration/default_source.rb +700 -0
  21. data/lib/new_relic/agent/configuration/environment_source.rb +83 -30
  22. data/lib/new_relic/agent/configuration/manager.rb +8 -8
  23. data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
  24. data/lib/new_relic/agent/cross_app_monitor.rb +10 -21
  25. data/lib/new_relic/agent/cross_app_tracing.rb +3 -3
  26. data/lib/new_relic/agent/error_collector.rb +7 -10
  27. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -1
  28. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +5 -1
  29. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +5 -1
  30. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
  31. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -12
  33. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -0
  34. data/lib/new_relic/agent/instrumentation/{rails4/active_record.rb → active_record_4.rb} +1 -1
  35. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -11
  36. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -6
  37. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +12 -6
  38. data/lib/new_relic/agent/instrumentation/curb.rb +11 -2
  39. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -3
  40. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +11 -2
  41. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +13 -4
  42. data/lib/new_relic/agent/instrumentation/puma.rb +2 -1
  43. data/lib/new_relic/agent/instrumentation/rack.rb +15 -17
  44. data/lib/new_relic/agent/method_tracer.rb +181 -191
  45. data/lib/new_relic/agent/new_relic_service.rb +16 -14
  46. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  47. data/lib/new_relic/agent/request_sampler.rb +32 -165
  48. data/lib/new_relic/agent/sampled_buffer.rb +79 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -8
  50. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  51. data/lib/new_relic/agent/stats_engine.rb +1 -1
  52. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  53. data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -3
  54. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -22
  55. data/lib/new_relic/agent/threading/agent_thread.rb +41 -0
  56. data/lib/new_relic/agent/threading/backtrace_node.rb +71 -0
  57. data/lib/new_relic/agent/threading/thread_profile.rb +172 -0
  58. data/lib/new_relic/agent/transaction.rb +16 -4
  59. data/lib/new_relic/agent/transaction_sample_builder.rb +13 -3
  60. data/lib/new_relic/agent/transaction_sampler.rb +5 -8
  61. data/lib/new_relic/agent/transaction_state.rb +166 -0
  62. data/lib/new_relic/agent/transaction_timings.rb +53 -0
  63. data/lib/new_relic/cli/command.rb +91 -0
  64. data/lib/new_relic/{commands → cli}/deployments.rb +13 -9
  65. data/lib/new_relic/{commands → cli}/install.rb +2 -2
  66. data/lib/new_relic/control/frameworks/rails.rb +1 -8
  67. data/lib/new_relic/control/instance_methods.rb +1 -2
  68. data/lib/new_relic/helper.rb +9 -0
  69. data/lib/new_relic/local_environment.rb +16 -63
  70. data/lib/new_relic/rack/browser_monitoring.rb +8 -5
  71. data/lib/new_relic/recipes.rb +44 -31
  72. data/lib/new_relic/transaction_sample.rb +6 -2
  73. data/lib/new_relic/version.rb +1 -1
  74. data/lib/tasks/install.rake +21 -1
  75. data/newrelic_rpm.gemspec +5 -1
  76. data/test/agent_helper.rb +4 -9
  77. data/test/environments/.gitignore +16 -0
  78. data/test/environments/lib/environments/runner.rb +104 -0
  79. data/test/environments/norails/Gemfile +11 -0
  80. data/test/environments/norails/Rakefile +9 -0
  81. data/test/environments/rails21/Gemfile +24 -0
  82. data/test/environments/rails21/Rakefile +12 -0
  83. data/test/environments/rails21/app/controllers/application.rb +20 -0
  84. data/test/environments/rails21/config/boot.rb +113 -0
  85. data/test/environments/rails21/config/database.yml +31 -0
  86. data/test/environments/rails21/config/environment.rb +28 -0
  87. data/test/environments/rails21/config/environments/development.rb +16 -0
  88. data/test/environments/rails21/config/environments/production.rb +8 -0
  89. data/test/environments/rails21/config/environments/test.rb +10 -0
  90. data/test/environments/rails21/config/routes.rb +5 -0
  91. data/test/environments/rails21/db/schema.rb +5 -0
  92. data/test/environments/rails22/Gemfile +29 -0
  93. data/test/environments/rails22/Rakefile +12 -0
  94. data/test/environments/rails22/app/controllers/application.rb +20 -0
  95. data/test/environments/rails22/config/boot.rb +113 -0
  96. data/test/environments/rails22/config/database.yml +31 -0
  97. data/test/environments/rails22/config/environment.rb +27 -0
  98. data/test/environments/rails22/config/environments/development.rb +16 -0
  99. data/test/environments/rails22/config/environments/production.rb +8 -0
  100. data/test/environments/rails22/config/environments/test.rb +10 -0
  101. data/test/environments/rails22/config/routes.rb +5 -0
  102. data/test/environments/rails22/db/schema.rb +5 -0
  103. data/test/environments/rails23/Gemfile +22 -0
  104. data/test/environments/rails23/Rakefile +12 -0
  105. data/test/environments/rails23/app/controllers/application.rb +20 -0
  106. data/test/environments/rails23/config/boot.rb +127 -0
  107. data/test/environments/rails23/config/database.yml +31 -0
  108. data/test/environments/rails23/config/environment.rb +25 -0
  109. data/test/environments/rails23/config/environments/development.rb +16 -0
  110. data/test/environments/rails23/config/environments/production.rb +8 -0
  111. data/test/environments/rails23/config/environments/test.rb +10 -0
  112. data/test/environments/rails23/config/preinitializer.rb +25 -0
  113. data/test/environments/rails23/config/routes.rb +5 -0
  114. data/test/environments/rails23/db/schema.rb +5 -0
  115. data/test/environments/rails30/Gemfile +19 -0
  116. data/test/environments/rails30/Rakefile +9 -0
  117. data/test/environments/rails30/config/application.rb +17 -0
  118. data/test/environments/rails30/config/boot.rb +10 -0
  119. data/test/environments/rails30/config/database.yml +31 -0
  120. data/test/environments/rails30/config/environment.rb +6 -0
  121. data/test/environments/rails30/config/initializers/new_rails_defaults.rb +11 -0
  122. data/test/environments/rails30/db/schema.rb +5 -0
  123. data/test/environments/rails31/Gemfile +19 -0
  124. data/test/environments/rails31/Rakefile +9 -0
  125. data/test/environments/rails31/config/application.rb +18 -0
  126. data/test/environments/rails31/config/boot.rb +10 -0
  127. data/test/environments/rails31/config/database.yml +31 -0
  128. data/test/environments/rails31/config/environment.rb +6 -0
  129. data/test/environments/rails31/config/initializers/new_rails_defaults.rb +21 -0
  130. data/test/environments/rails31/db/schema.rb +5 -0
  131. data/test/environments/rails32/Gemfile +25 -0
  132. data/test/environments/rails32/Rakefile +9 -0
  133. data/test/environments/rails32/config/application.rb +19 -0
  134. data/test/environments/rails32/config/boot.rb +10 -0
  135. data/test/environments/rails32/config/database.yml +31 -0
  136. data/test/environments/rails32/config/environment.rb +6 -0
  137. data/test/environments/rails32/db/schema.rb +5 -0
  138. data/test/environments/rails40/Gemfile +25 -0
  139. data/test/environments/rails40/Rakefile +9 -0
  140. data/test/environments/rails40/config/application.rb +18 -0
  141. data/test/environments/rails40/config/boot.rb +10 -0
  142. data/test/environments/rails40/config/database.yml +31 -0
  143. data/test/environments/rails40/config/environment.rb +6 -0
  144. data/test/environments/rails40/db/schema.rb +5 -0
  145. data/test/multiverse/lib/multiverse/suite.rb +24 -12
  146. data/test/multiverse/suites/agent_only/logging_test.rb +18 -1
  147. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +1 -8
  148. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +10 -7
  149. data/test/multiverse/suites/curb/curb_test.rb +17 -3
  150. data/test/multiverse/suites/excon/Envfile +1 -1
  151. data/test/multiverse/suites/excon/excon_test.rb +18 -2
  152. data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
  153. data/test/multiverse/suites/net_http/net_http_test.rb +2 -2
  154. data/test/multiverse/suites/rails/error_tracing_test.rb +35 -8
  155. data/test/multiverse/suites/rails/ignore_test.rb +48 -0
  156. data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +44 -0
  157. data/test/multiverse/suites/sequel/sequel_test.rb +11 -0
  158. data/test/multiverse/suites/sinatra/ignoring_test.rb +2 -2
  159. data/test/multiverse/suites/typhoeus/Envfile +9 -2
  160. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +3 -2
  161. data/test/new_relic/agent/agent/start_test.rb +3 -22
  162. data/test/new_relic/agent/agent_test.rb +6 -5
  163. data/test/new_relic/agent/autostart_test.rb +39 -1
  164. data/test/new_relic/agent/browser_monitoring_test.rb +43 -88
  165. data/test/new_relic/agent/browser_token_test.rb +52 -0
  166. data/test/new_relic/agent/busy_calculator_test.rb +1 -1
  167. data/test/new_relic/agent/commands/agent_command_router_test.rb +98 -0
  168. data/test/new_relic/agent/commands/agent_command_test.rb +37 -0
  169. data/test/new_relic/agent/commands/thread_profiler_test.rb +177 -0
  170. data/test/new_relic/agent/configuration/default_source_test.rb +81 -0
  171. data/test/new_relic/agent/configuration/environment_source_test.rb +81 -7
  172. data/test/new_relic/agent/configuration/manager_test.rb +16 -1
  173. data/test/new_relic/agent/cross_app_monitor_test.rb +3 -5
  174. data/test/new_relic/agent/error_collector_test.rb +14 -0
  175. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
  176. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +2 -3
  177. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +29 -31
  178. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +22 -0
  179. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +2 -2
  180. data/test/new_relic/agent/method_tracer_test.rb +2 -2
  181. data/test/new_relic/agent/new_relic_service_test.rb +5 -49
  182. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -0
  183. data/test/new_relic/agent/request_sampler_test.rb +32 -95
  184. data/test/new_relic/agent/rpm_agent_test.rb +7 -5
  185. data/test/new_relic/agent/sampled_buffer_test.rb +178 -0
  186. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +0 -1
  187. data/test/new_relic/agent/stats_engine_test.rb +10 -17
  188. data/test/new_relic/agent/threading/agent_thread_test.rb +107 -0
  189. data/test/new_relic/agent/threading/backtrace_node_test.rb +96 -0
  190. data/test/new_relic/agent/{threaded_test.rb → threading/fake_thread.rb} +0 -25
  191. data/test/new_relic/agent/threading/thread_profile_test.rb +308 -0
  192. data/test/new_relic/agent/threading/threaded_test_case.rb +33 -0
  193. data/test/new_relic/agent/transaction/pop_test.rb +0 -16
  194. data/test/new_relic/agent/transaction_sample_builder_test.rb +23 -4
  195. data/test/new_relic/agent/transaction_sampler_test.rb +14 -15
  196. data/test/new_relic/agent/transaction_state_test.rb +75 -0
  197. data/test/new_relic/agent/transaction_test.rb +15 -0
  198. data/test/new_relic/agent/transaction_timings_test.rb +81 -0
  199. data/test/new_relic/agent_test.rb +12 -14
  200. data/test/new_relic/{command → cli}/deployments_test.rb +41 -13
  201. data/test/new_relic/control/frameworks/rails_test.rb +1 -2
  202. data/test/new_relic/control_test.rb +1 -2
  203. data/test/new_relic/dependency_detection_test.rb +14 -0
  204. data/test/new_relic/fake_collector.rb +1 -0
  205. data/test/new_relic/helper_test.rb +7 -2
  206. data/test/new_relic/http_client_test_cases.rb +33 -1
  207. data/test/new_relic/local_environment_test.rb +0 -23
  208. data/test/new_relic/metric_data_test.rb +4 -0
  209. data/test/new_relic/rack/browser_monitoring_test.rb +31 -30
  210. data/test/performance/lib/performance/result.rb +15 -4
  211. data/test/performance/lib/performance/timer.rb +7 -1
  212. data/test/performance/script/baselines +102 -0
  213. data/test/performance/suites/rum_autoinsertion.rb +57 -0
  214. data/test/rum/basic.result.html +10 -0
  215. data/test/rum/basic.source.html +10 -0
  216. data/test/rum/comments1.result.html +24 -0
  217. data/test/rum/comments1.source.html +24 -0
  218. data/test/rum/comments2.result.html +24 -0
  219. data/test/rum/comments2.source.html +24 -0
  220. data/test/rum/gt_in_quotes1.result.html +27 -0
  221. data/test/rum/gt_in_quotes1.source.html +27 -0
  222. data/test/rum/gt_in_quotes2.result.html +24 -0
  223. data/test/rum/gt_in_quotes2.source.html +24 -0
  224. data/test/rum/gt_in_quotes_mismatch.result.html +24 -0
  225. data/test/rum/gt_in_quotes_mismatch.source.html +24 -0
  226. data/test/rum/gt_in_single_quotes1.result.html +25 -0
  227. data/test/rum/gt_in_single_quotes1.source.html +25 -0
  228. data/test/rum/gt_in_single_quotes_mismatch.result.html +25 -0
  229. data/test/rum/gt_in_single_quotes_mismatch.source.html +25 -0
  230. data/test/rum/incomplete_non_meta_tags.result.html +10 -0
  231. data/test/rum/incomplete_non_meta_tags.source.html +10 -0
  232. data/test/rum/no_body.result.html +21 -0
  233. data/test/rum/no_body.source.html +21 -0
  234. data/test/rum/no_header.result.html +7 -0
  235. data/test/rum/no_header.source.html +7 -0
  236. data/test/rum/no_start_header.result.html +9 -0
  237. data/test/rum/no_start_header.source.html +9 -0
  238. data/test/rum/script1.result.html +19 -0
  239. data/test/rum/script1.source.html +19 -0
  240. data/test/rum/script2.result.html +17 -0
  241. data/test/rum/script2.source.html +17 -0
  242. data/test/rum/x_ua_meta_tag.result.html +10 -0
  243. data/test/rum/x_ua_meta_tag.source.html +10 -0
  244. data/test/rum/x_ua_meta_tag_multiline.result.html +11 -0
  245. data/test/rum/x_ua_meta_tag_multiline.source.html +11 -0
  246. data/test/rum/x_ua_meta_tag_with_others.result.html +11 -0
  247. data/test/rum/x_ua_meta_tag_with_others.source.html +11 -0
  248. data/test/rum/x_ua_meta_tag_with_spaces.result.html +10 -0
  249. data/test/rum/x_ua_meta_tag_with_spaces.source.html +10 -0
  250. data/test/script/ci.sh +1 -12
  251. data/test/test_helper.rb +1 -0
  252. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +11 -0
  253. metadata +225 -32
  254. metadata.gz.sig +0 -0
  255. data/lib/new_relic/agent/configuration/defaults.rb +0 -157
  256. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +0 -56
  257. data/lib/new_relic/agent/thread.rb +0 -37
  258. data/lib/new_relic/agent/thread_profiler.rb +0 -323
  259. data/lib/new_relic/agent/transaction_info.rb +0 -114
  260. data/lib/new_relic/command.rb +0 -89
  261. data/test/new_relic/agent/agent_test_controller_test.rb +0 -348
  262. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +0 -70
  263. data/test/new_relic/agent/thread_profiler_test.rb +0 -586
  264. data/test/new_relic/agent/thread_test.rb +0 -93
  265. data/test/new_relic/agent/transaction_info_test.rb +0 -99
@@ -18,7 +18,7 @@ module NewRelic
18
18
 
19
19
  def initialize
20
20
  # Makes the unit tests happy
21
- Thread::current[:newrelic_scope_stack] = nil
21
+ NewRelic::Agent::TransactionState.get.clear_stats_scope_stack
22
22
  @stats_lock = Mutex.new
23
23
  @stats_hash = StatsHash.new
24
24
  end
@@ -57,7 +57,7 @@ module NewRelic
57
57
  end
58
58
 
59
59
  def scope_stack
60
- Thread::current[:newrelic_scope_stack] ||= []
60
+ NewRelic::Agent::TransactionState.get.stats_scope_stack
61
61
  end
62
62
  end
63
63
 
@@ -59,10 +59,9 @@ module NewRelic
59
59
  get_stats(metric_name, false)
60
60
  end
61
61
 
62
- # If use_scope is true, two chained metrics are created, one with scope and one without
63
62
  # If scoped_metric_only is true, only a scoped metric is created (used by rendering metrics which by definition are per controller only)
64
- def get_stats(metric_name, use_scope = true, scoped_metric_only = false, scope = nil)
65
- scope ||= scope_name if use_scope
63
+ # Leaving second, unused parameter for compatibility
64
+ def get_stats(metric_name, _ = true, scoped_metric_only = false, scope = nil)
66
65
  stats = nil
67
66
  with_stats_lock do
68
67
  if scoped_metric_only
@@ -29,8 +29,6 @@ module Agent
29
29
  def end_transaction; end
30
30
  def push_scope(*args); end
31
31
  def transaction_sampler=(*args); end
32
- def scope_name=(*args); end
33
- def scope_name; end
34
32
  def pop_scope(*args); end
35
33
  end
36
34
 
@@ -85,23 +83,6 @@ module Agent
85
83
  NewRelic::Agent.logger.warn("NewRelic::Agent::StatsEngine#transaction_sampler is deprecated")
86
84
  end
87
85
 
88
- # set the name of the transaction for the current thread, which will be used
89
- # to define the scope of all traced methods called on this thread until the
90
- # scope stack is empty.
91
- #
92
- # currently the transaction name is the name of the controller action that
93
- # is invoked via the dispatcher, but conceivably we could use other transaction
94
- # names in the future if the traced application does more than service http request
95
- # via controller actions
96
- def scope_name=(transaction)
97
- Thread::current[:newrelic_scope_name] = transaction
98
- end
99
-
100
- # Returns the current scope name from the thread local
101
- def scope_name
102
- Thread::current[:newrelic_scope_name]
103
- end
104
-
105
86
  # Start a new transaction, unless one is already in progress
106
87
  def start_transaction
107
88
  NewRelic::Agent.instance.events.notify(:start_transaction)
@@ -115,8 +96,7 @@ module Agent
115
96
  stack = scope_stack
116
97
 
117
98
  if stack && stack.empty?
118
- Thread::current[:newrelic_scope_stack] = nil
119
- Thread::current[:newrelic_scope_name] = nil
99
+ NewRelic::Agent::TransactionState.get.clear_stats_scope_stack
120
100
  end
121
101
  end
122
102
 
@@ -126,7 +106,7 @@ module Agent
126
106
 
127
107
  # Returns the current scope stack, memoized to a thread local variable
128
108
  def scope_stack
129
- Thread::current[:newrelic_scope_stack] ||= []
109
+ NewRelic::Agent::TransactionState.get.stats_scope_stack
130
110
  end
131
111
  end
132
112
  end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ module NewRelic
6
+ module Agent
7
+ module Threading
8
+
9
+ class AgentThread < ::Thread
10
+ def initialize(label)
11
+ ::NewRelic::Agent.logger.debug("Creating New Relic thread: #{label}")
12
+ self[:newrelic_label] = label
13
+ super
14
+ end
15
+
16
+ def self.bucket_thread(thread, profile_agent_code)
17
+ if thread.key?(:newrelic_label)
18
+ profile_agent_code ? :agent : :ignore
19
+ elsif TransactionState.in_background_transaction?(thread)
20
+ :background
21
+ elsif TransactionState.in_request_transaction?(thread)
22
+ :request
23
+ else
24
+ :other
25
+ end
26
+ end
27
+
28
+ def self.scrub_backtrace(thread, profile_agent_code)
29
+ begin
30
+ bt = thread.backtrace
31
+ rescue Exception => e
32
+ ::NewRelic::Agent.logger.debug("Failed to backtrace #{thread.inspect}: #{e.class.name}: #{e.to_s}")
33
+ end
34
+ return nil unless bt
35
+ profile_agent_code ? bt : bt.select { |t| t !~ /\/newrelic_rpm-\d/ }
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ module NewRelic
6
+ module Agent
7
+ module Threading
8
+
9
+ class BacktraceNode
10
+ attr_reader :file, :method, :line_no, :children
11
+ attr_accessor :runnable_count, :to_prune, :depth
12
+
13
+ def initialize(line, parent=nil)
14
+ line =~ /(.*)\:(\d+)\:in `(.*)'/
15
+ @file = $1
16
+ @method = $3
17
+ @line_no = $2.to_i
18
+ @children = []
19
+ @runnable_count = 0
20
+ @to_prune = false
21
+ @depth = 0
22
+
23
+ parent.add_child(self) if parent
24
+ end
25
+
26
+ def ==(other)
27
+ @file == other.file &&
28
+ @method == other.method &&
29
+ @line_no == other.line_no
30
+ end
31
+
32
+ def total_count
33
+ @runnable_count
34
+ end
35
+
36
+ # Descending order on count, ascending on depth of nodes
37
+ def order_for_pruning(y)
38
+ [-runnable_count, depth] <=> [-y.runnable_count, y.depth]
39
+ end
40
+
41
+ include NewRelic::Coerce
42
+
43
+ def to_array
44
+ [[
45
+ string(@file),
46
+ string(@method),
47
+ int(@line_no)
48
+ ],
49
+ int(@runnable_count),
50
+ 0,
51
+ @children.map {|c| c.to_array}]
52
+ end
53
+
54
+ def add_child(child)
55
+ child.depth = @depth + 1
56
+ @children << child unless @children.include? child
57
+ end
58
+
59
+ def prune!
60
+ BacktraceNode.prune!(@children)
61
+ end
62
+
63
+ def self.prune!(kids)
64
+ kids.delete_if { |child| child.to_prune }
65
+ kids.each { |child| child.prune! }
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,172 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require 'new_relic/agent/worker_loop'
6
+ require 'new_relic/agent/threading/backtrace_node'
7
+
8
+ # Intent is for this to be a data structure for representing a thread profile
9
+ # TODO: Get rid of the running/sampling in this class, externalize it elsewhere
10
+
11
+ module NewRelic
12
+ module Agent
13
+ module Threading
14
+
15
+ class ThreadProfile
16
+
17
+ attr_reader :profile_id,
18
+ :traces,
19
+ :profile_agent_code,
20
+ :interval, :duration,
21
+ :poll_count, :sample_count,
22
+ :start_time, :stop_time
23
+
24
+ def initialize(agent_command)
25
+ arguments = agent_command.arguments
26
+ @profile_id = arguments.fetch('profile_id', -1)
27
+ @profile_agent_code = arguments.fetch('profile_agent_code', true)
28
+
29
+ @duration = arguments.fetch('duration', 120)
30
+ @worker_loop = NewRelic::Agent::WorkerLoop.new(:duration => duration)
31
+ @interval = arguments.fetch('sample_period', 0.1)
32
+ @finished = false
33
+
34
+ @traces = {
35
+ :agent => [],
36
+ :background => [],
37
+ :other => [],
38
+ :request => []
39
+ }
40
+ @flattened_nodes = []
41
+
42
+ @poll_count = 0
43
+ @sample_count = 0
44
+ @failure_count = 0
45
+ end
46
+
47
+ def run
48
+ NewRelic::Agent.logger.debug("Starting thread profile. profile_id=#{profile_id}, duration=#{duration}")
49
+
50
+ Threading::AgentThread.new('Thread Profiler') do
51
+ @start_time = now_in_millis
52
+
53
+ @worker_loop.run(@interval) do
54
+ NewRelic::Agent.instance.stats_engine.
55
+ record_supportability_metric_timed("ThreadProfiler/PollingTime") do
56
+
57
+ @poll_count += 1
58
+ Threading::AgentThread.list.each do |t|
59
+ bucket = Threading::AgentThread.bucket_thread(t, @profile_agent_code)
60
+ if bucket != :ignore
61
+ backtrace = Threading::AgentThread.scrub_backtrace(t, @profile_agent_code)
62
+ if backtrace.nil?
63
+ @failure_count += 1
64
+ else
65
+ @sample_count += 1
66
+ aggregate(backtrace, @traces[bucket])
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ mark_done
74
+ NewRelic::Agent.logger.debug("Finished thread profile. #{@sample_count} backtraces, #{@failure_count} failures. Will send with next harvest.")
75
+ NewRelic::Agent.instance.stats_engine.
76
+ record_supportability_metric_count("ThreadProfiler/BacktraceFailures", @failure_count)
77
+ end
78
+ end
79
+
80
+ def stop
81
+ @worker_loop.stop
82
+ mark_done
83
+ NewRelic::Agent.logger.debug("Stopping thread profile.")
84
+ end
85
+
86
+ def aggregate(trace, trees=@traces[:request], parent=nil)
87
+ return nil if trace.nil? || trace.empty?
88
+ node = Threading::BacktraceNode.new(trace.last)
89
+ existing = trees.find {|n| n == node}
90
+
91
+ if existing.nil?
92
+ existing = node
93
+ @flattened_nodes << node
94
+ end
95
+
96
+ if parent
97
+ parent.add_child(node)
98
+ else
99
+ trees << node unless trees.include? node
100
+ end
101
+
102
+ existing.runnable_count += 1
103
+ aggregate(trace[0..-2], existing.children, existing)
104
+
105
+ existing
106
+ end
107
+
108
+ def prune!(count_to_keep)
109
+ @flattened_nodes.sort!(&:order_for_pruning)
110
+
111
+ NewRelic::Agent.instance.stats_engine.
112
+ record_supportability_metric_count("ThreadProfiler/NodeCount", @flattened_nodes.size)
113
+
114
+ mark_for_pruning(@flattened_nodes, count_to_keep)
115
+
116
+ traces.each { |_, nodes| Threading::BacktraceNode.prune!(nodes) }
117
+ end
118
+
119
+ THREAD_PROFILER_NODES = 20_000
120
+
121
+ include NewRelic::Coerce
122
+
123
+ def to_collector_array(encoder)
124
+ prune!(THREAD_PROFILER_NODES)
125
+
126
+ traces = {
127
+ "OTHER" => @traces[:other].map{|t| t.to_array },
128
+ "REQUEST" => @traces[:request].map{|t| t.to_array },
129
+ "AGENT" => @traces[:agent].map{|t| t.to_array },
130
+ "BACKGROUND" => @traces[:background].map{|t| t.to_array }
131
+ }
132
+
133
+ [[
134
+ int(@profile_id),
135
+ float(@start_time),
136
+ float(@stop_time),
137
+ int(@poll_count),
138
+ string(encoder.encode(traces)),
139
+ int(@sample_count),
140
+ 0
141
+ ]]
142
+ end
143
+
144
+ def now_in_millis
145
+ Time.now.to_f * 1_000
146
+ end
147
+
148
+ def finished?
149
+ @finished
150
+ end
151
+
152
+ def mark_done
153
+ @finished = true
154
+ @stop_time = now_in_millis
155
+ end
156
+
157
+ def mark_for_pruning(nodes, count_to_keep)
158
+ to_prune = nodes[count_to_keep..-1] || []
159
+ to_prune.each { |n| n.to_prune = true }
160
+ end
161
+
162
+ def self.parse_backtrace(trace)
163
+ trace.map do |line|
164
+ line =~ /(.*)\:(\d+)\:in `(.*)'/
165
+ { :method => $3, :line_no => $2.to_i, :file => $1 }
166
+ end
167
+ end
168
+
169
+ end
170
+ end
171
+ end
172
+ end
@@ -3,6 +3,7 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require 'new_relic/agent/transaction/pop'
6
+ require 'new_relic/agent/transaction_timings'
6
7
 
7
8
  # A struct holding the information required to measure a controller
8
9
  # action. This is put on the thread local. Handles the issue of
@@ -30,7 +31,6 @@ module NewRelic
30
31
  # as a Rack::Request or an ActionController::AbstractRequest.
31
32
  attr_accessor :request
32
33
 
33
-
34
34
  # Return the currently active transaction, or nil.
35
35
  def self.current
36
36
  self.stack.last
@@ -54,7 +54,7 @@ module NewRelic
54
54
  end
55
55
 
56
56
  def self.stack
57
- Thread.current[:newrelic_transaction] ||= []
57
+ TransactionState.get.current_transaction_stack
58
58
  end
59
59
 
60
60
  def self.in_transaction?
@@ -104,7 +104,11 @@ module NewRelic
104
104
  @request = options[:request]
105
105
  @exceptions = {}
106
106
  @stats_hash = StatsHash.new
107
- TransactionInfo.get.transaction = self
107
+ TransactionState.get.transaction = self
108
+ end
109
+
110
+ def noticed_error_ids
111
+ @noticed_error_ids ||= []
108
112
  end
109
113
 
110
114
  def name=(name)
@@ -290,7 +294,6 @@ module NewRelic
290
294
  return unless recording_web_transaction? && NewRelic::Agent.is_execution_traced?
291
295
 
292
296
  freeze_name
293
- apdex_t = TransactionInfo.get.apdex_t
294
297
  action_duration = end_time - start_time
295
298
  total_duration = end_time - apdex_start
296
299
  is_error = is_error.nil? ? !exceptions.empty? : is_error
@@ -303,6 +306,15 @@ module NewRelic
303
306
  @stats_hash.record(txn_apdex_metric, apdex_bucket_txn, apdex_t)
304
307
  end
305
308
 
309
+ def apdex_t
310
+ transaction_specific_apdex_t || Agent.config[:apdex_t]
311
+ end
312
+
313
+ def transaction_specific_apdex_t
314
+ key = :web_transactions_apdex
315
+ Agent.config[key] && Agent.config[key][self.name]
316
+ end
317
+
306
318
  # Yield to a block that is run with a database metric name context. This means
307
319
  # the Database instrumentation will use this for the metric name if it does not
308
320
  # otherwise know about a model. This is re-entrant.
@@ -110,13 +110,23 @@ module NewRelic
110
110
  @sample.params[:custom_params] ||= {}
111
111
  @sample.params[:custom_params].merge!(normalize_params(custom_params))
112
112
 
113
- txn_info = NewRelic::Agent::TransactionInfo.get
114
- @sample.force_persist = txn_info.force_persist_sample?(sample)
115
- @sample.threshold = txn_info.transaction_trace_threshold
113
+ @sample.force_persist = sample.force_persist_sample?
114
+ @sample.threshold = transaction_trace_threshold
116
115
  @sample.freeze
117
116
  @current_segment = nil
118
117
  end
119
118
 
119
+ TT_THRESHOLD_KEY = :'transaction_tracer.transaction_threshold'
120
+
121
+ def transaction_trace_threshold
122
+ source_class = Agent.config.source(TT_THRESHOLD_KEY).class
123
+ if source_class == Configuration::DefaultSource && TransactionState.get.transaction
124
+ TransactionState.get.transaction.apdex_t * 4
125
+ else
126
+ Agent.config[TT_THRESHOLD_KEY]
127
+ end
128
+ end
129
+
120
130
  def scope_depth
121
131
  depth = -1 # have to account for the root
122
132
  current = @current_segment