From 1df654d416b833382ec58c3d6ab8a7c29ee401f9 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Wed, 10 Aug 2011 11:10:13 -0700 Subject: [PATCH] Send a correct backtrace and some other nice things to airbrake on resque errors --- lib/resque_job_logging.rb | 22 +++++++++++++--------- spec/lib/resque_job_logging_spec.rb | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/resque_job_logging.rb b/lib/resque_job_logging.rb index 98c76d4f3..2fcc8c38d 100644 --- a/lib/resque_job_logging.rb +++ b/lib/resque_job_logging.rb @@ -10,33 +10,37 @@ module ResqueJobLogging error = e end }*1000 + + log_string += "ms=#{time} " + args.each_with_index{|arg,idx| log_string += "arg#{idx.succ}=\"#{arg.to_s[0..30]}\" "} + if error log_string += "status=error " log_string << "error_class=#{error.class} error_message='#{error.message}' " log_string << "orig_error_message='#{error.original_error.message}'" if error.respond_to?(:original_error) log_string << "annotated_source='#{error.annoted_source_code.to_s}' " if error.respond_to?(:annoted_source_code) - log_string << "app_backtrace='#{application_trace(error).join(";")}' " + backtrace = application_trace(error) + log_string << "app_backtrace='#{backtrace.join(";")}' " + notify_hoptoad(error, args, backtrace) if AppConfig[:hoptoad_api_key].present? else log_string += "status=complete " end - log_string += "ms=#{time} " - args.each_with_index{|arg,idx| log_string += "arg#{idx.succ}=\"#{arg.to_s[0..30]}\" "} Rails.logger.info(log_string) - if error - notify_hoptoad(error, args) if AppConfig[:hoptoad_api_key].present? - raise error - end + raise error if error end - def notify_hoptoad(error, job_arguments) + def notify_hoptoad(error, job_arguments, backtrace) puts "Notifying hoptoad" HoptoadNotifier.notify( :error_class => error.class, :error_message => error.message, + :backtrace => backtrace, :parameters => { :job_class => self.name, - :arguments => job_arguments.map!{|a| a.to_s[0..30]} + :arguments => job_arguments.map!{|a| a.to_s[0..30]}, + :controller => "Resque", + :action => self.name } ) if Rails.env.production? end diff --git a/spec/lib/resque_job_logging_spec.rb b/spec/lib/resque_job_logging_spec.rb index cff02fb77..a69f4fdcf 100644 --- a/spec/lib/resque_job_logging_spec.rb +++ b/spec/lib/resque_job_logging_spec.rb @@ -34,7 +34,7 @@ describe ResqueJobLogging do Rails.logger.should_receive(:info) AppConfig.should_receive(:[]).with(:hoptoad_api_key).and_return("what") error = RuntimeError.new("GRAAAAAAAAAGH") - ResqueJobLoggingDummy.should_receive(:notify_hoptoad).with(error, ["stuff"]) + ResqueJobLoggingDummy.should_receive(:notify_hoptoad).with(error, ["stuff"], anything) proc { ResqueJobLoggingDummy.around_perform_log_job("stuff"){raise error } }.should raise_error