Class: RailsInformant::Fingerprint

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_informant/fingerprint.rb

Constant Summary collapse

APP_FRAME_PATTERN =
/\A(?!.*\/(gems|ruby|rubies)\/)/.freeze

Class Method Summary collapse

Class Method Details

.first_app_frame(exception) ⇒ Object



15
16
17
# File 'lib/rails_informant/fingerprint.rb', line 15

def self.first_app_frame(exception)
  exception.backtrace.find { APP_FRAME_PATTERN.match?(it) } || exception.backtrace.first
end

.generate(exception) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/rails_informant/fingerprint.rb', line 7

def self.generate(exception)
  return Digest::SHA256.hexdigest(exception.class.name) unless exception.backtrace

  first_frame = first_app_frame(exception)
  normalized = normalize_frame(first_frame)
  Digest::SHA256.hexdigest "#{exception.class.name}:#{normalized}"
end

.normalize_frame(frame) ⇒ Object



19
20
21
# File 'lib/rails_informant/fingerprint.rb', line 19

def self.normalize_frame(frame)
  frame.sub(/:(\d+)(?=:in |$)/, ":0")
end