Class: ShieldPressTracker::ErrorCollector
- Inherits:
-
Object
- Object
- ShieldPressTracker::ErrorCollector
- Defined in:
- lib/shieldpress_tracker/collectors.rb
Instance Method Summary collapse
- #capture(error, meta = {}) ⇒ Object
- #flush ⇒ Object
-
#initialize(maximum) ⇒ ErrorCollector
constructor
A new instance of ErrorCollector.
Constructor Details
#initialize(maximum) ⇒ ErrorCollector
Returns a new instance of ErrorCollector.
45 |
# File 'lib/shieldpress_tracker/collectors.rb', line 45 def initialize(maximum); @maximum, @events, @mutex = maximum, [], Mutex.new end |
Instance Method Details
#capture(error, meta = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/shieldpress_tracker/collectors.rb', line 46 def capture(error, = {}) event = { message: error.to_s[0, 4096], type: error.class.name, timestamp: Time.now.utc.iso8601 } event[:stack] = Array(error.backtrace).join("\n")[0, 4096] if error.respond_to?(:backtrace) = .dup { url: :url, method: :method, status_code: :statusCode }.each { |from, to| event[to] = .delete(from) if .key?(from) } event[:meta] = unless .empty? @mutex.synchronize { @events << event; @events = @events.last(@maximum) } rescue StandardError nil end |
#flush ⇒ Object
56 |
# File 'lib/shieldpress_tracker/collectors.rb', line 56 def flush; @mutex.synchronize { rows = @events; @events = []; rows } end |