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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13adbf148b2adf2f831fdf34c73814362fc2e08dab9564183fb69f193c935a34
4
- data.tar.gz: 77f6661494c46d98e72697fe6816de893e1f66fcf9a06f5bfffa7d9f61095da9
3
+ metadata.gz: 71f2d05d2caf43bbaab7641118f09b86cafb4949d9f4c2be262a4773f6a88eab
4
+ data.tar.gz: 8f3de02212167bfcbbb412d653af259eeed2a0e5907f75b8e1191d724faf112a
5
5
  SHA512:
6
- metadata.gz: c2dbb4db63a9749d40d0b1c8cd46020e400912f409810d266b483c7916384083cdf1ac51a43732fdf5675fe19b09e02b13ec7c31cd49a832a4eeaf4671ff8464
7
- data.tar.gz: a359ac2d32fa026e29d9c53e17551af84cd13b7e4702b8141612ac0b92a0cab41f555ea54419849244f4b62c62d2bae49c6fb198a04bb6471afef7021d50fed9
6
+ metadata.gz: b7c2c8599fe28a7adef712a0cc4f989cdae99465a18b2120055c049dbf77136e243dee9f382fc8dee0ed6d6c7d2d6173a18b1e42a750d031a31268fd377758ff
7
+ data.tar.gz: 59729b6bd6f564023810acd041e3d71f7cf930e8bb65dd88833495b6392d3eb979aa920b80650d4ffe6833f91675743b928a1162ecad4bf10c75c894759843ad
@@ -1,15 +1,18 @@
1
1
  module RailsInformant
2
2
  class Configuration
3
- attr_accessor :api_token,
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
- rails_env: Rails.env.to_s,
55
- ruby_version: RUBY_VERSION,
56
- rails_version: Rails::VERSION::STRING,
57
- hostname: Socket.gethostname
58
- }.freeze
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
- type: "header",
26
- text: {
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
- { type: "context", elements: elements }
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
@@ -57,7 +57,8 @@ module RailsInformant
57
57
  self.config = Configuration.new
58
58
 
59
59
  class << self
60
- delegate :api_token,
60
+ delegate :app_name,
61
+ :api_token,
61
62
  :capture_errors,
62
63
  :capture_user_email,
63
64
  :ignored_exceptions,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-informant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel López Prat