exception_notification 4.6.0 → 5.0.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/CHANGELOG.rdoc +16 -0
- data/CONTRIBUTING.md +23 -51
- data/Gemfile +1 -1
- data/Gemfile.lock +27 -33
- data/README.md +65 -31
- data/Rakefile +14 -7
- data/exception_notification.gemspec +27 -30
- data/gemfiles/pinned_dependencies.gemfile +8 -0
- data/gemfiles/rails7_1.gemfile +5 -0
- data/gemfiles/rails7_2.gemfile +5 -0
- data/gemfiles/rails8_0.gemfile +5 -0
- data/lib/exception_notification/rack.rb +4 -4
- data/lib/exception_notification/rails.rb +2 -2
- data/lib/exception_notification/rake.rb +3 -7
- data/lib/exception_notification/resque.rb +2 -2
- data/lib/exception_notification/sidekiq.rb +8 -23
- data/lib/exception_notification/version.rb +1 -1
- data/lib/exception_notification.rb +3 -3
- data/lib/exception_notifier/datadog_notifier.rb +26 -26
- data/lib/exception_notifier/email_notifier.rb +34 -30
- data/lib/exception_notifier/google_chat_notifier.rb +9 -9
- data/lib/exception_notifier/hipchat_notifier.rb +12 -12
- data/lib/exception_notifier/irc_notifier.rb +6 -6
- data/lib/exception_notifier/mattermost_notifier.rb +13 -13
- data/lib/exception_notifier/modules/error_grouping.rb +5 -5
- data/lib/exception_notifier/modules/formatter.rb +12 -12
- data/lib/exception_notifier/notifier.rb +3 -3
- data/lib/exception_notifier/slack_notifier.rb +16 -16
- data/lib/exception_notifier/sns_notifier.rb +9 -9
- data/lib/exception_notifier/teams_notifier.rb +61 -57
- data/lib/exception_notifier/webhook_notifier.rb +3 -3
- data/lib/exception_notifier.rb +27 -26
- data/lib/generators/exception_notification/install_generator.rb +7 -7
- data/lib/generators/exception_notification/templates/exception_notification.rb.erb +26 -27
- data/test/exception_notification/rack_test.rb +14 -14
- data/test/exception_notification/rake_test.rb +13 -13
- data/test/exception_notification/resque_test.rb +14 -14
- data/test/exception_notifier/datadog_notifier_test.rb +47 -46
- data/test/exception_notifier/email_notifier_test.rb +89 -98
- data/test/exception_notifier/google_chat_notifier_test.rb +77 -77
- data/test/exception_notifier/hipchat_notifier_test.rb +76 -74
- data/test/exception_notifier/irc_notifier_test.rb +26 -26
- data/test/exception_notifier/mattermost_notifier_test.rb +77 -77
- data/test/exception_notifier/modules/error_grouping_test.rb +39 -39
- data/test/exception_notifier/modules/formatter_test.rb +51 -49
- data/test/exception_notifier/sidekiq_test.rb +17 -10
- data/test/exception_notifier/slack_notifier_test.rb +66 -67
- data/test/exception_notifier/sns_notifier_test.rb +73 -70
- data/test/exception_notifier/teams_notifier_test.rb +33 -33
- data/test/exception_notifier/webhook_notifier_test.rb +34 -34
- data/test/exception_notifier_test.rb +51 -41
- data/test/test_helper.rb +8 -11
- metadata +45 -85
- data/Appraisals +0 -9
- data/gemfiles/rails5_2.gemfile +0 -7
- data/gemfiles/rails6_0.gemfile +0 -7
- data/gemfiles/rails6_1.gemfile +0 -7
- data/gemfiles/rails7_0.gemfile +0 -7
@@ -48,15 +48,15 @@ module ExceptionNotification
|
|
48
48
|
def call(env)
|
49
49
|
_, headers, = response = @app.call(env)
|
50
50
|
|
51
|
-
if !@ignore_cascade_pass && headers[
|
51
|
+
if !@ignore_cascade_pass && headers["X-Cascade"] == "pass"
|
52
52
|
msg = "This exception means that the preceding Rack middleware set the 'X-Cascade' header to 'pass' -- in " \
|
53
|
-
|
53
|
+
"Rails, this often means that the route was not found (404 error)."
|
54
54
|
raise CascadePassException, msg
|
55
55
|
end
|
56
56
|
|
57
57
|
response
|
58
|
-
rescue Exception => e
|
59
|
-
env[
|
58
|
+
rescue Exception => e # standard:disable Lint/RescueException
|
59
|
+
env["exception_notifier.delivered"] = true if ExceptionNotifier.notify_exception(e, env: env)
|
60
60
|
|
61
61
|
raise e unless e.is_a?(CascadePassException)
|
62
62
|
|
@@ -15,12 +15,12 @@ module ExceptionNotification
|
|
15
15
|
|
16
16
|
rake_tasks do
|
17
17
|
# Report exceptions occurring in Rake tasks.
|
18
|
-
require
|
18
|
+
require "exception_notification/rake"
|
19
19
|
end
|
20
20
|
|
21
21
|
runner do
|
22
22
|
# Report exceptions occurring in runner commands.
|
23
|
-
require
|
23
|
+
require "exception_notification/rails/runner_tie"
|
24
24
|
Rails::RunnerTie.new.call
|
25
25
|
end
|
26
26
|
end
|
@@ -8,15 +8,12 @@ module ExceptionNotification
|
|
8
8
|
module RakeTaskExtensions
|
9
9
|
# A wrapper around the original +#execute+, that catches all errors and
|
10
10
|
# passes them on to ExceptionNotifier.
|
11
|
-
#
|
12
|
-
# rubocop:disable Lint/RescueException
|
13
11
|
def execute(args = nil)
|
14
|
-
super
|
15
|
-
rescue Exception => e
|
12
|
+
super
|
13
|
+
rescue Exception => e # standard:disable Lint/RescueException
|
16
14
|
ExceptionNotifier.notify_exception(e, data: data_for_exception_notifier(e)) unless e.is_a?(SystemExit)
|
17
15
|
raise e
|
18
16
|
end
|
19
|
-
# rubocop:enable Lint/RescueException
|
20
17
|
|
21
18
|
private
|
22
19
|
|
@@ -45,10 +42,9 @@ module ExceptionNotification
|
|
45
42
|
|
46
43
|
data
|
47
44
|
end
|
48
|
-
# rubocop:enable
|
49
45
|
|
50
46
|
def reconstruct_command_line
|
51
|
-
"rake #{ARGV.join(
|
47
|
+
"rake #{ARGV.join(" ")}"
|
52
48
|
end
|
53
49
|
end
|
54
50
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "resque/failure/base"
|
4
4
|
|
5
5
|
module ExceptionNotification
|
6
6
|
class Resque < Resque::Failure::Base
|
@@ -18,7 +18,7 @@ module ExceptionNotification
|
|
18
18
|
worker: worker.to_s
|
19
19
|
}
|
20
20
|
|
21
|
-
ExceptionNotifier.notify_exception(exception, data: {
|
21
|
+
ExceptionNotifier.notify_exception(exception, data: {resque: data})
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -1,29 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "sidekiq"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
ExceptionNotifier.notify_exception(
|
12
|
-
raise e
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
if ::Sidekiq::VERSION < '3'
|
18
|
-
::Sidekiq.configure_server do |config|
|
19
|
-
config.server_middleware do |chain|
|
20
|
-
chain.add ::ExceptionNotification::Sidekiq
|
21
|
-
end
|
22
|
-
end
|
23
|
-
else
|
24
|
-
::Sidekiq.configure_server do |config|
|
25
|
-
config.error_handlers << proc do |ex, context|
|
26
|
-
ExceptionNotifier.notify_exception(ex, data: { sidekiq: context })
|
5
|
+
::Sidekiq.configure_server do |config|
|
6
|
+
config.error_handlers << proc do |ex, context, config|
|
7
|
+
# Before Sidekiq 7.1.5 the config was not passed to the proc
|
8
|
+
if config
|
9
|
+
ExceptionNotifier.notify_exception(ex, data: {sidekiq: {context: context, config: config}})
|
10
|
+
else
|
11
|
+
ExceptionNotifier.notify_exception(ex, data: {sidekiq: context})
|
27
12
|
end
|
28
13
|
end
|
29
14
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "exception_notifier"
|
4
|
+
require "exception_notification/rack"
|
5
|
+
require "exception_notification/version"
|
6
6
|
|
7
7
|
module ExceptionNotification
|
8
8
|
# Alternative way to setup ExceptionNotification.
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "action_dispatch"
|
4
4
|
|
5
5
|
module ExceptionNotifier
|
6
6
|
class DatadogNotifier < BaseNotifier
|
7
7
|
attr_reader :client,
|
8
|
-
|
8
|
+
:default_options
|
9
9
|
|
10
10
|
def initialize(options)
|
11
11
|
super
|
@@ -32,10 +32,10 @@ module ExceptionNotifier
|
|
32
32
|
MAX_TITLE_LENGTH = 120
|
33
33
|
MAX_VALUE_LENGTH = 300
|
34
34
|
MAX_BACKTRACE_SIZE = 3
|
35
|
-
ALERT_TYPE =
|
35
|
+
ALERT_TYPE = "error"
|
36
36
|
|
37
37
|
attr_reader :exception,
|
38
|
-
|
38
|
+
:options
|
39
39
|
|
40
40
|
def initialize(exception, options)
|
41
41
|
@exception = exception
|
@@ -47,7 +47,7 @@ module ExceptionNotifier
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def controller
|
50
|
-
@controller ||= options[:env] && options[:env][
|
50
|
+
@controller ||= options[:env] && options[:env]["action_controller.instance"]
|
51
51
|
end
|
52
52
|
|
53
53
|
def backtrace
|
@@ -59,7 +59,7 @@ module ExceptionNotifier
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def title_prefix
|
62
|
-
options[:title_prefix] ||
|
62
|
+
options[:title_prefix] || ""
|
63
63
|
end
|
64
64
|
|
65
65
|
def event
|
@@ -85,11 +85,11 @@ module ExceptionNotifier
|
|
85
85
|
def formatted_body
|
86
86
|
text = []
|
87
87
|
|
88
|
-
text <<
|
88
|
+
text << "%%%"
|
89
89
|
text << formatted_request if request
|
90
90
|
text << formatted_session if request
|
91
91
|
text << formatted_backtrace
|
92
|
-
text <<
|
92
|
+
text << "%%%"
|
93
93
|
|
94
94
|
text.join("\n")
|
95
95
|
end
|
@@ -100,24 +100,24 @@ module ExceptionNotifier
|
|
100
100
|
|
101
101
|
def formatted_request
|
102
102
|
text = []
|
103
|
-
text <<
|
104
|
-
text << formatted_key_value(
|
105
|
-
text << formatted_key_value(
|
106
|
-
text << formatted_key_value(
|
107
|
-
text << formatted_key_value(
|
108
|
-
text << formatted_key_value(
|
109
|
-
text << formatted_key_value(
|
110
|
-
text << formatted_key_value(
|
111
|
-
text << formatted_key_value(
|
112
|
-
text <<
|
103
|
+
text << "### **Request**"
|
104
|
+
text << formatted_key_value("URL", request.url)
|
105
|
+
text << formatted_key_value("HTTP Method", request.request_method)
|
106
|
+
text << formatted_key_value("IP Address", request.remote_ip)
|
107
|
+
text << formatted_key_value("Parameters", request.filtered_parameters.inspect)
|
108
|
+
text << formatted_key_value("Timestamp", Time.current)
|
109
|
+
text << formatted_key_value("Server", Socket.gethostname)
|
110
|
+
text << formatted_key_value("Rails root", Rails.root) if defined?(Rails) && Rails.respond_to?(:root)
|
111
|
+
text << formatted_key_value("Process", $PROCESS_ID)
|
112
|
+
text << "___"
|
113
113
|
text.join("\n")
|
114
114
|
end
|
115
115
|
|
116
116
|
def formatted_session
|
117
117
|
text = []
|
118
|
-
text <<
|
119
|
-
text << formatted_key_value(
|
120
|
-
text <<
|
118
|
+
text << "### **Session**"
|
119
|
+
text << formatted_key_value("Data", request.session.to_hash)
|
120
|
+
text << "___"
|
121
121
|
text.join("\n")
|
122
122
|
end
|
123
123
|
|
@@ -125,16 +125,16 @@ module ExceptionNotifier
|
|
125
125
|
size = [backtrace.size, MAX_BACKTRACE_SIZE].min
|
126
126
|
|
127
127
|
text = []
|
128
|
-
text <<
|
129
|
-
text <<
|
128
|
+
text << "### **Backtrace**"
|
129
|
+
text << "````"
|
130
130
|
size.times { |i| text << backtrace[i] }
|
131
|
-
text <<
|
132
|
-
text <<
|
131
|
+
text << "````"
|
132
|
+
text << "___"
|
133
133
|
text.join("\n")
|
134
134
|
end
|
135
135
|
|
136
136
|
def truncate(string, max)
|
137
|
-
string.length > max ? "#{string[0...max]}..." : string
|
137
|
+
(string.length > max) ? "#{string[0...max]}..." : string
|
138
138
|
end
|
139
139
|
|
140
140
|
def inspect_object(object)
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "active_support/core_ext/time"
|
4
|
+
require "action_mailer"
|
5
|
+
require "action_dispatch"
|
6
|
+
require "pp"
|
7
7
|
|
8
8
|
module ExceptionNotifier
|
9
9
|
class EmailNotifier < BaseNotifier
|
10
10
|
DEFAULT_OPTIONS = {
|
11
11
|
sender_address: %("Exception Notifier" <exception.notifier@example.com>),
|
12
12
|
exception_recipients: [],
|
13
|
-
email_prefix:
|
13
|
+
email_prefix: "[ERROR] ",
|
14
14
|
email_format: :text,
|
15
15
|
sections: %w[request session environment backtrace],
|
16
16
|
background_sections: %w[backtrace data],
|
@@ -20,14 +20,18 @@ module ExceptionNotifier
|
|
20
20
|
delivery_method: nil,
|
21
21
|
mailer_settings: nil,
|
22
22
|
email_headers: {},
|
23
|
-
mailer_parent:
|
24
|
-
template_path:
|
23
|
+
mailer_parent: "ActionMailer::Base",
|
24
|
+
template_path: "exception_notifier",
|
25
25
|
deliver_with: nil
|
26
26
|
}.freeze
|
27
27
|
|
28
28
|
module Mailer
|
29
29
|
class MissingController
|
30
|
-
def method_missing(*args, &block)
|
30
|
+
def method_missing(*args, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def respond_to_missing?(*args)
|
34
|
+
end
|
31
35
|
end
|
32
36
|
|
33
37
|
def self.extended(base)
|
@@ -40,18 +44,18 @@ module ExceptionNotifier
|
|
40
44
|
def exception_notification(env, exception, options = {}, default_options = {})
|
41
45
|
load_custom_views
|
42
46
|
|
43
|
-
@env
|
44
|
-
@exception
|
47
|
+
@env = env
|
48
|
+
@exception = exception
|
45
49
|
|
46
|
-
env_options = env[
|
47
|
-
@options
|
50
|
+
env_options = env["exception_notifier.options"] || {}
|
51
|
+
@options = default_options.merge(env_options).merge(options)
|
48
52
|
|
49
|
-
@kontroller = env[
|
50
|
-
@request
|
51
|
-
@backtrace
|
52
|
-
@timestamp
|
53
|
-
@sections
|
54
|
-
@data
|
53
|
+
@kontroller = env["action_controller.instance"] || MissingController.new
|
54
|
+
@request = ActionDispatch::Request.new(env)
|
55
|
+
@backtrace = exception.backtrace ? clean_backtrace(exception) : []
|
56
|
+
@timestamp = Time.current
|
57
|
+
@sections = @options[:sections]
|
58
|
+
@data = (env["exception_notifier.exception_data"] || {}).merge(options[:data] || {})
|
55
59
|
@sections += %w[data] unless @data.empty?
|
56
60
|
|
57
61
|
compose_email
|
@@ -61,11 +65,11 @@ module ExceptionNotifier
|
|
61
65
|
load_custom_views
|
62
66
|
|
63
67
|
@exception = exception
|
64
|
-
@options
|
68
|
+
@options = default_options.merge(options).symbolize_keys
|
65
69
|
@backtrace = exception.backtrace || []
|
66
70
|
@timestamp = Time.current
|
67
|
-
@sections
|
68
|
-
@data
|
71
|
+
@sections = @options[:background_sections]
|
72
|
+
@data = options[:data] || {}
|
69
73
|
@env = @kontroller = nil
|
70
74
|
|
71
75
|
compose_email
|
@@ -80,7 +84,7 @@ module ExceptionNotifier
|
|
80
84
|
subject << " (#{@exception.class})"
|
81
85
|
subject << " #{@exception.message.inspect}" if @options[:verbose_subject]
|
82
86
|
subject = EmailNotifier.normalize_digits(subject) if @options[:normalize_subject]
|
83
|
-
subject.length > 120 ? subject[0...120] +
|
87
|
+
(subject.length > 120) ? subject[0...120] + "..." : subject
|
84
88
|
end
|
85
89
|
|
86
90
|
def include_controller?
|
@@ -89,14 +93,14 @@ module ExceptionNotifier
|
|
89
93
|
|
90
94
|
def set_data_variables
|
91
95
|
@data.each do |name, value|
|
92
|
-
instance_variable_set("@#{name}", value)
|
96
|
+
instance_variable_set(:"@#{name}", value)
|
93
97
|
end
|
94
98
|
end
|
95
99
|
|
96
100
|
helper_method :inspect_object
|
97
101
|
|
98
102
|
def truncate(string, max)
|
99
|
-
string.length > max ? "#{string[0...max]}..." : string
|
103
|
+
(string.length > max) ? "#{string[0...max]}..." : string
|
100
104
|
end
|
101
105
|
|
102
106
|
def inspect_object(object)
|
@@ -111,7 +115,7 @@ module ExceptionNotifier
|
|
111
115
|
helper_method :safe_encode
|
112
116
|
|
113
117
|
def safe_encode(value)
|
114
|
-
value.encode(
|
118
|
+
value.encode("utf-8", invalid: :replace, undef: :replace, replace: "_")
|
115
119
|
end
|
116
120
|
|
117
121
|
def html_mail?
|
@@ -121,7 +125,7 @@ module ExceptionNotifier
|
|
121
125
|
def compose_email
|
122
126
|
set_data_variables
|
123
127
|
subject = compose_subject
|
124
|
-
name = @env.nil? ?
|
128
|
+
name = @env.nil? ? "background_exception_notification" : "exception_notification"
|
125
129
|
exception_recipients = maybe_call(@options[:exception_recipients])
|
126
130
|
|
127
131
|
headers = {
|
@@ -145,7 +149,7 @@ module ExceptionNotifier
|
|
145
149
|
def load_custom_views
|
146
150
|
return unless defined?(Rails) && Rails.respond_to?(:root)
|
147
151
|
|
148
|
-
prepend_view_path Rails.root.nil? ?
|
152
|
+
prepend_view_path Rails.root.nil? ? "app/views" : "#{Rails.root}/app/views"
|
149
153
|
end
|
150
154
|
|
151
155
|
def maybe_call(maybe_proc)
|
@@ -158,8 +162,8 @@ module ExceptionNotifier
|
|
158
162
|
def initialize(options)
|
159
163
|
super
|
160
164
|
|
161
|
-
delivery_method =
|
162
|
-
mailer_settings_key = "#{delivery_method}_settings"
|
165
|
+
delivery_method = options[:delivery_method] || :smtp
|
166
|
+
mailer_settings_key = :"#{delivery_method}_settings"
|
163
167
|
options[:mailer_settings] = options.delete(mailer_settings_key)
|
164
168
|
|
165
169
|
@base_options = DEFAULT_OPTIONS.merge(options)
|
@@ -184,7 +188,7 @@ module ExceptionNotifier
|
|
184
188
|
end
|
185
189
|
|
186
190
|
def self.normalize_digits(string)
|
187
|
-
string.gsub(/[0-9]+/,
|
191
|
+
string.gsub(/[0-9]+/, "N")
|
188
192
|
end
|
189
193
|
|
190
194
|
private
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "httparty"
|
4
4
|
|
5
5
|
module ExceptionNotifier
|
6
6
|
class GoogleChatNotifier < BaseNotifier
|
@@ -10,8 +10,8 @@ module ExceptionNotifier
|
|
10
10
|
|
11
11
|
HTTParty.post(
|
12
12
|
options[:webhook_url],
|
13
|
-
body: {
|
14
|
-
headers: {
|
13
|
+
body: {text: body(exception, formatter)}.to_json,
|
14
|
+
headers: {"Content-Type" => "application/json"}
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
@@ -21,20 +21,20 @@ module ExceptionNotifier
|
|
21
21
|
text = [
|
22
22
|
"\nApplication: *#{formatter.app_name}*",
|
23
23
|
formatter.subtitle,
|
24
|
-
|
24
|
+
"",
|
25
25
|
formatter.title,
|
26
|
-
"*#{exception.message.tr(
|
26
|
+
"*#{exception.message.tr("`", "'")}*"
|
27
27
|
]
|
28
28
|
|
29
29
|
if (request = formatter.request_message.presence)
|
30
|
-
text <<
|
31
|
-
text <<
|
30
|
+
text << ""
|
31
|
+
text << "*Request:*"
|
32
32
|
text << request
|
33
33
|
end
|
34
34
|
|
35
35
|
if (backtrace = formatter.backtrace_message.presence)
|
36
|
-
text <<
|
37
|
-
text <<
|
36
|
+
text << ""
|
37
|
+
text << "*Backtrace:*"
|
38
38
|
text << backtrace
|
39
39
|
end
|
40
40
|
|
@@ -9,26 +9,26 @@ module ExceptionNotifier
|
|
9
9
|
def initialize(options)
|
10
10
|
super
|
11
11
|
begin
|
12
|
-
api_token
|
13
|
-
room_name
|
14
|
-
opts
|
15
|
-
api_version: options.delete(:api_version) ||
|
12
|
+
api_token = options.delete(:api_token)
|
13
|
+
room_name = options.delete(:room_name)
|
14
|
+
opts = {
|
15
|
+
api_version: options.delete(:api_version) || "v1"
|
16
16
|
}
|
17
17
|
opts[:server_url] = options.delete(:server_url) if options[:server_url]
|
18
|
-
@from
|
19
|
-
@room
|
18
|
+
@from = options.delete(:from) || "Exception"
|
19
|
+
@room = HipChat::Client.new(api_token, opts)[room_name]
|
20
20
|
@message_template = options.delete(:message_template) || lambda { |exception, errors_count|
|
21
21
|
msg = if errors_count > 1
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
"The exception occurred #{errors_count} times: '#{Rack::Utils.escape_html(exception.message)}'"
|
23
|
+
else
|
24
|
+
"A new exception occurred: '#{Rack::Utils.escape_html(exception.message)}'"
|
25
|
+
end
|
26
26
|
msg += " on '#{exception.backtrace.first}'" if exception.backtrace
|
27
27
|
msg
|
28
28
|
}
|
29
29
|
@message_options = options
|
30
|
-
@message_options[:color] ||=
|
31
|
-
rescue
|
30
|
+
@message_options[:color] ||= "red"
|
31
|
+
rescue
|
32
32
|
@room = nil
|
33
33
|
end
|
34
34
|
end
|
@@ -18,7 +18,7 @@ module ExceptionNotifier
|
|
18
18
|
return unless active?
|
19
19
|
|
20
20
|
send_notice(exception, options, message) do |msg, _|
|
21
|
-
send_message([*@config.prefix, *msg].join(
|
21
|
+
send_message([*@config.prefix, *msg].join(" "))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -29,20 +29,20 @@ module ExceptionNotifier
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def parse_options(options)
|
32
|
-
nick = options.fetch(:nick,
|
32
|
+
nick = options.fetch(:nick, "ExceptionNotifierBot")
|
33
33
|
password = options[:password] ? ":#{options[:password]}" : nil
|
34
34
|
domain = options.fetch(:domain, nil)
|
35
35
|
port = options[:port] ? ":#{options[:port]}" : nil
|
36
|
-
channel = options.fetch(:channel,
|
36
|
+
channel = options.fetch(:channel, "#log")
|
37
37
|
notice = options.fetch(:notice, false)
|
38
38
|
ssl = options.fetch(:ssl, false)
|
39
39
|
join = options.fetch(:join, false)
|
40
40
|
uri = "irc://#{nick}#{password}@#{domain}#{port}/#{channel}"
|
41
41
|
prefix = options.fetch(:prefix, nil)
|
42
|
-
recipients = options[:recipients] ? options[:recipients].join(
|
42
|
+
recipients = options[:recipients] ? options[:recipients].join(", ") + ":" : nil
|
43
43
|
|
44
|
-
@config.prefix = [*prefix, *recipients].join(
|
45
|
-
@config.irc = {
|
44
|
+
@config.prefix = [*prefix, *recipients].join(" ")
|
45
|
+
@config.irc = {uri: uri, ssl: ssl, notice: notice, join: join}
|
46
46
|
end
|
47
47
|
|
48
48
|
def active?
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "httparty"
|
4
4
|
|
5
5
|
module ExceptionNotifier
|
6
6
|
class MattermostNotifier < BaseNotifier
|
@@ -16,7 +16,7 @@ module ExceptionNotifier
|
|
16
16
|
|
17
17
|
payload = {
|
18
18
|
text: message_text.compact.join("\n"),
|
19
|
-
username: options[:username] ||
|
19
|
+
username: options[:username] || "Exception Notifier"
|
20
20
|
}
|
21
21
|
|
22
22
|
payload[:icon_url] = options[:avatar] if options[:avatar]
|
@@ -29,7 +29,7 @@ module ExceptionNotifier
|
|
29
29
|
|
30
30
|
httparty_options[:body] = payload.to_json
|
31
31
|
httparty_options[:headers] ||= {}
|
32
|
-
httparty_options[:headers][
|
32
|
+
httparty_options[:headers]["Content-Type"] = "application/json"
|
33
33
|
|
34
34
|
HTTParty.post(options[:webhook_url], httparty_options)
|
35
35
|
end
|
@@ -40,24 +40,24 @@ module ExceptionNotifier
|
|
40
40
|
|
41
41
|
def message_text
|
42
42
|
text = [
|
43
|
-
|
43
|
+
"@channel",
|
44
44
|
"### #{formatter.title}",
|
45
45
|
formatter.subtitle,
|
46
46
|
"*#{@exception.message}*"
|
47
47
|
]
|
48
48
|
|
49
49
|
if (request = formatter.request_message.presence)
|
50
|
-
text <<
|
50
|
+
text << "### Request"
|
51
51
|
text << request
|
52
52
|
end
|
53
53
|
|
54
54
|
if (backtrace = formatter.backtrace_message.presence)
|
55
|
-
text <<
|
55
|
+
text << "### Backtrace"
|
56
56
|
text << backtrace
|
57
57
|
end
|
58
58
|
|
59
|
-
if (exception_data = @env[
|
60
|
-
text <<
|
59
|
+
if (exception_data = @env["exception_notifier.exception_data"])
|
60
|
+
text << "### Data"
|
61
61
|
data_string = exception_data.map { |k, v| "* #{k} : #{v}" }.join("\n")
|
62
62
|
text << "```\n#{data_string}\n```"
|
63
63
|
end
|
@@ -68,12 +68,12 @@ module ExceptionNotifier
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def message_issue_link
|
71
|
-
link = [@gitlab_url, formatter.app_name,
|
71
|
+
link = [@gitlab_url, formatter.app_name, "issues", "new"].join("/")
|
72
72
|
params = {
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
"issue[title]" => ["[BUG] Error 500 :",
|
74
|
+
formatter.controller_and_action || "",
|
75
|
+
"(#{@exception.class})",
|
76
|
+
@exception.message].compact.join(" ")
|
77
77
|
}.to_query
|
78
78
|
|
79
79
|
"[Create an issue](#{link}/?#{params})"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/core_ext/numeric/time"
|
5
|
+
require "active_support/concern"
|
6
6
|
|
7
7
|
module ExceptionNotifier
|
8
8
|
module ErrorGrouping
|
@@ -31,7 +31,7 @@ module ExceptionNotifier
|
|
31
31
|
count =
|
32
32
|
begin
|
33
33
|
error_grouping_cache.read(error_key)
|
34
|
-
rescue
|
34
|
+
rescue => e
|
35
35
|
log_cache_error(error_grouping_cache, e, :read)
|
36
36
|
fallback_cache_store.read(error_key)
|
37
37
|
end
|
@@ -41,7 +41,7 @@ module ExceptionNotifier
|
|
41
41
|
|
42
42
|
def save_error_count(error_key, count)
|
43
43
|
error_grouping_cache.write(error_key, count, expires_in: error_grouping_period)
|
44
|
-
rescue
|
44
|
+
rescue => e
|
45
45
|
log_cache_error(error_grouping_cache, e, :write)
|
46
46
|
fallback_cache_store.write(error_key, count, expires_in: error_grouping_period)
|
47
47
|
end
|