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
|
# File 'lib/error_track/notifier.rb', line 5
def call(exception, context: {})
return unless ErrorTrack.configuration.enabled
return if ErrorTrack.configuration.ignored?(exception)
fingerprint = generate_fingerprint(exception)
event = ErrorTrack::ErrorEvent.transaction do
e = ErrorTrack::ErrorEvent.lock.find_or_initialize_by(fingerprint: fingerprint)
e.klass ||= exception.class.name
e.message = exception.message.to_s.truncate(1000)
e.first_seen_at ||= Time.current
e.last_seen_at = Time.current
e.occurrences_count = e.occurrences_count.to_i + 1
e.resolved = false if e.resolved?
e.save!
e
end
event.occurrences.create!(
backtrace: Array(exception.backtrace).first(50).join("\n"),
context: context.presence || {},
environment: defined?(Rails) ? Rails.env.to_s : nil,
occurred_at: Time.current
)
event
rescue => e
Rails.logger&.error("[ErrorTrack] failed to record exception: #{e.class} #{e.message}") if defined?(Rails)
nil
end
|