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
@@ -6,43 +6,44 @@ module NewRelic
6
6
  module Agent
7
7
  module Configuration
8
8
  class EnvironmentSource < DottedHash
9
+ SUPPORTED_PREFIXES = /^new_relic_|newrelic_/i
10
+
11
+ attr_accessor :alias_map, :type_map
12
+
9
13
  def initialize
10
- string_map = {
11
- 'NRCONFIG' => :config_path,
12
- 'NEW_RELIC_LICENSE_KEY' => :license_key,
13
- 'NEWRELIC_LICENSE_KEY' => :license_key,
14
- 'NEW_RELIC_APP_NAME' => :app_name,
15
- 'NEWRELIC_APP_NAME' => :app_name,
16
- 'NEW_RELIC_HOST' => :host,
17
- 'NEW_RELIC_PORT' => :port
18
- }.each do |key, val|
19
- self[val] = ENV[key] if ENV[key]
14
+ set_log_file
15
+ set_config_file
16
+
17
+ @alias_map = {}
18
+ @type_map = {}
19
+
20
+ DEFAULTS.each do |config_setting, value|
21
+ self.type_map[config_setting] = value[:type]
22
+ set_aliases(config_setting, value)
20
23
  end
21
24
 
22
- symbol_map = {
23
- 'NEW_RELIC_DISPATCHER' => :dispatcher,
24
- 'NEWRELIC_DISPATCHER' => :dispatcher,
25
- 'NEW_RELIC_FRAMEWORK' => :framework,
26
- 'NEWRELIC_FRAMEWORK' => :framework
27
- }.each do |key, val|
28
- self[val] = ENV[key].intern if ENV[key]
25
+ set_values_from_new_relic_environment_variables
26
+ end
27
+
28
+ def set_aliases(config_setting, value)
29
+ set_dotted_alias(config_setting)
30
+
31
+ return unless value[:aliases]
32
+ value[:aliases].each do |config_alias|
33
+ self.alias_map[config_alias] = config_setting
29
34
  end
35
+ end
30
36
 
31
- boolean_map = {
32
- 'NEWRELIC_ENABLE' => :agent_enabled,
33
- 'NEWRELIC_ENABLED' => :agent_enabled,
34
- 'NEW_RELIC_ENABLE' => :agent_enabled,
35
- 'NEW_RELIC_ENABLED' => :agent_enabled,
36
- 'NEWRELIC_DISABLE_HARVEST_THREAD' => :disable_harvest_thread,
37
- 'NEW_RELIC_DISABLE_HARVEST_THREAD' => :disable_harvest_thread
38
- }.each do |key, val|
39
- if ENV[key].to_s =~ /false|off|no/i
40
- self[val] = false
41
- elsif ENV[key] != nil
42
- self[val] = true
43
- end
37
+ def set_dotted_alias(original_config_setting)
38
+ config_setting = original_config_setting.to_s
39
+
40
+ if config_setting.include? '.'
41
+ config_alias = config_setting.gsub(/\./,'_').to_sym
42
+ self.alias_map[config_alias] = original_config_setting
44
43
  end
44
+ end
45
45
 
46
+ def set_log_file
46
47
  if ENV['NEW_RELIC_LOG']
47
48
  if ENV['NEW_RELIC_LOG'].upcase == 'STDOUT'
48
49
  self[:log_file_path] = self[:log_file_name] = 'STDOUT'
@@ -52,6 +53,58 @@ module NewRelic
52
53
  end
53
54
  end
54
55
  end
56
+
57
+ def set_config_file
58
+ self[:config_path] = ENV['NRCONFIG'] if ENV['NRCONFIG']
59
+ end
60
+
61
+ def set_values_from_new_relic_environment_variables
62
+ nr_env_var_keys = collect_new_relic_environment_variable_keys
63
+
64
+ nr_env_var_keys.each do |key|
65
+ set_value_from_environment_variable(key)
66
+ end
67
+ end
68
+
69
+ def set_value_from_environment_variable(key)
70
+ config_key = convert_environment_key_to_config_key(key)
71
+ set_key_by_type(config_key, key)
72
+ end
73
+
74
+ def set_key_by_type(config_key, environment_key)
75
+ value = ENV[environment_key]
76
+ type = self.type_map[config_key]
77
+
78
+ if type == String
79
+ self[config_key] = value
80
+ elsif type == Fixnum
81
+ self[config_key] = value.to_i
82
+ elsif type == Float
83
+ self[config_key] = value.to_f
84
+ elsif type == Symbol
85
+ self[config_key] = value.to_sym
86
+ elsif type == NewRelic::Agent::Configuration::Boolean
87
+ if value =~ /false|off|no/i
88
+ self[config_key] = false
89
+ elsif value != nil
90
+ self[config_key] = true
91
+ end
92
+ else
93
+ ::NewRelic::Agent.logger.info("#{environment_key} does not have a corresponding configuration setting (#{config_key} does not exist).")
94
+ ::NewRelic::Agent.logger.info("Run `rake newrelic:config:docs` or visit https://newrelic.com/docs/ruby/ruby-agent-configuration to see a list of available configuration settings.")
95
+ self[config_key] = value
96
+ end
97
+ end
98
+
99
+ def convert_environment_key_to_config_key(key)
100
+ stripped_key = key.gsub(SUPPORTED_PREFIXES, '').downcase.to_sym
101
+ self.alias_map[stripped_key] || stripped_key
102
+ end
103
+
104
+ def collect_new_relic_environment_variable_keys
105
+ ENV.keys.select { |key| key.match(SUPPORTED_PREFIXES) }
106
+ end
107
+
55
108
  end
56
109
  end
57
110
  end
@@ -3,9 +3,9 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require 'forwardable'
6
- require 'new_relic/agent/configuration/defaults'
7
6
  require 'new_relic/agent/configuration/mask_defaults'
8
7
  require 'new_relic/agent/configuration/yaml_source'
8
+ require 'new_relic/agent/configuration/default_source'
9
9
  require 'new_relic/agent/configuration/server_source'
10
10
  require 'new_relic/agent/configuration/environment_source'
11
11
 
@@ -14,7 +14,7 @@ module NewRelic
14
14
  module Configuration
15
15
  class Manager
16
16
  extend Forwardable
17
- def_delegators :@cache, :[], :has_key?
17
+ def_delegators :@cache, :[], :has_key?, :keys
18
18
  attr_reader :config_stack, :stripped_exceptions_whitelist
19
19
 
20
20
  def initialize
@@ -53,9 +53,9 @@ module NewRelic
53
53
  end
54
54
 
55
55
  def replace_or_add_config(source, level=0)
56
- idx = @config_stack.map{|s| s.class}.index(source.class)
57
- @config_stack.delete_at(idx) if idx
58
- apply_config(source, idx || level)
56
+ index = @config_stack.map{|s| s.class}.index(source.class)
57
+ @config_stack.delete_at(index) if index
58
+ apply_config(source, index || level)
59
59
  end
60
60
 
61
61
  def source(key)
@@ -111,7 +111,7 @@ module NewRelic
111
111
 
112
112
  def flattened
113
113
  @config_stack.reverse.inject({}) do |flat,layer|
114
- thawed_layer = layer.dup
114
+ thawed_layer = layer.to_hash.dup
115
115
  thawed_layer.each do |k,v|
116
116
  begin
117
117
  thawed_layer[k] = instance_eval(&v) if v.respond_to?(:call)
@@ -121,7 +121,7 @@ module NewRelic
121
121
  end
122
122
  thawed_layer.delete(:config)
123
123
  end
124
- flat.merge(thawed_layer)
124
+ flat.merge(thawed_layer.to_hash)
125
125
  end
126
126
  end
127
127
 
@@ -146,7 +146,7 @@ module NewRelic
146
146
 
147
147
  # Generally only useful during initial construction and tests
148
148
  def reset_to_defaults
149
- @config_stack = [ EnvironmentSource.new, DEFAULTS ]
149
+ @config_stack = [ EnvironmentSource.new, DefaultSource.new ]
150
150
  reset_cache
151
151
  end
152
152
 
@@ -6,8 +6,8 @@ module NewRelic
6
6
  module Agent
7
7
  module Configuration
8
8
  MASK_DEFAULTS = {
9
- :'thread_profiler' => Proc.new { !NewRelic::Agent::ThreadProfiler.is_supported? },
10
- :'thread_profiler.enabled' => Proc.new { !NewRelic::Agent::ThreadProfiler.is_supported? }
9
+ :'thread_profiler' => Proc.new { !NewRelic::Agent::Commands::ThreadProfiler.is_supported? },
10
+ :'thread_profiler.enabled' => Proc.new { !NewRelic::Agent::Commands::ThreadProfiler.is_supported? }
11
11
  }
12
12
  end
13
13
  end
@@ -3,7 +3,8 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require 'new_relic/rack/agent_hooks'
6
- require 'new_relic/agent/thread'
6
+ require 'new_relic/agent/transaction_state'
7
+ require 'new_relic/agent/threading/agent_thread'
7
8
 
8
9
  module NewRelic
9
10
  module Agent
@@ -21,14 +22,6 @@ module NewRelic
21
22
  }
22
23
  CONTENT_LENGTH_HEADER_KEYS = %w{Content-Length HTTP_CONTENT_LENGTH CONTENT_LENGTH}
23
24
 
24
- # Because we aren't in the right spot when our transaction actually
25
- # starts, hold client_cross_app_id we get thread local until then.
26
- THREAD_ID_KEY = :newrelic_client_cross_app_id
27
-
28
- # Same for the referring transaction guid
29
- THREAD_TXN_KEY = :newrelic_cross_app_referring_txn_info
30
-
31
-
32
25
  # Functions for obfuscating and unobfuscating header values
33
26
  module EncodingFunctions
34
27
 
@@ -101,15 +94,15 @@ module NewRelic
101
94
  end
102
95
 
103
96
  def save_client_cross_app_id(request_headers)
104
- NewRelic::Agent::AgentThread.current[THREAD_ID_KEY] = decoded_id(request_headers)
97
+ TransactionState.get.client_cross_app_id = decoded_id(request_headers)
105
98
  end
106
99
 
107
100
  def clear_client_cross_app_id
108
- NewRelic::Agent::AgentThread.current[THREAD_ID_KEY] = nil
101
+ TransactionState.get.client_cross_app_id = nil
109
102
  end
110
103
 
111
104
  def client_cross_app_id
112
- NewRelic::Agent::AgentThread.current[THREAD_ID_KEY]
105
+ TransactionState.get.client_cross_app_id
113
106
  end
114
107
 
115
108
  def save_referring_transaction_info(request_headers)
@@ -119,27 +112,23 @@ module NewRelic
119
112
  txn_info = NewRelic.json_load( txn_header )
120
113
  NewRelic::Agent.logger.debug "Referring txn_info: %p" % [ txn_info ]
121
114
 
122
- NewRelic::Agent::AgentThread.current[THREAD_TXN_KEY] = txn_info
123
- end
124
-
125
- def clear_referring_transaction_info
126
- NewRelic::Agent::AgentThread.current[THREAD_TXN_KEY] = nil
115
+ TransactionState.get.referring_transaction_info = txn_info
127
116
  end
128
117
 
129
118
  def client_referring_transaction_guid
130
- info = NewRelic::Agent::AgentThread.current[THREAD_TXN_KEY] or return nil
119
+ info = TransactionState.get.referring_transaction_info or return nil
131
120
  return info[0]
132
121
  end
133
122
 
134
123
  def client_referring_transaction_record_flag
135
- info = NewRelic::Agent::AgentThread.current[THREAD_TXN_KEY] or return nil
124
+ info = TransactionState.get.referring_transaction_info or return nil
136
125
  return info[1]
137
126
  end
138
127
 
139
128
  def insert_response_header(request_headers, response_headers)
140
129
  unless client_cross_app_id.nil?
141
130
  NewRelic::Agent::Transaction.freeze_name
142
- timings = NewRelic::Agent::BrowserMonitoring.timings
131
+ timings = NewRelic::Agent::TransactionState.get.timings
143
132
  content_length = content_length_from_request(request_headers)
144
133
 
145
134
  set_response_headers(response_headers, timings, content_length)
@@ -220,7 +209,7 @@ module NewRelic
220
209
  end
221
210
 
222
211
  def transaction_guid
223
- NewRelic::Agent::TransactionInfo.get.guid
212
+ NewRelic::Agent::TransactionState.get.request_guid
224
213
  end
225
214
 
226
215
  private
@@ -103,7 +103,7 @@ module NewRelic
103
103
 
104
104
  # Add TT custom parameters
105
105
  segment.name = scoped_metric
106
- add_transaction_trace_parameters(request, response) if response
106
+ add_transaction_trace_parameters(request, response)
107
107
  end
108
108
  ensure
109
109
  # We always need to pop the scope stack to avoid an inconsistent
@@ -138,7 +138,7 @@ module NewRelic
138
138
  key = cross_app_encoding_key()
139
139
  cross_app_id = NewRelic::Agent.config[:cross_process_id] or
140
140
  raise NewRelic::Agent::CrossAppTracing::Error, "no cross app ID configured"
141
- txn_guid = NewRelic::Agent::TransactionInfo.get.guid
141
+ txn_guid = NewRelic::Agent::TransactionState.get.request_guid
142
142
  txn_data = NewRelic.json_dump([ txn_guid, false ])
143
143
 
144
144
  request[ NR_ID_HEADER ] = obfuscate_with_key( key, cross_app_id )
@@ -151,7 +151,7 @@ module NewRelic
151
151
  def add_transaction_trace_parameters(request, response)
152
152
  filtered_uri = ::NewRelic::Agent::HTTPClients::URIUtil.filter_uri(request.uri)
153
153
  transaction_sampler.add_segment_parameters(:uri => filtered_uri)
154
- if response_is_crossapp?( response )
154
+ if response && response_is_crossapp?( response )
155
155
  add_cat_transaction_trace_parameters( response )
156
156
  end
157
157
  end
@@ -20,10 +20,6 @@ module NewRelic
20
20
  # memory and data retention
21
21
  MAX_ERROR_QUEUE_LENGTH = 20 unless defined? MAX_ERROR_QUEUE_LENGTH
22
22
 
23
- # This ivar is used to tag exceptions that we've alreday seen, so that we
24
- # don't double-count them.
25
- EXCEPTION_TAG_IVAR = :@__new_relic_exception_tag
26
-
27
23
  attr_accessor :errors
28
24
 
29
25
  # Returns a new error collector
@@ -101,20 +97,21 @@ module NewRelic
101
97
  end
102
98
 
103
99
  def seen?(exception)
104
- exception.instance_variable_get(EXCEPTION_TAG_IVAR)
100
+ error_ids = TransactionState.get.transaction_noticed_error_ids
101
+ error_ids.include?(exception.object_id)
105
102
  end
106
103
 
107
104
  def tag_as_seen(exception)
108
- exception.instance_variable_set(EXCEPTION_TAG_IVAR, true)
105
+ txn = Transaction.current
106
+ txn.noticed_error_ids << exception.object_id if txn
109
107
  end
110
108
 
111
109
  def blamed_metric_name(options)
112
110
  if options[:metric] && options[:metric] != ::NewRelic::Agent::UNKNOWN_METRIC
113
111
  "Errors/#{options[:metric]}"
114
112
  else
115
- txn_info = TransactionInfo.get
116
- if txn_info && txn_info.transaction
117
- "Errors/#{txn_info.transaction.name}"
113
+ if txn = TransactionState.get.transaction
114
+ "Errors/#{txn.name}"
118
115
  end
119
116
  end
120
117
  end
@@ -264,7 +261,7 @@ module NewRelic
264
261
  return if should_exit_notice_error?(exception)
265
262
  increment_error_count!(exception, options)
266
263
  NewRelic::Agent.instance.events.notify(:notice_error, exception, options)
267
- action_path = fetch_from_options(options, :metric, (NewRelic::Agent.instance.stats_engine.scope_name || ''))
264
+ action_path = fetch_from_options(options, :metric, "")
268
265
  exception_options = error_params_from_options(options).merge(exception_info(exception))
269
266
  add_to_error_queue(NewRelic::NoticedError.new(action_path, exception_options, exception))
270
267
  exception
@@ -16,7 +16,7 @@ module NewRelic
16
16
  end
17
17
 
18
18
  def host
19
- self.uri.host
19
+ self["host"] || self["Host"] || self.uri.host
20
20
  end
21
21
 
22
22
  def method
@@ -36,7 +36,11 @@ module NewRelic
36
36
  end
37
37
 
38
38
  def host
39
- @datum[:host]
39
+ if hostname = (self['host'] || self['Host'])
40
+ hostname.split(':').first
41
+ else
42
+ @datum[:host]
43
+ end
40
44
  end
41
45
 
42
46
  def method
@@ -43,7 +43,11 @@ module NewRelic
43
43
  end
44
44
 
45
45
  def host
46
- uri.host.to_s
46
+ if hostname = (self['host'] || self['Host'])
47
+ hostname.split(':').first
48
+ else
49
+ uri.host.to_s
50
+ end
47
51
  end
48
52
 
49
53
  def [](key)
@@ -16,7 +16,11 @@ module NewRelic
16
16
  end
17
17
 
18
18
  def host
19
- @connection.address
19
+ if hostname = self['host']
20
+ hostname.split(':').first
21
+ else
22
+ @connection.address
23
+ end
20
24
  end
21
25
 
22
26
  def method
@@ -46,7 +46,7 @@ module NewRelic
46
46
  end
47
47
 
48
48
  def host
49
- @uri.host
49
+ self['host'] || self['Host'] || @uri.host
50
50
  end
51
51
 
52
52
  def method
@@ -18,12 +18,12 @@ module NewRelic
18
18
  Agent.logger.debug("Error creating Rack::Request object: #{e}")
19
19
  nil
20
20
  end
21
- TransactionInfo.reset(request)
21
+ TransactionState.reset(request)
22
22
  end
23
23
  end
24
24
 
25
25
  def start(name, id, payload)
26
- payload[:request] = TransactionInfo.get.request
26
+ payload[:request] = TransactionState.get.request
27
27
  event = ControllerEvent.new(name, Time.now, nil, id, payload)
28
28
  push_event(event)
29
29
 
@@ -35,7 +35,7 @@ module NewRelic
35
35
  NewRelic::Agent.instance.push_trace_execution_flag(false)
36
36
  end
37
37
  rescue => e
38
- handle_tracing_error('ActionControllerSubscriber#start', e)
38
+ log_notification_error(e, name, 'start')
39
39
  end
40
40
 
41
41
  def finish(name, id, payload)
@@ -55,18 +55,11 @@ module NewRelic
55
55
  Agent.instance.pop_trace_execution_flag
56
56
  end
57
57
  rescue => e
58
- handle_tracing_error('ActionControllerSubscriber#finish', e)
59
- end
60
-
61
- def handle_tracing_error(identifier, e)
62
- # This is an important enough failure that we want the backtrace logged
63
- # at error level, hence the explicit log_exception call.
64
- NewRelic::Agent.logger.error("Tracing error during #{identifier}:")
65
- NewRelic::Agent.logger.log_exception(:error, e)
58
+ log_notification_error(e, name, 'finish')
66
59
  end
67
60
 
68
61
  def set_enduser_ignore
69
- TransactionInfo.get.ignore_end_user = true
62
+ TransactionState.get.request_ignore_enduser = true
70
63
  end
71
64
 
72
65
  def record_metrics(event)