fingerprint.rb
922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
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
require 'digest/sha1'
class Fingerprint
attr_reader :notice, :api_key
def self.generate(notice, api_key)
self.new(notice, api_key).to_s
end
def initialize(notice, api_key)
@notice = notice
@api_key = api_key
end
def to_s
Digest::SHA1.hexdigest(fingerprint_source.to_s)
end
def fingerprint_source
{
:file_or_message => file_or_message,
:error_class => notice.error_class,
:component => notice.component || 'unknown',
:action => notice.action,
:environment => notice.environment_name || 'development',
:api_key => api_key
}
end
def file_or_message
@file_or_message ||= unified_message + notice.backtrace.fingerprint
end
# filter memory addresses out of object strings
# example: "#<Object:0x007fa2b33d9458>" becomes "#<Object>"
def unified_message
notice.message.gsub(/(#<.+?):[0-9a-f]x[0-9a-f]+(>)/, '\1\2')
end
end