Class: ErrorLog
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ErrorLog
- Defined in:
- app/models/error_log.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.capture!(exception) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/error_log.rb', line 13 def self.capture!(exception) cleaned = Rails.backtrace_cleaner.clean(exception.backtrace || []) # Don't store exception.inspect — Ruby's default inspect for many error # subclasses includes ivar dumps that can carry secrets (API keys read # from ENV into a local, request bodies, etc.). Store just class + # truncated message instead. Apps that need richer context should # capture it explicitly via target/parent or via Sentry's PII rules. safe_inspect = "#<#{exception.class}: #{exception..to_s[0, 1000]}>" log = create!( message: exception., inspect: safe_inspect, backtrace: cleaned.to_json ) log.update_column(:slug, "error-log-#{log.id}") # Fan out to Sentry if the host app loaded sentry-ruby. Guard with # respond_to? so we don't blow up on old SDK versions. The DB ErrorLog # row remains the local triage view; Sentry is the paging layer. if defined?(::Sentry) && ::Sentry.respond_to?(:capture_exception) begin ::Sentry.capture_exception(exception) do |scope| scope.(error_log_slug: log.slug) end rescue => e Rails.logger.warn "[ErrorLog.capture!] Sentry delivery failed: #{e.class}: #{e.}" end end log end |
Instance Method Details
#inspect_field ⇒ Object
9 10 11 |
# File 'app/models/error_log.rb', line 9 def inspect_field read_attribute(:inspect) end |
#to_param ⇒ Object
5 6 7 |
# File 'app/models/error_log.rb', line 5 def to_param slug end |