Send a correct backtrace and some other nice things to airbrake on resque errors
This commit is contained in:
parent
a2bfc4a487
commit
1df654d416
2 changed files with 14 additions and 10 deletions
|
|
@ -10,33 +10,37 @@ module ResqueJobLogging
|
||||||
error = e
|
error = e
|
||||||
end
|
end
|
||||||
}*1000
|
}*1000
|
||||||
|
|
||||||
|
log_string += "ms=#{time} "
|
||||||
|
args.each_with_index{|arg,idx| log_string += "arg#{idx.succ}=\"#{arg.to_s[0..30]}\" "}
|
||||||
|
|
||||||
if error
|
if error
|
||||||
log_string += "status=error "
|
log_string += "status=error "
|
||||||
log_string << "error_class=#{error.class} error_message='#{error.message}' "
|
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 << "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 << "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
|
else
|
||||||
log_string += "status=complete "
|
log_string += "status=complete "
|
||||||
end
|
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)
|
Rails.logger.info(log_string)
|
||||||
if error
|
raise error if error
|
||||||
notify_hoptoad(error, args) if AppConfig[:hoptoad_api_key].present?
|
|
||||||
raise error
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_hoptoad(error, job_arguments)
|
def notify_hoptoad(error, job_arguments, backtrace)
|
||||||
puts "Notifying hoptoad"
|
puts "Notifying hoptoad"
|
||||||
HoptoadNotifier.notify(
|
HoptoadNotifier.notify(
|
||||||
:error_class => error.class,
|
:error_class => error.class,
|
||||||
:error_message => error.message,
|
:error_message => error.message,
|
||||||
|
:backtrace => backtrace,
|
||||||
:parameters => {
|
:parameters => {
|
||||||
:job_class => self.name,
|
: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?
|
) if Rails.env.production?
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ describe ResqueJobLogging do
|
||||||
Rails.logger.should_receive(:info)
|
Rails.logger.should_receive(:info)
|
||||||
AppConfig.should_receive(:[]).with(:hoptoad_api_key).and_return("what")
|
AppConfig.should_receive(:[]).with(:hoptoad_api_key).and_return("what")
|
||||||
error = RuntimeError.new("GRAAAAAAAAAGH")
|
error = RuntimeError.new("GRAAAAAAAAAGH")
|
||||||
ResqueJobLoggingDummy.should_receive(:notify_hoptoad).with(error, ["stuff"])
|
ResqueJobLoggingDummy.should_receive(:notify_hoptoad).with(error, ["stuff"], anything)
|
||||||
proc {
|
proc {
|
||||||
ResqueJobLoggingDummy.around_perform_log_job("stuff"){raise error }
|
ResqueJobLoggingDummy.around_perform_log_job("stuff"){raise error }
|
||||||
}.should raise_error
|
}.should raise_error
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue