newrelic_rpm 3.5.4.35.beta → 3.5.5.38

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/CHANGELOG +42 -0
  2. data/GUIDELINES_FOR_CONTRIBUTING.md +3 -0
  3. data/Rakefile +8 -0
  4. data/bin/mongrel_rpm +1 -1
  5. data/init.rb +1 -8
  6. data/lib/new_relic/agent.rb +11 -13
  7. data/lib/new_relic/agent/agent.rb +89 -110
  8. data/lib/new_relic/agent/agent_logger.rb +165 -0
  9. data/lib/new_relic/agent/audit_logger.rb +72 -0
  10. data/lib/new_relic/agent/beacon_configuration.rb +4 -4
  11. data/lib/new_relic/agent/browser_monitoring.rb +13 -7
  12. data/lib/new_relic/agent/busy_calculator.rb +2 -2
  13. data/lib/new_relic/agent/configuration.rb +25 -0
  14. data/lib/new_relic/agent/configuration/defaults.rb +45 -8
  15. data/lib/new_relic/agent/configuration/environment_source.rb +8 -15
  16. data/lib/new_relic/agent/configuration/manager.rb +22 -2
  17. data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
  18. data/lib/new_relic/agent/configuration/yaml_source.rb +4 -2
  19. data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
  20. data/lib/new_relic/agent/database.rb +2 -4
  21. data/lib/new_relic/agent/error_collector.rb +4 -9
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  26. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
  27. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +7 -7
  28. data/lib/new_relic/agent/instrumentation/data_mapper.rb +1 -1
  29. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  30. data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
  31. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -2
  36. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +4 -4
  37. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  38. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  39. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -3
  40. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/resque.rb +3 -2
  42. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
  43. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  44. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +2 -2
  45. data/lib/new_relic/agent/method_tracer.rb +6 -8
  46. data/lib/new_relic/agent/new_relic_service.rb +94 -106
  47. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  48. data/lib/new_relic/agent/samplers/memory_sampler.rb +4 -6
  49. data/lib/new_relic/agent/sql_sampler.rb +3 -18
  50. data/lib/new_relic/agent/stats_engine.rb +0 -5
  51. data/lib/new_relic/agent/stats_engine/metric_stats.rb +3 -3
  52. data/lib/new_relic/agent/stats_engine/samplers.rb +2 -4
  53. data/lib/new_relic/agent/thread.rb +8 -3
  54. data/lib/new_relic/agent/thread_profiler.rb +38 -27
  55. data/lib/new_relic/agent/transaction_info.rb +1 -1
  56. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
  57. data/lib/new_relic/agent/transaction_sampler.rb +3 -7
  58. data/lib/new_relic/agent/worker_loop.rb +3 -11
  59. data/lib/new_relic/control.rb +0 -2
  60. data/lib/new_relic/control/class_methods.rb +8 -2
  61. data/lib/new_relic/control/frameworks/merb.rb +0 -6
  62. data/lib/new_relic/control/frameworks/rails.rb +8 -29
  63. data/lib/new_relic/control/frameworks/rails3.rb +8 -20
  64. data/lib/new_relic/control/frameworks/rails4.rb +23 -0
  65. data/lib/new_relic/control/frameworks/ruby.rb +1 -22
  66. data/lib/new_relic/control/instance_methods.rb +12 -34
  67. data/lib/new_relic/control/instrumentation.rb +7 -12
  68. data/lib/new_relic/control/server_methods.rb +5 -8
  69. data/lib/new_relic/delayed_job_injection.rb +1 -1
  70. data/lib/new_relic/local_environment.rb +30 -64
  71. data/lib/new_relic/metric_data.rb +1 -1
  72. data/lib/new_relic/metric_spec.rb +1 -1
  73. data/lib/new_relic/noticed_error.rb +1 -1
  74. data/lib/new_relic/rack/browser_monitoring.rb +5 -5
  75. data/lib/new_relic/stats.rb +9 -7
  76. data/lib/new_relic/transaction_sample.rb +2 -7
  77. data/lib/new_relic/version.rb +1 -1
  78. data/lib/newrelic_rpm.rb +1 -1
  79. data/newrelic_rpm.gemspec.erb +15 -17
  80. data/test/config/newrelic.yml +1 -1
  81. data/test/config/test_control.rb +18 -18
  82. data/test/fixtures/gemspec_no_build.rb +0 -2
  83. data/test/fixtures/gemspec_with_build.rb +0 -2
  84. data/test/fixtures/gemspec_with_build_and_stage.rb +0 -2
  85. data/test/multiverse/README.md +3 -8
  86. data/test/multiverse/suites/agent_only/Envfile +1 -0
  87. data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
  88. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
  89. data/test/multiverse/suites/config_file_loading/Envfile +7 -0
  90. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
  91. data/test/multiverse/suites/logging/Envfile +4 -0
  92. data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
  93. data/test/multiverse/suites/logging/logging_test.rb +143 -0
  94. data/test/multiverse/suites/no_load/config/newrelic.yml +1 -2
  95. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +0 -13
  96. data/test/new_relic/agent/agent/connect_test.rb +30 -92
  97. data/test/new_relic/agent/agent/start_test.rb +4 -84
  98. data/test/new_relic/agent/agent/start_worker_thread_test.rb +8 -43
  99. data/test/new_relic/agent/agent_logger_test.rb +153 -0
  100. data/test/new_relic/agent/agent_test.rb +10 -9
  101. data/test/new_relic/agent/audit_logger_test.rb +105 -0
  102. data/test/new_relic/agent/browser_monitoring_test.rb +2 -1
  103. data/test/new_relic/agent/busy_calculator_test.rb +7 -0
  104. data/test/new_relic/agent/configuration/environment_source_test.rb +25 -20
  105. data/test/new_relic/agent/configuration/manager_test.rb +59 -4
  106. data/test/new_relic/agent/configuration/yaml_source_test.rb +20 -1
  107. data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
  108. data/test/new_relic/agent/database_test.rb +0 -11
  109. data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -3
  110. data/test/new_relic/agent/error_collector_test.rb +11 -7
  111. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +39 -19
  112. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
  113. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
  114. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +0 -6
  115. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
  116. data/test/new_relic/agent/new_relic_service_test.rb +48 -8
  117. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
  118. data/test/new_relic/agent/sql_sampler_test.rb +1 -1
  119. data/test/new_relic/agent/thread_profiler_test.rb +46 -45
  120. data/test/new_relic/agent/thread_test.rb +13 -0
  121. data/test/new_relic/agent/transaction_sample_builder_test.rb +1 -1
  122. data/test/new_relic/agent/worker_loop_test.rb +4 -9
  123. data/test/new_relic/agent_test.rb +6 -9
  124. data/test/new_relic/control/class_methods_test.rb +0 -18
  125. data/test/new_relic/control_test.rb +6 -9
  126. data/test/new_relic/dispatcher_test.rb +54 -0
  127. data/test/new_relic/fake_collector.rb +15 -14
  128. data/test/new_relic/fake_service.rb +4 -1
  129. data/test/new_relic/fakes_sending_data.rb +30 -0
  130. data/test/new_relic/framework_test.rb +53 -0
  131. data/test/new_relic/local_environment_test.rb +5 -2
  132. data/test/new_relic/rack/browser_monitoring_test.rb +2 -1
  133. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  134. data/test/new_relic/stats_test.rb +10 -0
  135. data/test/new_relic/transaction_sample_test.rb +2 -2
  136. data/test/script/ci.sh +1 -1
  137. data/test/test_helper.rb +23 -0
  138. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  139. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  140. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  141. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  142. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  143. metadata +47 -41
  144. data/InstallationNotes.md +0 -15
  145. data/lib/new_relic/control/logging_methods.rb +0 -125
  146. data/test/multiverse/Rakefile +0 -17
  147. data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +0 -422
  148. data/test/new_relic/control/logging_methods_test.rb +0 -211
@@ -149,7 +149,7 @@ module NewRelic
149
149
  end
150
150
  rescue StandardError => e
151
151
  msg = "#{e.class.name} '#{e.message}' trying to load #{Base64.encode64(data)}"
152
- NewRelic::Control.instance.log.debug(msg)
152
+ ::NewRelic::Agent.logger.debug(msg)
153
153
  nil
154
154
  end
155
155
 
@@ -15,10 +15,10 @@ module NewRelic
15
15
  elsif platform =~ /linux/
16
16
  @sampler = ProcStatus.new
17
17
  if !@sampler.can_run?
18
- NewRelic::Agent.instance.warn.debug "Error attempting to use /proc/#{$$}/status file for reading memory. Using ps command instead."
18
+ ::NewRelic::Agent.logger.debug "Error attempting to use /proc/#{$$}/status file for reading memory. Using ps command instead."
19
19
  @sampler = ShellPS.new("ps -o rsz")
20
20
  else
21
- NewRelic::Agent.instance.log.debug "Using /proc/#{$$}/status for reading process memory."
21
+ ::NewRelic::Agent.logger.debug "Using /proc/#{$$}/status for reading process memory."
22
22
  end
23
23
  elsif platform =~ /darwin9/ # 10.5
24
24
  @sampler = ShellPS.new("ps -o rsz")
@@ -68,14 +68,12 @@ module NewRelic
68
68
  begin
69
69
  m = get_memory
70
70
  if m.nil?
71
- NewRelic::Agent.instance.log.error "Unable to get the resident memory for process #{$$}. Disabling memory sampler."
71
+ ::NewRelic::Agent.logger.warn "Unable to get the resident memory for process #{$$}. Disabling memory sampler."
72
72
  @broken = true
73
73
  end
74
74
  return m
75
75
  rescue => e
76
- NewRelic::Agent.instance.log.error "Unable to get the resident memory for process #{$$}. (#{e})"
77
- NewRelic::Agent.instance.log.debug e.backtrace.join("\n ")
78
- NewRelic::Agent.instance.log.error "Disabling memory sampler."
76
+ ::NewRelic::Agent.logger.warn "Unable to get the resident memory for process #{$$}. Disabling memory sampler.", e
79
77
  @broken = true
80
78
  return nil
81
79
  end
@@ -71,7 +71,7 @@ module NewRelic
71
71
 
72
72
  if data.sql_data.size > 0
73
73
  @samples_lock.synchronize do
74
- NewRelic::Agent.instance.log.debug "Harvesting #{data.sql_data.size} slow transaction sql statement(s)"
74
+ ::NewRelic::Agent.logger.debug "Harvesting #{data.sql_data.size} slow transaction sql statement(s)"
75
75
  #FIXME get tx name and uri
76
76
  harvest_slow_sql data
77
77
  end
@@ -223,31 +223,16 @@ module NewRelic
223
223
  Agent.config[:'slow_sql.explain_enabled']
224
224
  end
225
225
 
226
- def to_collector_array(marshaller)
227
- params = if marshaller.respond_to?(:encode_compress)
228
- marshaller.encode_compress(@params)
229
- else
230
- @params
231
- end
232
-
226
+ def to_collector_array(encoder)
233
227
  [ @path, @url, @sql_id, @sql, @database_metric_name, @call_count,
234
228
  Helper.time_to_millis(@total_call_time),
235
229
  Helper.time_to_millis(@min_call_time),
236
230
  Helper.time_to_millis(@max_call_time),
237
- params ]
231
+ encoder.encode(@params) ]
238
232
  end
239
233
 
240
234
  private
241
235
 
242
- def compress(data)
243
- if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
244
- require 'json'
245
- Base64.encode64(Zlib::Deflate.deflate(JSON.dump(data), Zlib::DEFAULT_COMPRESSION))
246
- else
247
- data
248
- end
249
- end
250
-
251
236
  def consistent_hash(string)
252
237
  # need to hash the same way in every process
253
238
  Digest::MD5.hexdigest(string).hex \
@@ -16,11 +16,6 @@ module NewRelic
16
16
  Thread::current[:newrelic_scope_stack] = nil
17
17
  start_sampler_thread
18
18
  end
19
-
20
- def log
21
- NewRelic::Control.instance.log
22
- end
23
-
24
19
  end
25
20
  end
26
21
  end
@@ -51,7 +51,7 @@ module NewRelic
51
51
 
52
52
  def log_error(e)
53
53
  backtraces = Thread.list.map { |t| log_thread(t) }.join("\n\n")
54
- NewRelic::Control.instance.log.warn(
54
+ ::NewRelic::Agent.logger.warn(
55
55
  "SynchronizedHash failure: #{e.class.name}: #{e.message}\n#{backtraces}")
56
56
  end
57
57
 
@@ -71,9 +71,9 @@ module NewRelic
71
71
  # exceptions without referencing their classes (since they don't
72
72
  # exist in MRI). It also prevents us from swallowing signals or
73
73
  # other nasty things that can happen when you rescue Exception.
74
- NewRelic::Control.instance.log.warn(
74
+ ::NewRelic::Agent.logger.warn(
75
75
  "Error collecting thread backtraces: #{e.class.name}: #{e.message}")
76
- NewRelic::Control.instance.log.debug( e.backtrace.join("\n") )
76
+ ::NewRelic::Agent.logger.debug( e.backtrace.join("\n") )
77
77
 
78
78
  raise e if e.class.ancestors.include? Exception
79
79
  end
@@ -51,7 +51,7 @@ module Agent
51
51
  end
52
52
 
53
53
  def log_added_sampler(type, sampler)
54
- log.debug "Adding #{type} sampler: #{sampler.id}"
54
+ ::NewRelic::Agent.logger.debug "Adding #{type} sampler: #{sampler.id}"
55
55
  end
56
56
 
57
57
  public
@@ -79,9 +79,7 @@ module Agent
79
79
  sampled_item.poll
80
80
  false # it's okay. don't delete it.
81
81
  rescue => e
82
- log.error "Removing #{sampled_item} from list"
83
- log.error e
84
- log.debug e.backtrace.to_s
82
+ ::NewRelic::Agent.logger.warn "Removing #{sampled_item} from list", e
85
83
  true # remove the sampler
86
84
  end
87
85
  end
@@ -3,7 +3,7 @@ module NewRelic
3
3
 
4
4
  class AgentThread < ::Thread
5
5
  def initialize(label)
6
- NewRelic::Agent.logger.debug("Creating New Relic thread: #{label}")
6
+ ::NewRelic::Agent.logger.debug("Creating New Relic thread: #{label}")
7
7
  self[:newrelic_label] = label
8
8
  super
9
9
  end
@@ -19,8 +19,13 @@ module NewRelic
19
19
  end
20
20
 
21
21
  def self.scrub_backtrace(thread, profile_agent_code)
22
- return thread.backtrace if profile_agent_code
23
- thread.backtrace.select {|t| t !~ /\/newrelic_rpm-\d/ }
22
+ begin
23
+ bt = thread.backtrace
24
+ rescue Exception => e
25
+ ::NewRelic::Agent.logger.debug("Failed to backtrace #{thread.inspect}: #{e.class.name}: #{e.to_s}")
26
+ end
27
+ return nil unless bt
28
+ profile_agent_code ? bt : bt.select { |t| t !~ /\/newrelic_rpm-\d/ }
24
29
  end
25
30
  end
26
31
  end
@@ -14,10 +14,10 @@ module NewRelic
14
14
 
15
15
  def start(profile_id, duration, interval, profile_agent_code)
16
16
  if !ThreadProfiler.is_supported?
17
- log.debug("Not starting thread profile as it isn't supported on this environment")
17
+ ::NewRelic::Agent.logger.debug("Not starting thread profile as it isn't supported on this environment")
18
18
  @profile = nil
19
19
  else
20
- log.debug("Starting thread profile. profile_id=#{profile_id}, duration=#{duration}")
20
+ ::NewRelic::Agent.logger.debug("Starting thread profile. profile_id=#{profile_id}, duration=#{duration}")
21
21
  @profile = ThreadProfile.new(profile_id, duration, interval, profile_agent_code)
22
22
  @profile.run
23
23
  end
@@ -45,12 +45,25 @@ module NewRelic
45
45
  name = command["name"]
46
46
  arguments = command["arguments"]
47
47
 
48
- case name
49
- when "start_profiler"
50
- start_unless_running_and_notify(command_id, arguments, &notify_results)
48
+ if (ThreadProfiler.is_supported?)
49
+ case name
50
+ when "start_profiler"
51
+ start_unless_running_and_notify(command_id, arguments, &notify_results)
51
52
 
52
- when "stop_profiler"
53
- stop_and_notify(command_id, arguments, &notify_results)
53
+ when "stop_profiler"
54
+ stop_and_notify(command_id, arguments, &notify_results)
55
+ end
56
+ else
57
+ msg = <<-EOF
58
+ Thread profiling is only supported on 1.9.2 and greater versions of Ruby.
59
+ We detected running agents capable of profiling, but the profile started with
60
+ an agent running Ruby #{RUBY_VERSION}.
61
+
62
+ Profiling again might select an appropriate agent, but we recommend running a
63
+ consistent version of Ruby across your application for better results.
64
+ EOF
65
+ ::NewRelic::Agent.logger.debug(msg)
66
+ notify_results.call(command_id, msg) if !notify_results.nil?
54
67
  end
55
68
  end
56
69
 
@@ -72,7 +85,7 @@ module NewRelic
72
85
 
73
86
  if running?
74
87
  msg = "Profile already in progress. Ignoring agent command to start another."
75
- log.debug(msg)
88
+ ::NewRelic::Agent.logger.debug(msg)
76
89
  yield(command_id, msg) if block_given?
77
90
  else
78
91
  start(profile_id, duration, interval, profile_agent_code)
@@ -86,9 +99,6 @@ module NewRelic
86
99
  yield(command_id) if block_given?
87
100
  end
88
101
 
89
- def log
90
- NewRelic::Agent.logger
91
- end
92
102
  end
93
103
 
94
104
  class ThreadProfile
@@ -117,6 +127,7 @@ module NewRelic
117
127
 
118
128
  @poll_count = 0
119
129
  @sample_count = 0
130
+ @failure_count = 0
120
131
  end
121
132
 
122
133
  def run
@@ -129,24 +140,31 @@ module NewRelic
129
140
 
130
141
  @poll_count += 1
131
142
  AgentThread.list.each do |t|
132
- @sample_count += 1
133
-
134
143
  bucket = AgentThread.bucket_thread(t, @profile_agent_code)
135
- backtrace = AgentThread.scrub_backtrace(t, @profile_agent_code)
136
- aggregate(backtrace, @traces[bucket]) unless bucket == :ignore
144
+ if bucket != :ignore
145
+ backtrace = AgentThread.scrub_backtrace(t, @profile_agent_code)
146
+ if backtrace.nil?
147
+ @failure_count += 1
148
+ else
149
+ @sample_count += 1
150
+ aggregate(backtrace, @traces[bucket])
151
+ end
152
+ end
137
153
  end
138
154
  end
139
155
  end
140
156
 
141
157
  mark_done
142
- log.debug("Finished thread profile. Will send with next harvest.")
158
+ ::NewRelic::Agent.logger.debug("Finished thread profile. #{@sample_count} backtraces, #{@failure_count} failures. Will send with next harvest.")
159
+ NewRelic::Agent.instance.stats_engine.
160
+ record_supportability_metrics_count(@failure_count, "ThreadProfiler/BacktraceFailures")
143
161
  end
144
162
  end
145
163
 
146
164
  def stop
147
165
  @worker_loop.stop
148
166
  mark_done
149
- log.debug("Stopping thread profile.")
167
+ ::NewRelic::Agent.logger.debug("Stopping thread profile.")
150
168
  end
151
169
 
152
170
  def aggregate(trace, trees=@traces[:request], parent=nil)
@@ -184,7 +202,7 @@ module NewRelic
184
202
 
185
203
  THREAD_PROFILER_NODES = 20_000
186
204
 
187
- def to_compressed_array
205
+ def to_collector_array(encoder)
188
206
  prune!(THREAD_PROFILER_NODES)
189
207
 
190
208
  traces = {
@@ -196,8 +214,8 @@ module NewRelic
196
214
 
197
215
  [[@profile_id,
198
216
  @start_time.to_f, @stop_time.to_f,
199
- @poll_count,
200
- ThreadProfile.compress(JSON.dump(traces)),
217
+ @poll_count,
218
+ encoder.encode(traces),
201
219
  @sample_count, 0]]
202
220
  end
203
221
 
@@ -223,10 +241,6 @@ module NewRelic
223
241
  nodes.map { |n| [n, flattened_nodes(n.children)] }.flatten
224
242
  end
225
243
 
226
- def self.compress(json)
227
- compressed = Base64.encode64(Zlib::Deflate.deflate(json, Zlib::DEFAULT_COMPRESSION))
228
- end
229
-
230
244
  def self.parse_backtrace(trace)
231
245
  trace.map do |line|
232
246
  line =~ /(.*)\:(\d+)\:in `(.*)'/
@@ -287,9 +301,6 @@ module NewRelic
287
301
  end
288
302
  end
289
303
 
290
- def log
291
- NewRelic::Agent.logger
292
- end
293
304
  end
294
305
  end
295
306
  end
@@ -33,7 +33,7 @@ module NewRelic
33
33
  def duration
34
34
  Time.now - start_time
35
35
  end
36
-
36
+
37
37
  def ignore_end_user?
38
38
  @ignore_end_user
39
39
  end
@@ -37,7 +37,7 @@ module NewRelic
37
37
  @current_segment.add_called_segment(segment)
38
38
  @current_segment = segment
39
39
  if @sample.count_segments == segment_limit
40
- NewRelic::Control.instance.log.debug("Segment limit of #{segment_limit} reached, ceasing collection.")
40
+ ::NewRelic::Agent.logger.debug("Segment limit of #{segment_limit} reached, ceasing collection.")
41
41
  end
42
42
  @current_segment
43
43
  end
@@ -56,8 +56,7 @@ module NewRelic
56
56
  # This should never get called twice, but in a rare case that we can't reproduce in house it does.
57
57
  # log forensics and return gracefully
58
58
  if @sample.frozen?
59
- log = NewRelic::Control.instance.log
60
- log.error "Unexpected double-freeze of Transaction Trace Object: \n#{@sample.to_s}"
59
+ ::NewRelic::Agent.logger.error "Unexpected double-freeze of Transaction Trace Object: \n#{@sample.to_s}"
61
60
  return
62
61
  end
63
62
  @sample.root_segment.end_trace(time.to_f - @sample_start)
@@ -45,23 +45,19 @@ module NewRelic
45
45
  Agent.config.register_callback(:'transaction_tracer.enabled') do |enabled|
46
46
  if enabled
47
47
  threshold = Agent.config[:'transaction_tracer.transaction_threshold']
48
- log.debug "Transaction tracing threshold is #{threshold} seconds."
48
+ ::NewRelic::Agent.logger.debug "Transaction tracing threshold is #{threshold} seconds."
49
49
  else
50
- log.debug "Transaction traces will not be sent to the New Relic service."
50
+ ::NewRelic::Agent.logger.debug "Transaction traces will not be sent to the New Relic service."
51
51
  end
52
52
  end
53
53
 
54
54
  Agent.config.register_callback(:'transaction_tracer.record_sql') do |config|
55
55
  if config == 'raw'
56
- log.warn("Agent is configured to send raw SQL to the service")
56
+ ::NewRelic::Agent.logger.warn("Agent is configured to send raw SQL to the service")
57
57
  end
58
58
  end
59
59
  end
60
60
 
61
- def log
62
- NewRelic::Control.instance.log
63
- end
64
-
65
61
  # Returns the current sample id, delegated from `builder`
66
62
  def current_sample_id
67
63
  b=builder
@@ -9,7 +9,6 @@ module NewRelic
9
9
  # Optional argument :duration (in seconds) for how long the worker loop runs
10
10
  # or :limit (integer) for max number of iterations
11
11
  def initialize(opts={})
12
- @log = log
13
12
  @should_run = true
14
13
  @next_invocation_time = Time.now
15
14
  @period = 60.0
@@ -23,11 +22,6 @@ module NewRelic
23
22
  @@lock ||= Mutex.new
24
23
  end
25
24
 
26
- # a helper to access the NewRelic::Control.instance.log
27
- def log
28
- NewRelic::Control.instance.log
29
- end
30
-
31
25
  # Run infinitely, calling the registered tasks at their specified
32
26
  # call periods. The caller is responsible for creating the thread
33
27
  # that runs this worker loop. This will run the task immediately.
@@ -75,23 +69,21 @@ module NewRelic
75
69
  @task.call
76
70
  end
77
71
  rescue ServerError => e
78
- log.debug "Server Error: #{e}"
72
+ ::NewRelic::Agent.logger.debug "Server Error:", e
79
73
  rescue NewRelic::Agent::ForceRestartException, NewRelic::Agent::ForceDisconnectException
80
74
  # blow out the loop
81
75
  raise
82
76
  rescue RuntimeError => e
83
77
  # This is probably a server error which has been logged in the server along
84
78
  # with your account name.
85
- log.error "Error running task in worker loop, likely a server error (#{e})"
86
- log.debug e.backtrace.join("\n")
79
+ ::NewRelic::Agent.logger.error "Error running task in worker loop, likely a server error:", e
87
80
  rescue Timeout::Error, NewRelic::Agent::ServerConnectionException
88
81
  # Want to ignore these because they are handled already
89
82
  rescue SystemExit, NoMemoryError, SignalException
90
83
  raise
91
84
  rescue => e
92
85
  # Don't blow out the stack for anything that hasn't already propagated
93
- log.error "Error running task in Agent Worker Loop '#{e}': #{e.backtrace.first}"
94
- log.debug e.backtrace.join("\n")
86
+ ::NewRelic::Agent.logger.error "Error running task in Agent Worker Loop:", e
95
87
  end
96
88
  now = Time.now
97
89
  while @next_invocation_time <= now && @period > 0
@@ -11,7 +11,6 @@ require 'net/https'
11
11
  require 'logger'
12
12
  require 'new_relic/control/frameworks'
13
13
  require 'new_relic/control/profiling'
14
- require 'new_relic/control/logging_methods'
15
14
  require 'new_relic/control/server_methods'
16
15
  require 'new_relic/control/instrumentation'
17
16
  require 'new_relic/control/class_methods'
@@ -35,7 +34,6 @@ module NewRelic
35
34
  # extend ClassMethods
36
35
  # include InstanceMethods
37
36
  # include Profiling
38
- # include LoggingMethods
39
37
  # include Configuration
40
38
  # include ServerMethods
41
39
  # include Instrumentation
@@ -9,6 +9,12 @@ module NewRelic
9
9
  @instance ||= create && new_instance
10
10
  end
11
11
 
12
+ # clear out memoized Control and LocalEnv instances
13
+ def reset
14
+ @instance = nil
15
+ @local_env = nil
16
+ end
17
+
12
18
  # Access the LocalEnvironment singleton, lazy initialized
13
19
  def local_env
14
20
  @local_env ||= NewRelic::LocalEnvironment.new
@@ -16,10 +22,10 @@ module NewRelic
16
22
 
17
23
  # Create the concrete class for environment specific behavior
18
24
  def new_instance
19
- if local_env.framework == :test
25
+ if Agent.config[:framework] == :test
20
26
  load_test_framework
21
27
  else
22
- load_framework_class(local_env.framework).new(local_env)
28
+ load_framework_class(Agent.config[:framework]).new(local_env)
23
29
  end
24
30
  end
25
31