exception_notification-lark-notifier 1.0.0 → 1.0.1
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/Gemfile.lock +1 -1
- data/README.md +12 -0
- data/lib/exception_notification-lark-notifier/version.rb +1 -1
- data/lib/exception_notifier/lark_notifier.rb +39 -28
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5f0ab0e3d65f71e4078769b0261b913088a32b48c400e731f6bc88b97db15b9
|
4
|
+
data.tar.gz: e54d66cb04d799fa8f6df66e13b3b5ea2befa83b9f22c75daeff8e6bd5b3aa4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aca1f9d76f52fcdbc8cb5b994862a6b1af7867bc5db0b77ab89fa5f664387ecb9ee095e7795d3a18d2eb4f152b08d9b8c27559c0f1ca4db8fbdbe2b5286db57b
|
7
|
+
data.tar.gz: 7ddb0447939c148d101d174a6c9c2dfc4922e2c8ea71d0be8d7218f425953eab4e9e3faf3bd69187bbb35856e9e5359c66b8e214c93efd98dcfc06a221b4273f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -55,6 +55,18 @@ The Incoming WebHook URL on Lark.
|
|
55
55
|
|
56
56
|
The secret key for *Signature validation*.
|
57
57
|
|
58
|
+
#### app_name
|
59
|
+
|
60
|
+
*String, optional*
|
61
|
+
|
62
|
+
Your application name, shown in the notification.
|
63
|
+
|
64
|
+
#### env_name
|
65
|
+
|
66
|
+
*String, optional*
|
67
|
+
|
68
|
+
Your env name, shown in the notification.
|
69
|
+
|
58
70
|
#### http
|
59
71
|
|
60
72
|
*Hash, optional*
|
@@ -2,19 +2,44 @@ module ExceptionNotifier
|
|
2
2
|
class LarkNotifier
|
3
3
|
include ExceptionNotifier::BacktraceCleaner
|
4
4
|
|
5
|
+
class << self
|
6
|
+
def rails_app_name
|
7
|
+
return unless defined?(::Rails) && ::Rails.respond_to?(:application)
|
8
|
+
if ::Gem::Version.new(::Rails.version) >= ::Gem::Version.new("6.0")
|
9
|
+
::Rails.application.class.module_parent_name
|
10
|
+
else
|
11
|
+
::Rails.application.class.parent_name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def rails_env_name
|
16
|
+
return unless defined?(::Rails) && ::Rails.respond_to?(:env)
|
17
|
+
::Rails.env
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
5
21
|
def initialize(options)
|
6
|
-
@
|
22
|
+
@default_app_name = self.class.rails_app_name
|
23
|
+
@default_env_name = self.class.rails_env_name
|
24
|
+
@default_options = options
|
25
|
+
|
7
26
|
@notifier = ExceptionNotificationLarkNotifier::Client.new(
|
8
27
|
options.slice(:webhook_url, :webhook_secret, :http)
|
9
28
|
)
|
10
29
|
end
|
11
30
|
|
12
|
-
def call(exception,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
31
|
+
def call(exception, call_options = {})
|
32
|
+
options = call_options.merge(@default_options)
|
33
|
+
app_name = options.delete(:app_name) || @default_app_name
|
34
|
+
env_name = options.delete(:env_name) || @default_env_name
|
35
|
+
|
36
|
+
title = "Exception Occurred"
|
37
|
+
title += " in #{app_name}" if app_name
|
38
|
+
title += " (env: #{env_name})" if env_name
|
39
|
+
|
40
|
+
backtrace = exception.backtrace ? clean_backtrace(exception) : []
|
41
|
+
summary, data = information_from_options(exception.class, options)
|
42
|
+
fields = fields(exception.message, backtrace, data)
|
18
43
|
|
19
44
|
@notifier.post interactive: {
|
20
45
|
header: {
|
@@ -22,7 +47,7 @@ module ExceptionNotifier
|
|
22
47
|
},
|
23
48
|
elements: [{
|
24
49
|
tag: "div",
|
25
|
-
text: {tag: "lark_md", content:
|
50
|
+
text: {tag: "lark_md", content: summary},
|
26
51
|
fields: fields
|
27
52
|
}]
|
28
53
|
}
|
@@ -30,26 +55,26 @@ module ExceptionNotifier
|
|
30
55
|
|
31
56
|
private
|
32
57
|
|
33
|
-
def fields(
|
58
|
+
def fields(message, backtrace, data)
|
34
59
|
fields = []
|
35
60
|
|
36
|
-
unless
|
61
|
+
unless message.empty?
|
37
62
|
fields << {is_short: false, text: {tag: "lark_md", content: "**Message:**"}}
|
38
|
-
fields << {is_short: false, text: {tag: "plain_text", content:
|
39
|
-
fields << {is_short: false, text: {tag: "
|
63
|
+
fields << {is_short: false, text: {tag: "plain_text", content: message}}
|
64
|
+
fields << {is_short: false, text: {tag: "plain_text", content: "\n"}}
|
40
65
|
end
|
41
66
|
|
42
67
|
unless backtrace.empty?
|
43
68
|
fields << {is_short: false, text: {tag: "lark_md", content: "**Backtrace:**"}}
|
44
69
|
fields << {is_short: false, text: {tag: "plain_text", content: backtrace.first(10).join("\n")}}
|
45
|
-
fields << {is_short: false, text: {tag: "
|
70
|
+
fields << {is_short: false, text: {tag: "plain_text", content: "\n"}}
|
46
71
|
end
|
47
72
|
|
48
73
|
unless data.empty?
|
49
74
|
data = data.map { |k, v| "#{k}: #{v}" }.join("\n")
|
50
75
|
fields << {is_short: false, text: {tag: "lark_md", content: "**Data:**"}}
|
51
76
|
fields << {is_short: false, text: {tag: "plain_text", content: data}}
|
52
|
-
fields << {is_short: false, text: {tag: "
|
77
|
+
fields << {is_short: false, text: {tag: "plain_text", content: "\n"}}
|
53
78
|
end
|
54
79
|
|
55
80
|
fields
|
@@ -79,19 +104,5 @@ module ExceptionNotifier
|
|
79
104
|
|
80
105
|
[text, data]
|
81
106
|
end
|
82
|
-
|
83
|
-
def rails_app_name
|
84
|
-
return unless defined?(::Rails) && ::Rails.respond_to?(:application)
|
85
|
-
if ::Gem::Version.new(::Rails.version) >= ::Gem::Version.new("6.0")
|
86
|
-
::Rails.application.class.module_parent_name
|
87
|
-
else
|
88
|
-
::Rails.application.class.parent_name
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def rails_env_name
|
93
|
-
return unless defined?(::Rails) && ::Rails.respond_to?(:env)
|
94
|
-
::Rails.env
|
95
|
-
end
|
96
107
|
end
|
97
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exception_notification-lark-notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Doe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: exception_notification
|