exception_notification
exception_notification copied to clipboard
Ignore_notifier_if settings are not respected in non-Rack usages such as background jobs.
Steps to reproduce
Given: ExceptionNotifier is configured with:
ignore_notifier_if: {
email: ->(env, exception) { ... }
},
And an exception notification is manually sent such as through a background worker with:
rescue => e
ExceptionNotifier.notify_exception(e)
end
Expected behavior
The ignore_notifier block should be called and respected.
Actual behavior
The ignore_notifier block is not called nor respected. This is likely because the ignore block is only set via Rack, so any non-Rack usages of ExceptionNotifier will not retain the ignore settings.
System configuration
Rails version: Rails v6+
Ruby version: Ruby 2.7
I have been struggling with the same issue The problematic code was:
if options.key?(:ignore_notifier_if)
rack_ignore_by_notifier = options.delete(:ignore_notifier_if)
rack_ignore_by_notifier.each do |notifier, proc|
ExceptionNotifier.ignore_notifier_if(notifier) do |exception, opts|
opts.key?(:env) && proc.call(opts[:env], exception)
end
end
end
Thus the notifier does not work if env is not set
Giving any non null value for env solved the issue for me:
ExceptionNotifier.notify_exception(e, env: request.env)