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
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 32 def error_count(error_key) count = begin error_grouping_cache.read(error_key) rescue => 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
28 29 30 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 28 def fallback_cache_store @fallback_cache_store ||= ActiveSupport::Cache::MemoryStore.new end |
#group_error!(exception, options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 51 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
44 45 46 47 48 49 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 44 def save_error_count(error_key, count) error_grouping_cache.write(error_key, count, expires_in: error_grouping_period) rescue => 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
74 75 76 77 78 79 80 81 |
# File 'lib/exception_notifier/modules/error_grouping.rb', line 74 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 |