Class: RailsErrorDashboard::Services::BacktraceProcessor
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Services::BacktraceProcessor
- Defined in:
- lib/rails_error_dashboard/services/backtrace_processor.rb
Overview
Pure algorithm service for backtrace processing Handles truncation and signature generation with no database access.
Class Method Summary collapse
-
.calculate_signature(backtrace, locations: nil) ⇒ String?
Calculate a signature hash from backtrace for fuzzy similarity matching Extracts file paths and method names, ignoring line numbers, then produces an order-independent SHA256 digest.
-
.truncate(backtrace, max_lines: nil) ⇒ String?
Truncate backtrace to a maximum number of lines.
Class Method Details
.calculate_signature(backtrace, locations: nil) ⇒ String?
Calculate a signature hash from backtrace for fuzzy similarity matching Extracts file paths and method names, ignoring line numbers, then produces an order-independent SHA256 digest.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rails_error_dashboard/services/backtrace_processor.rb', line 34 def self.calculate_signature(backtrace, locations: nil) # Try structured locations first (more reliable, no regex) if locations && !locations.empty? return signature_from_locations(locations) end return nil if backtrace.blank? lines = backtrace.is_a?(String) ? backtrace.split("\n") : backtrace frames = lines.first(20).map do |line| if line =~ %r{([^/]+\.rb):.*?in `(.+)'$} "#{Regexp.last_match(1)}:#{Regexp.last_match(2)}" elsif line =~ %r{([^/]+\.rb)} Regexp.last_match(1) end end.compact.uniq return nil if frames.empty? file_paths = frames.map { |frame| frame.split(":").first }.sort Digest::SHA256.hexdigest(file_paths.join("|"))[0..15] end |
.truncate(backtrace, max_lines: nil) ⇒ String?
Truncate backtrace to a maximum number of lines
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rails_error_dashboard/services/backtrace_processor.rb', line 12 def self.truncate(backtrace, max_lines: nil) return nil if backtrace.nil? max_lines ||= RailsErrorDashboard.configuration.max_backtrace_lines limited_backtrace = backtrace.first(max_lines) result = limited_backtrace.join("\n") if backtrace.length > max_lines truncation_notice = "... (#{backtrace.length - max_lines} more lines truncated)" result = result.empty? ? truncation_notice : result + "\n" + truncation_notice end result end |