bellman 0.1.0 → 0.1.2
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 +6 -0
- data/lib/bellman/bellman.rb +7 -6
- data/lib/bellman/handlers/handler.rb +14 -6
- data/lib/bellman/handlers/sentry.rb +17 -3
- data/lib/bellman/version.rb +1 -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: c65c02d5ddc7dc46aba77a42fc162c5f35b77bba264a990cc5c66580fd5bd397
|
4
|
+
data.tar.gz: 484d19f9b7546a31599afef4184ecff5a9ef43e24bd6dd46294c532a02707815
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '03491319b209b2994b3329c12aafa4aba3ea3b09bb3046aff6cfc4d0899797748f591384ddc3b6e2df713a00bc7e6921c1b44ef1aa7e2c64d79d6d8a4bf2e2bb'
|
7
|
+
data.tar.gz: 80961f465408e2880701fc8f41f9a21157fa989da5c6d2231f8c53b891bea76ede01177d464c3eaa3962191a028b16e9168cd1f34e30f0de62abfc02ed435918
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -81,6 +81,12 @@ For example, here is a common configuration for when an application uses the Rai
|
|
81
81
|
```ruby
|
82
82
|
Bellman.configure do |config|
|
83
83
|
config.default_severity = :error
|
84
|
+
|
85
|
+
# Anything other than :raise will set the severity level to the default
|
86
|
+
# severity if an unkown one is past. By default Bellman will raise an error
|
87
|
+
# so that you can catch your mistakes in development
|
88
|
+
config.on_unknown_severity = :raise
|
89
|
+
|
84
90
|
config.handlers = [
|
85
91
|
{
|
86
92
|
id: :log,
|
data/lib/bellman/bellman.rb
CHANGED
@@ -19,6 +19,7 @@ module Bellman
|
|
19
19
|
# Set the defaults
|
20
20
|
config.severities = %i[debug info warn error fatal].freeze
|
21
21
|
config.default_severity = :error
|
22
|
+
config.on_unknown_severity = :raise
|
22
23
|
config.handlers = [
|
23
24
|
{
|
24
25
|
id: :log,
|
@@ -38,12 +39,12 @@ module Bellman
|
|
38
39
|
@handler = Handlers::Handler.new
|
39
40
|
end
|
40
41
|
|
41
|
-
def self.handler
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
def self.handler(id: nil)
|
43
|
+
if id.nil?
|
44
|
+
@handler
|
45
|
+
else
|
46
|
+
@handler.handlers.find { |hndlr| hndlr[:id] == id.to_sym }
|
47
|
+
end
|
47
48
|
end
|
48
49
|
|
49
50
|
# rubocop:disable Metrics/ParameterLists
|
@@ -14,10 +14,8 @@ module Bellman
|
|
14
14
|
# rubocop:disable Metrics/ParameterLists
|
15
15
|
def handle(error, severity: :error, trace_id: nil, objects: nil,
|
16
16
|
data: nil, include_backtrace: false, handlers: nil)
|
17
|
-
unless Bellman.config.severities.include?(severity)
|
18
|
-
severity = Bellman.config.default_severity
|
19
|
-
end
|
20
17
|
|
18
|
+
severity = handle_severity(severity)
|
21
19
|
handlers = if handlers.present?
|
22
20
|
process_handlers_config(handlers)
|
23
21
|
else
|
@@ -43,6 +41,16 @@ module Bellman
|
|
43
41
|
|
44
42
|
private
|
45
43
|
|
44
|
+
def handle_severity(severity)
|
45
|
+
return severity if Bellman.config.severities.include?(severity)
|
46
|
+
if Bellman.config.on_unknown_severity != :raise
|
47
|
+
return Bellman.config.default_severity
|
48
|
+
end
|
49
|
+
|
50
|
+
raise "Unknown severity level #{severity}. " \
|
51
|
+
"Must be one of #{Bellman.config.severities}"
|
52
|
+
end
|
53
|
+
|
46
54
|
def process_handlers_config(configs)
|
47
55
|
configs.map { |config| process_handler_config(config) }
|
48
56
|
end
|
@@ -68,7 +76,7 @@ module Bellman
|
|
68
76
|
config[:class].new(**config[:params])
|
69
77
|
end
|
70
78
|
elsif config[:id]
|
71
|
-
config = Bellman.
|
79
|
+
config = Bellman.handler(config[:id])
|
72
80
|
config[:handler] = if config[:params].blank?
|
73
81
|
config[:class].new
|
74
82
|
else
|
@@ -88,12 +96,12 @@ module Bellman
|
|
88
96
|
|
89
97
|
case config
|
90
98
|
when Symbol
|
91
|
-
handler = Bellman.
|
99
|
+
handler = Bellman.handler(id: config)
|
92
100
|
return handler if handler
|
93
101
|
when String
|
94
102
|
# If the string matches the ID of a handler defined in the Bellman
|
95
103
|
# default config, return that.
|
96
|
-
handler = Bellman.
|
104
|
+
handler = Bellman.handler(id: config.to_sym)
|
97
105
|
return handler if handler
|
98
106
|
|
99
107
|
# rubocop:disable Lint/SuppressedException
|
@@ -47,9 +47,23 @@ module Bellman
|
|
47
47
|
private
|
48
48
|
|
49
49
|
def set_sentry_context(scope, objects)
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
# We are organizing the objects by class so that we can send the data
|
51
|
+
# on a per class basis. Note, we cannot just loop over the objects
|
52
|
+
# if we are using the class name as the key since this would mean that
|
53
|
+
# any time there are multiple objects of the same type, we'd only send
|
54
|
+
# the data for the last one as it would overwrite the data.
|
55
|
+
h = {}
|
56
|
+
objects.each do |object|
|
57
|
+
key = object.class.name
|
58
|
+
h[key] = [] unless h.key?(key)
|
59
|
+
h[key] << object
|
60
|
+
end
|
61
|
+
|
62
|
+
h.each do |key, obj_array|
|
63
|
+
scope.set_context(
|
64
|
+
key, { ids: obj_array.map(&:id) }
|
65
|
+
)
|
66
|
+
end
|
53
67
|
end
|
54
68
|
|
55
69
|
def set_sentry_user_and_tags(scope, data)
|
data/lib/bellman/version.rb
CHANGED