In a Sidekiq worker I want to ignore some errors in NewRelic while still raising them so that Sidekiqs retry behaviour kicks in.
I wrote a helper class to call NewRelic::Agent.ignore_transaction
but still NewRelic reports these exceptions and complains about the error rate. What am I doing wrong?
I guess that I may have misunderstood something about the scope of the transaction?
module NewRelic
# Run a block which rescues some exceptions and ignores them in NewRelic
class IgnoreExceptions
class << self
def ignore(*class_list)
raise ArgumentError, 'Block required' unless block_given?
begin
yield
rescue errors_matching { |e| class_list.include?(e.class) }
NewRelic::Agent.ignore_transaction
raise
end
end
private
def errors_matching(&block)
Module.new.tap { |m| m.define_singleton_method(:===, &block) }
end
end
end
end
Instead of trying to ignore the transaction you may be better off targeting the errors being generated. If there is a specific error class you would like the New Relic Ruby agent to ignore you could utilize the error_collector.ignore_errors
configuration option. Another possible solution would be to use the NewRelic::Agent#ignore_error_filter
method to filter the errors the agent is tracking.