35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/error_radar/notifications/discord.rb', line 35
def self.build_payload(log, event)
spike_data = log.instance_variable_get(:@spike_data)
app = ErrorRadar::Notifier.app_name
link = ErrorRadar::Notifier.error_url(log)
prefix, color = case event
when :spike
["⚠️ Spike (#{spike_data[:count]} hits / #{spike_data[:window_minutes]} min)", SPIKE_COLOR]
when :new_error
['🆕 New error', SEV_COLORS[log.severity] || 0x6c757d]
else
['🔁 Recurring error', SEV_COLORS[log.severity] || 0x6c757d]
end
fields = [
{ name: 'Source', value: (log.source || 'unknown').truncate(100), inline: true },
{ name: 'Category', value: log.category.to_s, inline: true },
{ name: 'Severity', value: log.severity.to_s, inline: true },
{ name: 'Occurrences', value: log.occurrences.to_s, inline: true }
]
fields << { name: 'View', value: "[Error Radar](#{link})", inline: false } if link
embed = {
title: "#{prefix}: #{log.error_class}",
description: "```#{log.message.to_s.truncate(300)}```",
color: color,
fields: fields,
footer: { text: "[#{app}] Error Radar" },
timestamp: log.last_seen_at&.iso8601
}.compact
{ embeds: [embed] }
end
|