NewRelic Ruby 代理:未忽略的错误
NewRelic Ruby Agent: errors not ignored
在 Sidekiq worker 中,我想忽略 NewRelic 中的一些错误,同时仍然提出它们,以便 Sidekiqs 重试行为开始。
我写了一个助手 class 来调用 NewRelic::Agent.ignore_transaction
但 NewRelic 仍然报告这些异常并抱怨错误率。我究竟做错了什么?
我想我可能对交易范围有什么误解?
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
与其试图忽略事务,不如将生成的错误作为目标。如果存在特定错误 class,您希望 New Relic Ruby 代理忽略您可以使用 error_collector.ignore_errors
configuration option. Another possible solution would be to use the NewRelic::Agent#ignore_error_filter
方法来过滤代理正在跟踪的错误。
在 Sidekiq worker 中,我想忽略 NewRelic 中的一些错误,同时仍然提出它们,以便 Sidekiqs 重试行为开始。
我写了一个助手 class 来调用 NewRelic::Agent.ignore_transaction
但 NewRelic 仍然报告这些异常并抱怨错误率。我究竟做错了什么?
我想我可能对交易范围有什么误解?
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
与其试图忽略事务,不如将生成的错误作为目标。如果存在特定错误 class,您希望 New Relic Ruby 代理忽略您可以使用 error_collector.ignore_errors
configuration option. Another possible solution would be to use the NewRelic::Agent#ignore_error_filter
方法来过滤代理正在跟踪的错误。