rails-informant 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rails_informant/configuration.rb +13 -2
- data/lib/rails_informant/context_builder.rb +14 -6
- data/lib/rails_informant/notifiers/slack.rb +45 -38
- data/lib/rails_informant.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 71f2d05d2caf43bbaab7641118f09b86cafb4949d9f4c2be262a4773f6a88eab
|
|
4
|
+
data.tar.gz: 8f3de02212167bfcbbb412d653af259eeed2a0e5907f75b8e1191d724faf112a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b7c2c8599fe28a7adef712a0cc4f989cdae99465a18b2120055c049dbf77136e243dee9f382fc8dee0ed6d6c7d2d6173a18b1e42a750d031a31268fd377758ff
|
|
7
|
+
data.tar.gz: 59729b6bd6f564023810acd041e3d71f7cf930e8bb65dd88833495b6392d3eb979aa920b80650d4ffe6833f91675743b928a1162ecad4bf10c75c894759843ad
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
module RailsInformant
|
|
2
2
|
class Configuration
|
|
3
|
-
attr_accessor :
|
|
4
|
-
:capture_errors,
|
|
3
|
+
attr_accessor :capture_errors,
|
|
5
4
|
:capture_user_email,
|
|
5
|
+
:api_token,
|
|
6
6
|
:ignored_exceptions,
|
|
7
7
|
:retention_days,
|
|
8
8
|
:slack_webhook_url,
|
|
9
9
|
:webhook_url
|
|
10
10
|
|
|
11
|
+
attr_writer :app_name
|
|
12
|
+
|
|
11
13
|
def initialize
|
|
12
14
|
@api_token = ENV["INFORMANT_API_TOKEN"]
|
|
15
|
+
@app_name = ENV["INFORMANT_APP_NAME"]
|
|
13
16
|
@capture_errors = ENV.fetch("INFORMANT_CAPTURE_ERRORS", "true") != "false"
|
|
14
17
|
@capture_user_email = false
|
|
15
18
|
@custom_notifiers = []
|
|
@@ -19,6 +22,10 @@ module RailsInformant
|
|
|
19
22
|
@webhook_url = ENV["INFORMANT_WEBHOOK_URL"]
|
|
20
23
|
end
|
|
21
24
|
|
|
25
|
+
def app_name
|
|
26
|
+
@app_name.presence || detect_app_name
|
|
27
|
+
end
|
|
28
|
+
|
|
22
29
|
# Returns all notifiers: built-in (auto-registered from config) + custom.
|
|
23
30
|
def notifiers
|
|
24
31
|
@_notifiers ||= built_in_notifiers + @custom_notifiers
|
|
@@ -36,6 +43,10 @@ module RailsInformant
|
|
|
36
43
|
|
|
37
44
|
private
|
|
38
45
|
|
|
46
|
+
def detect_app_name
|
|
47
|
+
Rails.application&.class&.module_parent_name.presence || "App"
|
|
48
|
+
end
|
|
49
|
+
|
|
39
50
|
def built_in_notifiers
|
|
40
51
|
[
|
|
41
52
|
(Notifiers::Slack.new if slack_webhook_url.present?),
|
|
@@ -50,15 +50,23 @@ module RailsInformant
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def build_environment_context
|
|
53
|
-
@_static_env ||=
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
@_static_env ||= begin
|
|
54
|
+
hostname = Socket.gethostname
|
|
55
|
+
env = {
|
|
56
|
+
rails_env: Rails.env.to_s,
|
|
57
|
+
ruby_version: RUBY_VERSION,
|
|
58
|
+
rails_version: Rails::VERSION::STRING
|
|
59
|
+
}
|
|
60
|
+
env[:hostname] = hostname unless hostname == "localhost"
|
|
61
|
+
env.freeze
|
|
62
|
+
end
|
|
59
63
|
@_static_env.merge(pid: Process.pid)
|
|
60
64
|
end
|
|
61
65
|
|
|
66
|
+
def reset!
|
|
67
|
+
@_static_env = nil
|
|
68
|
+
end
|
|
69
|
+
|
|
62
70
|
def group_attributes(error, severity:, context:, env:, now:)
|
|
63
71
|
{
|
|
64
72
|
error_class: error.class.name, severity:,
|
|
@@ -17,39 +17,51 @@ module RailsInformant
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def build_payload(error_group, occurrence)
|
|
20
|
-
regression_tag = regression?(error_group) ? " [REGRESSION]" : ""
|
|
21
|
-
|
|
22
20
|
{
|
|
21
|
+
text: "#{error_group.error_class}: #{error_group.message.to_s.truncate(200)}",
|
|
23
22
|
blocks: [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
type: "plain_text",
|
|
28
|
-
text: "#{error_group.error_class}#{regression_tag}",
|
|
29
|
-
emoji: true
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
type: "section",
|
|
34
|
-
fields: [
|
|
35
|
-
{ type: "mrkdwn", text: "*Message:*\n#{error_group.message.to_s.truncate(200)}" },
|
|
36
|
-
{ type: "mrkdwn", text: "*Status:*\n#{error_group.status}" },
|
|
37
|
-
{ type: "mrkdwn", text: "*Occurrences:*\n#{error_group.total_occurrences}" },
|
|
38
|
-
{ type: "mrkdwn", text: "*First seen:*\n#{error_group.first_seen_at&.iso8601}" }
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
type: "section",
|
|
43
|
-
fields: [
|
|
44
|
-
location_field(error_group),
|
|
45
|
-
{ type: "mrkdwn", text: "*Severity:*\n#{error_group.severity}" }
|
|
46
|
-
].compact
|
|
47
|
-
},
|
|
23
|
+
header_block(error_group, occurrence),
|
|
24
|
+
error_class_block(error_group),
|
|
25
|
+
fields_block(error_group),
|
|
48
26
|
context_block(occurrence)
|
|
49
27
|
].compact
|
|
50
28
|
}
|
|
51
29
|
end
|
|
52
30
|
|
|
31
|
+
def header_block(error_group, occurrence)
|
|
32
|
+
env = occurrence&.environment_context&.dig("rails_env") || Rails.env
|
|
33
|
+
regression_tag = regression?(error_group) ? " [REGRESSION]" : ""
|
|
34
|
+
text = "🚨 #{RailsInformant.app_name} · #{env}#{regression_tag}".truncate(150)
|
|
35
|
+
|
|
36
|
+
{
|
|
37
|
+
type: "header",
|
|
38
|
+
text: { type: "plain_text", text:, emoji: true }
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def error_class_block(error_group)
|
|
43
|
+
{
|
|
44
|
+
type: "section",
|
|
45
|
+
text: {
|
|
46
|
+
type: "mrkdwn",
|
|
47
|
+
text: "*#{error_group.error_class}*\n#{error_group.message.to_s.truncate(200)}"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def fields_block(error_group)
|
|
53
|
+
{
|
|
54
|
+
type: "section",
|
|
55
|
+
fields: [
|
|
56
|
+
{ type: "mrkdwn", text: "*Status:*\n#{error_group.status}" },
|
|
57
|
+
{ type: "mrkdwn", text: "*Occurrences:*\n#{error_group.total_occurrences}" },
|
|
58
|
+
{ type: "mrkdwn", text: "*First seen:*\n#{error_group.first_seen_at&.iso8601}" },
|
|
59
|
+
{ type: "mrkdwn", text: "*Severity:*\n#{error_group.severity}" },
|
|
60
|
+
location_field(error_group)
|
|
61
|
+
].compact
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
53
65
|
def location_field(error_group)
|
|
54
66
|
location = error_group.controller_action || error_group.job_class || error_group.first_backtrace_line
|
|
55
67
|
return unless location
|
|
@@ -58,19 +70,14 @@ module RailsInformant
|
|
|
58
70
|
end
|
|
59
71
|
|
|
60
72
|
def context_block(occurrence)
|
|
61
|
-
return unless occurrence
|
|
62
|
-
|
|
63
|
-
elements = []
|
|
64
|
-
if occurrence.git_sha
|
|
65
|
-
elements << { type: "mrkdwn", text: "Deploy: `#{occurrence.git_sha[0, 7]}`" }
|
|
66
|
-
end
|
|
67
|
-
if occurrence.environment_context&.dig("hostname")
|
|
68
|
-
elements << { type: "mrkdwn", text: "Host: `#{occurrence.environment_context["hostname"]}`" }
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
return if elements.empty?
|
|
73
|
+
return unless occurrence&.git_sha
|
|
72
74
|
|
|
73
|
-
{
|
|
75
|
+
{
|
|
76
|
+
type: "context",
|
|
77
|
+
elements: [
|
|
78
|
+
{ type: "mrkdwn", text: "Deploy: `#{occurrence.git_sha[0, 7]}`" }
|
|
79
|
+
]
|
|
80
|
+
}
|
|
74
81
|
end
|
|
75
82
|
end
|
|
76
83
|
end
|
data/lib/rails_informant.rb
CHANGED