Module: ExceptionNotifier::ErrorGrouping::ClassMethods
- Defined in:
- lib/exception_notifier/modules/error_grouping.rb
Instance Method Summary collapse
- #error_count(error_key) ⇒ Object
-
#fallback_cache_store ⇒ Object
Fallback to the memory store while the specified cache store doesn’t work.
- #group_error!(exception, options) ⇒ Object
- #save_error_count(error_key, count) ⇒ Object
- #send_notification?(exception, count) ⇒ Boolean
Instance Method Details
#error_count(error_key) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 30 def error_count(error_key) count = begin error_grouping_cache.read(error_key) rescue StandardError => e log_cache_error(error_grouping_cache, e, :read) fallback_cache_store.read(error_key) end count&.to_i end |
#fallback_cache_store ⇒ Object
Fallback to the memory store while the specified cache store doesn’t work
26 27 28 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 26 def fallback_cache_store @fallback_cache_store ||= ActiveSupport::Cache::MemoryStore.new end |
#group_error!(exception, options) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 49 def group_error!(exception, ) = "exception:#{Zlib.crc32("#{exception.class.name}\nmessage:#{exception.}")}" accumulated_errors_count = 1 if (count = error_count()) accumulated_errors_count = count + 1 save_error_count(, accumulated_errors_count) else backtrace_based_key = "exception:#{Zlib.crc32("#{exception.class.name}\npath:#{exception.backtrace.try(:first)}")}" if (count = error_grouping_cache.read(backtrace_based_key)) accumulated_errors_count = count + 1 save_error_count(backtrace_based_key, accumulated_errors_count) else save_error_count(backtrace_based_key, accumulated_errors_count) save_error_count(, accumulated_errors_count) end end [:accumulated_errors_count] = accumulated_errors_count end |
#save_error_count(error_key, count) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 42 def save_error_count(error_key, count) error_grouping_cache.write(error_key, count, expires_in: error_grouping_period) rescue StandardError => e log_cache_error(error_grouping_cache, e, :write) fallback_cache_store.write(error_key, count, expires_in: error_grouping_period) end |
#send_notification?(exception, count) ⇒ Boolean
72 73 74 75 76 77 78 79 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 72 def send_notification?(exception, count) if notification_trigger.respond_to?(:call) notification_trigger.call(exception, count) else factor = Math.log2(count) factor.to_i == factor end end |