Module: Exceptify::ErrorGrouping::ClassMethods
- Defined in:
- lib/exceptify/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
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/exceptify/modules/error_grouping.rb', line 112 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
108 109 110 |
# File 'lib/exceptify/modules/error_grouping.rb', line 108 def fallback_cache_store @fallback_cache_store ||= ActiveSupport::Cache::MemoryStore.new end |
#group_error!(exception, options) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/exceptify/modules/error_grouping.rb', line 131 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
124 125 126 127 128 129 |
# File 'lib/exceptify/modules/error_grouping.rb', line 124 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
154 155 156 157 158 159 160 161 |
# File 'lib/exceptify/modules/error_grouping.rb', line 154 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 |