lib/honeybadger/monitor/worker.rb in honeybadger-1.15.2 vs lib/honeybadger/monitor/worker.rb in honeybadger-1.15.3
- old
+ new
@@ -19,10 +19,12 @@
start
at_exit { stop }
end
def start
+ Honeybadger.write_verbose_log('Starting worker')
+
@thread = MetricsThread.new do
begin
until Thread.current[:should_exit] do
send_metrics
send_traces
@@ -34,13 +36,28 @@
end
end
end
def stop
+ Honeybadger.write_verbose_log('Stopping worker')
@thread[:should_exit] = true if @thread
end
+ def fork
+ Honeybadger.write_verbose_log('Forking worker')
+
+ stop
+
+ @lock.unlock if @lock.locked?
+ @lock.synchronize do
+ init_metrics
+ init_traces
+ end
+
+ start
+ end
+
def timing(name, value)
add_metric(name, value, :timing)
end
def increment(name, value)
@@ -92,10 +109,13 @@
end
def send_metrics
metrics = collect_metrics
return unless metrics[:timing].any? || metrics[:counter].any?
+
+ Honeybadger.write_verbose_log('Sending metrics')
+
[].tap do |m|
metrics[:counter].each do |metric, values|
m << "#{metric} #{values.sum}"
end
metrics[:timing].each do |metric, values|
@@ -115,10 +135,15 @@
end
end
end
def send_traces
- collect_traces.each_slice(@per_request) do |t|
+ traces = collect_traces
+ return unless traces.any?
+
+ Honeybadger.write_verbose_log('Sending traces')
+
+ traces.each_slice(@per_request) do |t|
begin
@sender.send_traces({ :traces => t.compact.map(&:to_h), :environment => Honeybadger.configuration.environment_name, :hostname => Honeybadger.configuration.hostname })
rescue Exception => e
log(:error, "[Honeybadger::Monitor::Worker#send_traces] Failed to send #{t.count} metrics: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}")
end