bellman 0.1.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 +7 -0
- data/.rubocop.yml +58 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +98 -0
- data/Gemfile.lock +314 -0
- data/LICENSE.txt +21 -0
- data/README.md +154 -0
- data/Rakefile +64 -0
- data/bellman.gemspec +46 -0
- data/lib/bellman/bellman.rb +60 -0
- data/lib/bellman/handlers/base_handler.rb +19 -0
- data/lib/bellman/handlers/handler.rb +121 -0
- data/lib/bellman/handlers/rails_logger.rb +73 -0
- data/lib/bellman/handlers/sentry.rb +66 -0
- data/lib/bellman/version.rb +5 -0
- data/lib/bellman.rb +19 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a729b18b61a082bb6b7c2614885528357e7f4f7c0b04c8059067b86d4ed18c8e
|
4
|
+
data.tar.gz: 4f6247d06e4a57523b0dfd7ecd33f6502bc82ada83e1e596961cdbbee9c04f88
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e515a69379105d8399709472777ef11070c0514cf9f6e1c97a4557cfc2eec9786d3ac666f02a4fe9c8efff00f0bcb2d051de06b4623a923c7e59b9d50338b62
|
7
|
+
data.tar.gz: 0a2dd55ed8d89d9fc43da2db58844a71fa93e699f5536ffb6d36d8aec93ee54a7ceca4bc2e6f56d2446f78616f418af9b8585753cee47ac94fa0430911f0ff12
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require:
|
2
|
+
- 'rubocop-performance'
|
3
|
+
- 'rubocop-rails'
|
4
|
+
- 'rubocop-minitest'
|
5
|
+
- 'rubocop-rake'
|
6
|
+
|
7
|
+
AllCops:
|
8
|
+
NewCops: enable
|
9
|
+
# Don't run rubocop on these files/directories
|
10
|
+
Exclude:
|
11
|
+
- '**/templates/**/*'
|
12
|
+
- '**/vendor/**/*'
|
13
|
+
- 'lib/templates/**/*'
|
14
|
+
- 'db/**/*'
|
15
|
+
- 'config/**/*'
|
16
|
+
- 'vendor/**/*'
|
17
|
+
- 'bin/**/*'
|
18
|
+
- 'test/dummy/**/*'
|
19
|
+
|
20
|
+
Layout/LineLength:
|
21
|
+
Max: 80
|
22
|
+
Exclude:
|
23
|
+
- 'bellman.gemspec'
|
24
|
+
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Max: 30
|
27
|
+
Exclude:
|
28
|
+
- 'test/**/*'
|
29
|
+
|
30
|
+
Metrics/BlockLength:
|
31
|
+
Max: 40
|
32
|
+
Exclude:
|
33
|
+
- 'bellman.gemspec'
|
34
|
+
- 'test/**/*'
|
35
|
+
|
36
|
+
Metrics/ClassLength:
|
37
|
+
Max: 150
|
38
|
+
Exclude:
|
39
|
+
- 'test/**/*'
|
40
|
+
|
41
|
+
Metrics/MethodLength:
|
42
|
+
Max: 35
|
43
|
+
Exclude:
|
44
|
+
- 'test/**/*'
|
45
|
+
|
46
|
+
Metrics/ModuleLength:
|
47
|
+
Max: 100
|
48
|
+
|
49
|
+
Minitest/MultipleAssertions:
|
50
|
+
Max: 10
|
51
|
+
|
52
|
+
Rails/RakeEnvironment:
|
53
|
+
Exclude:
|
54
|
+
- 'Rakefile'
|
55
|
+
|
56
|
+
Rails/RefuteMethods:
|
57
|
+
Exclude:
|
58
|
+
- 'test/**/*'
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bellman
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.2.2
|
data/Gemfile
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in bellman.gemspec
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
gem 'bundler', '~> 2.3'
|
11
|
+
gem 'bundler-audit', '>= 0'
|
12
|
+
gem 'minitest', '~> 5.0'
|
13
|
+
gem 'rake', '~> 13.0'
|
14
|
+
gem 'rubocop', '~> 1.21'
|
15
|
+
gem 'rubocop-minitest', '>= 0'
|
16
|
+
gem 'rubocop-performance', '>= 0'
|
17
|
+
gem 'rubocop-rails', '>= 0'
|
18
|
+
gem 'rubocop-rake', '>= 0'
|
19
|
+
gem 'ruby_audit', '>= 0'
|
20
|
+
|
21
|
+
##
|
22
|
+
## Rails App Gemfile contents
|
23
|
+
##
|
24
|
+
|
25
|
+
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
26
|
+
gem 'rails', '~> 7.1.0'
|
27
|
+
|
28
|
+
# The original asset pipeline for Rails
|
29
|
+
# [https://github.com/rails/sprockets-rails]
|
30
|
+
gem 'sprockets-rails'
|
31
|
+
|
32
|
+
# Use the Puma web server
|
33
|
+
# [https://github.com/puma/puma]
|
34
|
+
gem 'puma', '~> 6.0'
|
35
|
+
|
36
|
+
# Build JSON APIs with ease
|
37
|
+
# [https://github.com/rails/jbuilder]
|
38
|
+
# gem 'jbuilder'
|
39
|
+
|
40
|
+
# Use Kredis to get higher-level data types in Redis
|
41
|
+
# [https://github.com/rails/kredis]
|
42
|
+
# gem "kredis"
|
43
|
+
|
44
|
+
# Use Active Model has_secure_password
|
45
|
+
# [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
|
46
|
+
# gem "bcrypt", "~> 3.1.7"
|
47
|
+
|
48
|
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
49
|
+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
|
50
|
+
|
51
|
+
# Reduces boot times through caching; required in config/boot.rb
|
52
|
+
gem 'bootsnap', require: false
|
53
|
+
|
54
|
+
# Use Sass to process CSS
|
55
|
+
# gem "sassc-rails"
|
56
|
+
|
57
|
+
group :development, :test do
|
58
|
+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
59
|
+
gem 'debug', platforms: %i[mri mingw x64_mingw]
|
60
|
+
end
|
61
|
+
|
62
|
+
group :development do
|
63
|
+
# Use console on exceptions pages [https://github.com/rails/web-console]
|
64
|
+
# gem 'web-console'
|
65
|
+
|
66
|
+
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
|
67
|
+
# gem "rack-mini-profiler"
|
68
|
+
|
69
|
+
# Speed up commands on slow machines / big apps
|
70
|
+
# [https://github.com/rails/spring]
|
71
|
+
# gem "spring"
|
72
|
+
end
|
73
|
+
|
74
|
+
group :test do
|
75
|
+
# Use system testing
|
76
|
+
# [https://guides.rubyonrails.org/testing.html#system-testing]
|
77
|
+
gem 'capybara'
|
78
|
+
gem 'selenium-webdriver'
|
79
|
+
gem 'webdrivers'
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Gem that has been added to default Gemfile so that we can run the tests
|
84
|
+
# for the handlers
|
85
|
+
#
|
86
|
+
|
87
|
+
# rubocop:disable Bundler/OrderedGems
|
88
|
+
# Ruby Error and Performance Monitoring
|
89
|
+
# https://github.com/getsentry/sentry-ruby
|
90
|
+
# NOTE: sentry-rails need to be added after sentry-ruby kindly do not reorder
|
91
|
+
gem 'sentry-ruby'
|
92
|
+
gem 'sentry-rails'
|
93
|
+
gem 'sentry-sidekiq'
|
94
|
+
# rubocop:enable Bundler/OrderedGems
|
95
|
+
|
96
|
+
# Sidekiq for background jobs
|
97
|
+
# https://github.com/mperham/sidekiq
|
98
|
+
gem 'sidekiq'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,314 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bellman (0.1.0)
|
5
|
+
activerecord (> 4.2.0)
|
6
|
+
activesupport (> 4.2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (7.1.2)
|
12
|
+
actionpack (= 7.1.2)
|
13
|
+
activesupport (= 7.1.2)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
zeitwerk (~> 2.6)
|
17
|
+
actionmailbox (7.1.2)
|
18
|
+
actionpack (= 7.1.2)
|
19
|
+
activejob (= 7.1.2)
|
20
|
+
activerecord (= 7.1.2)
|
21
|
+
activestorage (= 7.1.2)
|
22
|
+
activesupport (= 7.1.2)
|
23
|
+
mail (>= 2.7.1)
|
24
|
+
net-imap
|
25
|
+
net-pop
|
26
|
+
net-smtp
|
27
|
+
actionmailer (7.1.2)
|
28
|
+
actionpack (= 7.1.2)
|
29
|
+
actionview (= 7.1.2)
|
30
|
+
activejob (= 7.1.2)
|
31
|
+
activesupport (= 7.1.2)
|
32
|
+
mail (~> 2.5, >= 2.5.4)
|
33
|
+
net-imap
|
34
|
+
net-pop
|
35
|
+
net-smtp
|
36
|
+
rails-dom-testing (~> 2.2)
|
37
|
+
actionpack (7.1.2)
|
38
|
+
actionview (= 7.1.2)
|
39
|
+
activesupport (= 7.1.2)
|
40
|
+
nokogiri (>= 1.8.5)
|
41
|
+
racc
|
42
|
+
rack (>= 2.2.4)
|
43
|
+
rack-session (>= 1.0.1)
|
44
|
+
rack-test (>= 0.6.3)
|
45
|
+
rails-dom-testing (~> 2.2)
|
46
|
+
rails-html-sanitizer (~> 1.6)
|
47
|
+
actiontext (7.1.2)
|
48
|
+
actionpack (= 7.1.2)
|
49
|
+
activerecord (= 7.1.2)
|
50
|
+
activestorage (= 7.1.2)
|
51
|
+
activesupport (= 7.1.2)
|
52
|
+
globalid (>= 0.6.0)
|
53
|
+
nokogiri (>= 1.8.5)
|
54
|
+
actionview (7.1.2)
|
55
|
+
activesupport (= 7.1.2)
|
56
|
+
builder (~> 3.1)
|
57
|
+
erubi (~> 1.11)
|
58
|
+
rails-dom-testing (~> 2.2)
|
59
|
+
rails-html-sanitizer (~> 1.6)
|
60
|
+
activejob (7.1.2)
|
61
|
+
activesupport (= 7.1.2)
|
62
|
+
globalid (>= 0.3.6)
|
63
|
+
activemodel (7.1.2)
|
64
|
+
activesupport (= 7.1.2)
|
65
|
+
activerecord (7.1.2)
|
66
|
+
activemodel (= 7.1.2)
|
67
|
+
activesupport (= 7.1.2)
|
68
|
+
timeout (>= 0.4.0)
|
69
|
+
activestorage (7.1.2)
|
70
|
+
actionpack (= 7.1.2)
|
71
|
+
activejob (= 7.1.2)
|
72
|
+
activerecord (= 7.1.2)
|
73
|
+
activesupport (= 7.1.2)
|
74
|
+
marcel (~> 1.0)
|
75
|
+
activesupport (7.1.2)
|
76
|
+
base64
|
77
|
+
bigdecimal
|
78
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
79
|
+
connection_pool (>= 2.2.5)
|
80
|
+
drb
|
81
|
+
i18n (>= 1.6, < 2)
|
82
|
+
minitest (>= 5.1)
|
83
|
+
mutex_m
|
84
|
+
tzinfo (~> 2.0)
|
85
|
+
addressable (2.8.5)
|
86
|
+
public_suffix (>= 2.0.2, < 6.0)
|
87
|
+
ast (2.4.2)
|
88
|
+
base64 (0.2.0)
|
89
|
+
bigdecimal (3.1.4)
|
90
|
+
bootsnap (1.17.0)
|
91
|
+
msgpack (~> 1.2)
|
92
|
+
builder (3.2.4)
|
93
|
+
bundler-audit (0.9.1)
|
94
|
+
bundler (>= 1.2.0, < 3)
|
95
|
+
thor (~> 1.0)
|
96
|
+
capybara (3.39.2)
|
97
|
+
addressable
|
98
|
+
matrix
|
99
|
+
mini_mime (>= 0.1.3)
|
100
|
+
nokogiri (~> 1.8)
|
101
|
+
rack (>= 1.6.0)
|
102
|
+
rack-test (>= 0.6.3)
|
103
|
+
regexp_parser (>= 1.5, < 3.0)
|
104
|
+
xpath (~> 3.2)
|
105
|
+
concurrent-ruby (1.2.2)
|
106
|
+
connection_pool (2.4.1)
|
107
|
+
crass (1.0.6)
|
108
|
+
date (3.3.4)
|
109
|
+
debug (1.8.0)
|
110
|
+
irb (>= 1.5.0)
|
111
|
+
reline (>= 0.3.1)
|
112
|
+
drb (2.2.0)
|
113
|
+
ruby2_keywords
|
114
|
+
erubi (1.12.0)
|
115
|
+
globalid (1.2.1)
|
116
|
+
activesupport (>= 6.1)
|
117
|
+
i18n (1.14.1)
|
118
|
+
concurrent-ruby (~> 1.0)
|
119
|
+
io-console (0.6.0)
|
120
|
+
irb (1.9.1)
|
121
|
+
rdoc
|
122
|
+
reline (>= 0.3.8)
|
123
|
+
json (2.6.3)
|
124
|
+
language_server-protocol (3.17.0.3)
|
125
|
+
loofah (2.22.0)
|
126
|
+
crass (~> 1.0.2)
|
127
|
+
nokogiri (>= 1.12.0)
|
128
|
+
mail (2.8.1)
|
129
|
+
mini_mime (>= 0.1.1)
|
130
|
+
net-imap
|
131
|
+
net-pop
|
132
|
+
net-smtp
|
133
|
+
marcel (1.0.2)
|
134
|
+
matrix (0.4.2)
|
135
|
+
mini_mime (1.1.5)
|
136
|
+
minitest (5.20.0)
|
137
|
+
msgpack (1.7.2)
|
138
|
+
mutex_m (0.2.0)
|
139
|
+
net-imap (0.4.7)
|
140
|
+
date
|
141
|
+
net-protocol
|
142
|
+
net-pop (0.1.2)
|
143
|
+
net-protocol
|
144
|
+
net-protocol (0.2.2)
|
145
|
+
timeout
|
146
|
+
net-smtp (0.4.0)
|
147
|
+
net-protocol
|
148
|
+
nio4r (2.6.1)
|
149
|
+
nokogiri (1.15.5-x86_64-darwin)
|
150
|
+
racc (~> 1.4)
|
151
|
+
nokogiri (1.15.5-x86_64-linux)
|
152
|
+
racc (~> 1.4)
|
153
|
+
parallel (1.23.0)
|
154
|
+
parser (3.2.2.4)
|
155
|
+
ast (~> 2.4.1)
|
156
|
+
racc
|
157
|
+
psych (5.1.1.1)
|
158
|
+
stringio
|
159
|
+
public_suffix (5.0.4)
|
160
|
+
puma (6.4.0)
|
161
|
+
nio4r (~> 2.0)
|
162
|
+
racc (1.7.3)
|
163
|
+
rack (3.0.8)
|
164
|
+
rack-session (2.0.0)
|
165
|
+
rack (>= 3.0.0)
|
166
|
+
rack-test (2.1.0)
|
167
|
+
rack (>= 1.3)
|
168
|
+
rackup (2.1.0)
|
169
|
+
rack (>= 3)
|
170
|
+
webrick (~> 1.8)
|
171
|
+
rails (7.1.2)
|
172
|
+
actioncable (= 7.1.2)
|
173
|
+
actionmailbox (= 7.1.2)
|
174
|
+
actionmailer (= 7.1.2)
|
175
|
+
actionpack (= 7.1.2)
|
176
|
+
actiontext (= 7.1.2)
|
177
|
+
actionview (= 7.1.2)
|
178
|
+
activejob (= 7.1.2)
|
179
|
+
activemodel (= 7.1.2)
|
180
|
+
activerecord (= 7.1.2)
|
181
|
+
activestorage (= 7.1.2)
|
182
|
+
activesupport (= 7.1.2)
|
183
|
+
bundler (>= 1.15.0)
|
184
|
+
railties (= 7.1.2)
|
185
|
+
rails-dom-testing (2.2.0)
|
186
|
+
activesupport (>= 5.0.0)
|
187
|
+
minitest
|
188
|
+
nokogiri (>= 1.6)
|
189
|
+
rails-html-sanitizer (1.6.0)
|
190
|
+
loofah (~> 2.21)
|
191
|
+
nokogiri (~> 1.14)
|
192
|
+
railties (7.1.2)
|
193
|
+
actionpack (= 7.1.2)
|
194
|
+
activesupport (= 7.1.2)
|
195
|
+
irb
|
196
|
+
rackup (>= 1.0.0)
|
197
|
+
rake (>= 12.2)
|
198
|
+
thor (~> 1.0, >= 1.2.2)
|
199
|
+
zeitwerk (~> 2.6)
|
200
|
+
rainbow (3.1.1)
|
201
|
+
rake (13.1.0)
|
202
|
+
rdoc (6.6.0)
|
203
|
+
psych (>= 4.0.0)
|
204
|
+
redis-client (0.18.0)
|
205
|
+
connection_pool
|
206
|
+
regexp_parser (2.8.2)
|
207
|
+
reline (0.4.1)
|
208
|
+
io-console (~> 0.5)
|
209
|
+
rexml (3.2.6)
|
210
|
+
rubocop (1.57.2)
|
211
|
+
json (~> 2.3)
|
212
|
+
language_server-protocol (>= 3.17.0)
|
213
|
+
parallel (~> 1.10)
|
214
|
+
parser (>= 3.2.2.4)
|
215
|
+
rainbow (>= 2.2.2, < 4.0)
|
216
|
+
regexp_parser (>= 1.8, < 3.0)
|
217
|
+
rexml (>= 3.2.5, < 4.0)
|
218
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
219
|
+
ruby-progressbar (~> 1.7)
|
220
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
221
|
+
rubocop-ast (1.30.0)
|
222
|
+
parser (>= 3.2.1.0)
|
223
|
+
rubocop-minitest (0.33.0)
|
224
|
+
rubocop (>= 1.39, < 2.0)
|
225
|
+
rubocop-performance (1.19.1)
|
226
|
+
rubocop (>= 1.7.0, < 2.0)
|
227
|
+
rubocop-ast (>= 0.4.0)
|
228
|
+
rubocop-rails (2.22.2)
|
229
|
+
activesupport (>= 4.2.0)
|
230
|
+
rack (>= 1.1)
|
231
|
+
rubocop (>= 1.33.0, < 2.0)
|
232
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
233
|
+
rubocop-rake (0.6.0)
|
234
|
+
rubocop (~> 1.0)
|
235
|
+
ruby-progressbar (1.13.0)
|
236
|
+
ruby2_keywords (0.0.5)
|
237
|
+
ruby_audit (2.2.0)
|
238
|
+
bundler-audit (~> 0.9.0)
|
239
|
+
rubyzip (2.3.2)
|
240
|
+
selenium-webdriver (4.10.0)
|
241
|
+
rexml (~> 3.2, >= 3.2.5)
|
242
|
+
rubyzip (>= 1.2.2, < 3.0)
|
243
|
+
websocket (~> 1.0)
|
244
|
+
sentry-rails (5.14.0)
|
245
|
+
railties (>= 5.0)
|
246
|
+
sentry-ruby (~> 5.14.0)
|
247
|
+
sentry-ruby (5.14.0)
|
248
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
249
|
+
sentry-sidekiq (5.14.0)
|
250
|
+
sentry-ruby (~> 5.14.0)
|
251
|
+
sidekiq (>= 3.0)
|
252
|
+
sidekiq (7.2.0)
|
253
|
+
concurrent-ruby (< 2)
|
254
|
+
connection_pool (>= 2.3.0)
|
255
|
+
rack (>= 2.2.4)
|
256
|
+
redis-client (>= 0.14.0)
|
257
|
+
sprockets (4.2.1)
|
258
|
+
concurrent-ruby (~> 1.0)
|
259
|
+
rack (>= 2.2.4, < 4)
|
260
|
+
sprockets-rails (3.4.2)
|
261
|
+
actionpack (>= 5.2)
|
262
|
+
activesupport (>= 5.2)
|
263
|
+
sprockets (>= 3.0.0)
|
264
|
+
stringio (3.1.0)
|
265
|
+
thor (1.3.0)
|
266
|
+
timeout (0.4.1)
|
267
|
+
tzinfo (2.0.6)
|
268
|
+
concurrent-ruby (~> 1.0)
|
269
|
+
unicode-display_width (2.5.0)
|
270
|
+
webdrivers (5.3.1)
|
271
|
+
nokogiri (~> 1.6)
|
272
|
+
rubyzip (>= 1.3.0)
|
273
|
+
selenium-webdriver (~> 4.0, < 4.11)
|
274
|
+
webrick (1.8.1)
|
275
|
+
websocket (1.2.10)
|
276
|
+
websocket-driver (0.7.6)
|
277
|
+
websocket-extensions (>= 0.1.0)
|
278
|
+
websocket-extensions (0.1.5)
|
279
|
+
xpath (3.2.0)
|
280
|
+
nokogiri (~> 1.8)
|
281
|
+
zeitwerk (2.6.12)
|
282
|
+
|
283
|
+
PLATFORMS
|
284
|
+
x86_64-darwin-22
|
285
|
+
x86_64-linux
|
286
|
+
|
287
|
+
DEPENDENCIES
|
288
|
+
bellman!
|
289
|
+
bootsnap
|
290
|
+
bundler (~> 2.3)
|
291
|
+
bundler-audit
|
292
|
+
capybara
|
293
|
+
debug
|
294
|
+
minitest (~> 5.0)
|
295
|
+
puma (~> 6.0)
|
296
|
+
rails (~> 7.1.0)
|
297
|
+
rake (~> 13.0)
|
298
|
+
rubocop (~> 1.21)
|
299
|
+
rubocop-minitest
|
300
|
+
rubocop-performance
|
301
|
+
rubocop-rails
|
302
|
+
rubocop-rake
|
303
|
+
ruby_audit
|
304
|
+
selenium-webdriver
|
305
|
+
sentry-rails
|
306
|
+
sentry-ruby
|
307
|
+
sentry-sidekiq
|
308
|
+
sidekiq
|
309
|
+
sprockets-rails
|
310
|
+
tzinfo-data
|
311
|
+
webdrivers
|
312
|
+
|
313
|
+
BUNDLED WITH
|
314
|
+
2.4.10
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
# Bellman
|
2
|
+
|
3
|
+
[](https://dl.circleci.com/status-badge/redirect/gh/prschmid/bellman/tree/main)
|
4
|
+
[](https://badge.fury.io/rb/bellman)
|
5
|
+
|
6
|
+
A simple and unified way to send log messages to the right place.
|
7
|
+
|
8
|
+
Why is this gem called Bellman? For historical details on a [bellman/town crier](https://en.wikipedia.org/wiki/Town_crier).
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Install the gem and add it to the application's Gemfile by executing:
|
13
|
+
|
14
|
+
$ bundle add bellman
|
15
|
+
|
16
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
17
|
+
|
18
|
+
$ gem install bellman
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Simply replace any call to a logger with
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# Use the default severity
|
26
|
+
Bellman.handle('Log this error message')
|
27
|
+
|
28
|
+
# Set the severity
|
29
|
+
Bellman.handle('Log this info message', severity: info)
|
30
|
+
```
|
31
|
+
|
32
|
+
And then based on your configuration this message will be sent to the right place. By default the severity level for a message is set to `:error`, but that can easily be configured or overridden on a case by case basis.
|
33
|
+
|
34
|
+
### Including Data
|
35
|
+
|
36
|
+
In many cases you will want to add some extra data to your log messages. The log messages are formatted in such a way that it should be easy to pull the extra information out with regular expressions, etc.
|
37
|
+
|
38
|
+
You can add arbitrary data to the log message as follows:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Bellman.handle(
|
42
|
+
'Something you should know about',
|
43
|
+
severity: :info,
|
44
|
+
data: {
|
45
|
+
favorite_food: 'Ice Cream'
|
46
|
+
}
|
47
|
+
)
|
48
|
+
```
|
49
|
+
|
50
|
+
This will result in a message that looks like
|
51
|
+
|
52
|
+
```sh
|
53
|
+
INFO | Something you should know about | DATA[{"favorite_food":"Ice Cream"}]
|
54
|
+
```
|
55
|
+
|
56
|
+
If there is a case where you want to add some objects to this log message, you can do this by passing them in.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
project = Project.last
|
60
|
+
task = project.tasks.last
|
61
|
+
|
62
|
+
Bellman.handle(
|
63
|
+
'Something you should know about',
|
64
|
+
severity: :info,
|
65
|
+
objecst: [project, task]
|
66
|
+
)
|
67
|
+
```
|
68
|
+
|
69
|
+
Assuming you are using UUIDs, this will result in a message that will look something like
|
70
|
+
|
71
|
+
```sh
|
72
|
+
INFO | Something you should know about | OBJECTS["Project|6a491e9d-ceb7-41fd-97ef-6cd8a6460242", "Task|ab30e8c7-eabf-4c95-ba97-a523bf017093"]
|
73
|
+
```
|
74
|
+
|
75
|
+
## Configuration
|
76
|
+
|
77
|
+
The aim of `bellman` is to take the guesswork out of where to send the logs and have it be configured in a uniform way for an entire application.
|
78
|
+
|
79
|
+
For example, here is a common configuration for when an application uses the Rails logger to send all logs to a centralized logging store (e.g. Papertrail, Sumo Logic, etc.) and then sends only the "high severity" ones to Sentry.io.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
Bellman.configure do |config|
|
83
|
+
config.default_severity = :error
|
84
|
+
config.handlers = [
|
85
|
+
{
|
86
|
+
id: :log,
|
87
|
+
class: Bellman::Handlers::RailsLogger,
|
88
|
+
severities: %i[debug info warn error fatal]
|
89
|
+
},
|
90
|
+
{
|
91
|
+
id: :sentry,
|
92
|
+
class: Bellman::Handlers::Sentry,
|
93
|
+
severities: %i[error fatal]
|
94
|
+
}
|
95
|
+
]
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
If for some reason you want to pass parameters to a handler while it is being initialized (e.g. if you make your own custom handler) you can do this by passing in `params` as follows:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
Bellman.configure do |config|
|
103
|
+
config.default_severity = :error
|
104
|
+
config.handlers = [
|
105
|
+
{
|
106
|
+
id: :custom_handler,
|
107
|
+
class: Acme::Handlers::CustomHandler,
|
108
|
+
params: {
|
109
|
+
some_option: 'foo',
|
110
|
+
other_option: 'bar'
|
111
|
+
},
|
112
|
+
severities: %i[debug info warn error fatal]
|
113
|
+
}
|
114
|
+
]
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
## Handlers
|
119
|
+
|
120
|
+
### Predefined Handlers
|
121
|
+
|
122
|
+
Built-in are 2 pre-defined handlers for handling log message
|
123
|
+
|
124
|
+
* `Bellman::Handlers::RailsLogger`: Send the log message to the Rails logger
|
125
|
+
* `Bellman::Handlers::Sentry`: Send the log message to Sentry.io
|
126
|
+
|
127
|
+
## Custom Handlers
|
128
|
+
|
129
|
+
Need a specific handler that's not built in? One can easily create a new log handler by simply inheriting from `Bellman::BaseHandler` and implementing the one method
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
def handle(
|
133
|
+
error, severity: nil, trace_id: nil, objects: nil, data: nil,
|
134
|
+
include_backtrace: false
|
135
|
+
)
|
136
|
+
raise 'Not implemented'
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
140
|
+
Once that is created, go ahead and add it to the configuration (see above).
|
141
|
+
|
142
|
+
## Development
|
143
|
+
|
144
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
145
|
+
|
146
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
147
|
+
|
148
|
+
## Contributing
|
149
|
+
|
150
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/prschmid/bellman.
|
151
|
+
|
152
|
+
## License
|
153
|
+
|
154
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.verbose = false
|
8
|
+
t.libs << 'test'
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.libs << 'test/dummy'
|
11
|
+
|
12
|
+
# We will include all of the files in test but are going to explicitly
|
13
|
+
# exclude all tests in rails. This is because we copy those files
|
14
|
+
# to the dummy Rails app so that we can test the Rails specific handlers
|
15
|
+
# in the context of a Rails app. See the `generate_dummy_rails_app` for
|
16
|
+
# more details
|
17
|
+
t.test_files = \
|
18
|
+
FileList['test/**/*_test.rb'].exclude('test/rails/**/*_test.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'generate a dummy Rails app inside the test directory for testing purposes'
|
22
|
+
task :generate_dummy_rails_app do
|
23
|
+
if File.exist?('test/dummy/config/environment.rb')
|
24
|
+
FileUtils.rm_r Dir.glob('test/dummy/')
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Create a dummy rails app
|
29
|
+
#
|
30
|
+
system(
|
31
|
+
'rails new test/dummy --skip-active-record ' \
|
32
|
+
'--skip-active-storage --skip-action-cable --skip-webpack-install ' \
|
33
|
+
'--skip-git --skip-sprockets --skip-javascript --skip-turbolinks'
|
34
|
+
)
|
35
|
+
|
36
|
+
# For now we don't need any DB specific things in our tests. However, if
|
37
|
+
# we ever do, we can update how we generate the rails app and then setup
|
38
|
+
# the DB appropriately using something like the following.
|
39
|
+
# system('rails new test/dummy --database=sqlite3')
|
40
|
+
# system('touch test/dummy/db/schema.rb')
|
41
|
+
# FileUtils.cp 'test/fixtures/database.yml', 'test/dummy/config/'
|
42
|
+
|
43
|
+
#
|
44
|
+
# Install/Setup the dependencies
|
45
|
+
#
|
46
|
+
|
47
|
+
system('cp -f test/rails/Gemfile test/dummy/.')
|
48
|
+
system(
|
49
|
+
'cp test/rails/config/initializers/*.rb test/dummy/config/initializers/.'
|
50
|
+
)
|
51
|
+
|
52
|
+
#
|
53
|
+
# Setup the tests by deleting the existing Rails app tests and then copying
|
54
|
+
# our test over to the dummy app
|
55
|
+
#
|
56
|
+
|
57
|
+
FileUtils.rm_r Dir.glob('test/dummy/test/*')
|
58
|
+
system('cp -r test/rails/test/lib test/dummy/test/.')
|
59
|
+
end
|
60
|
+
|
61
|
+
require 'rubocop/rake_task'
|
62
|
+
RuboCop::RakeTask.new
|
63
|
+
|
64
|
+
task default: %i[generate_dummy_rails_app test rubocop]
|
data/bellman.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'bellman/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'bellman'
|
9
|
+
spec.version = Bellman::VERSION
|
10
|
+
spec.authors = ['Patrick R. Schmid']
|
11
|
+
spec.email = ['prschmid@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Unified way to take all of the log messages and direct them to the right place.'
|
14
|
+
spec.description = 'Unified way to take all of the log messages and direct them to the right place.'
|
15
|
+
spec.homepage = 'https://github.com/prschmid/bellman'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the
|
19
|
+
# 'allowed_push_host' to allow pushing to a single host or delete this
|
20
|
+
# section to allow pushing to any host.
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
23
|
+
spec.metadata['source_code_uri'] = 'https://github.com/prschmid/bellman'
|
24
|
+
spec.metadata['changelog_uri'] = 'https://github.com/prschmid/bellman'
|
25
|
+
else
|
26
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
27
|
+
'public gem pushes.'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(__dir__) do
|
33
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
34
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
spec.bindir = 'exe'
|
38
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
39
|
+
spec.require_paths = ['lib']
|
40
|
+
|
41
|
+
spec.required_ruby_version = '>= 3.2'
|
42
|
+
|
43
|
+
spec.add_runtime_dependency('activerecord', '> 4.2.0')
|
44
|
+
spec.add_runtime_dependency('activesupport', '> 4.2.0')
|
45
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
46
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Bellman
|
4
|
+
#
|
5
|
+
# Unified way to take all of the log messages and direct them to the right
|
6
|
+
# place.
|
7
|
+
#
|
8
|
+
# By default all messages will be logged using the Rails standard logger and
|
9
|
+
# any message with severity of :error or :fatal will also be sent to
|
10
|
+
# Sentry.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# For historical details on a bellman/town crier see:
|
14
|
+
# https://en.wikipedia.org/wiki/Town_crier
|
15
|
+
module Bellman
|
16
|
+
include ActiveSupport::Configurable
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
# Set the defaults
|
20
|
+
config.severities = %i[debug info warn error fatal].freeze
|
21
|
+
config.default_severity = :error
|
22
|
+
config.handlers = [
|
23
|
+
{
|
24
|
+
id: :log,
|
25
|
+
class: Bellman::Handlers::RailsLogger,
|
26
|
+
severities: %i[debug info warn error fatal]
|
27
|
+
},
|
28
|
+
{
|
29
|
+
id: :sentry,
|
30
|
+
class: Bellman::Handlers::Sentry,
|
31
|
+
severities: %i[error fatal]
|
32
|
+
}
|
33
|
+
]
|
34
|
+
|
35
|
+
super
|
36
|
+
|
37
|
+
# Create an instance of the handler that can be used
|
38
|
+
@handler = Handlers::Handler.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.handler
|
42
|
+
@handler
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.error_handler(id:)
|
46
|
+
@handler.handlers.find { |hndlr| hndlr[:id] == id.to_sym }
|
47
|
+
end
|
48
|
+
|
49
|
+
# rubocop:disable Metrics/ParameterLists
|
50
|
+
def self.handle(
|
51
|
+
error, severity: nil, trace_id: nil, objects: nil, data: nil,
|
52
|
+
include_backtrace: false, handlers: nil
|
53
|
+
)
|
54
|
+
@handler.handle(
|
55
|
+
error, severity:, trace_id:, objects:, data:, include_backtrace:,
|
56
|
+
handlers:
|
57
|
+
)
|
58
|
+
end
|
59
|
+
# rubocop:enable Metrics/ParameterLists
|
60
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bellman
|
4
|
+
module Handlers
|
5
|
+
# Base class for all error handlers
|
6
|
+
class BaseHandler
|
7
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
8
|
+
# rubocop:disable Metrics/ParameterLists
|
9
|
+
def handle(
|
10
|
+
_error, severity: nil, trace_id: nil, objects: nil, data: nil,
|
11
|
+
include_backtrace: false
|
12
|
+
)
|
13
|
+
raise 'Not implemented'
|
14
|
+
end
|
15
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
16
|
+
# rubocop:enable Metrics/ParameterLists
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bellman
|
4
|
+
module Handlers
|
5
|
+
# Main interface for interacting with all of the registerd handlers
|
6
|
+
class Handler
|
7
|
+
attr_reader :handlers
|
8
|
+
|
9
|
+
def initialize(handlers: nil)
|
10
|
+
handlers ||= Bellman.config.handlers
|
11
|
+
@handlers = process_handlers_config(handlers)
|
12
|
+
end
|
13
|
+
|
14
|
+
# rubocop:disable Metrics/ParameterLists
|
15
|
+
def handle(error, severity: :error, trace_id: nil, objects: nil,
|
16
|
+
data: nil, include_backtrace: false, handlers: nil)
|
17
|
+
unless Bellman.config.severities.include?(severity)
|
18
|
+
severity = Bellman.config.default_severity
|
19
|
+
end
|
20
|
+
|
21
|
+
handlers = if handlers.present?
|
22
|
+
process_handlers_config(handlers)
|
23
|
+
else
|
24
|
+
@handlers
|
25
|
+
end
|
26
|
+
|
27
|
+
handled = false
|
28
|
+
handlers.each do |handler|
|
29
|
+
next unless handler[:severities].include?(severity)
|
30
|
+
|
31
|
+
raise "No handler specificed in #{handler}" unless handler[:handler]
|
32
|
+
|
33
|
+
handler[:handler].handle(
|
34
|
+
error, severity:, trace_id:, objects:, data:, include_backtrace:
|
35
|
+
)
|
36
|
+
|
37
|
+
handled = true
|
38
|
+
end
|
39
|
+
|
40
|
+
handled
|
41
|
+
end
|
42
|
+
# rubocop:enable Metrics/ParameterLists
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def process_handlers_config(configs)
|
47
|
+
configs.map { |config| process_handler_config(config) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_handler_config(config)
|
51
|
+
config = to_handler_config(config) unless config.is_a?(Hash)
|
52
|
+
|
53
|
+
initalize_from_config_hash(config)
|
54
|
+
end
|
55
|
+
|
56
|
+
# rubocop:disable Metrics/AbcSize
|
57
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
58
|
+
def initalize_from_config_hash(config)
|
59
|
+
if config[:handler]
|
60
|
+
config[:class] = config[:handler].class
|
61
|
+
elsif config[:class]
|
62
|
+
if config[:class].is_a?(String)
|
63
|
+
config[:class] = config[:class].safe_constantize
|
64
|
+
end
|
65
|
+
config[:handler] = if config[:params].blank?
|
66
|
+
config[:class].new
|
67
|
+
else
|
68
|
+
config[:class].new(**config[:params])
|
69
|
+
end
|
70
|
+
elsif config[:id]
|
71
|
+
config = Bellman.error_handler(config[:id])
|
72
|
+
config[:handler] = if config[:params].blank?
|
73
|
+
config[:class].new
|
74
|
+
else
|
75
|
+
config[:class].new(**config[:params])
|
76
|
+
end
|
77
|
+
else
|
78
|
+
raise "Bellman: Could not initialize handler from config: #{config}"
|
79
|
+
end
|
80
|
+
config
|
81
|
+
end
|
82
|
+
# rubocop:enable Metrics/AbcSize
|
83
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
84
|
+
|
85
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
86
|
+
def to_handler_config(config)
|
87
|
+
retval = { severities: Bellman.config.severities }
|
88
|
+
|
89
|
+
case config
|
90
|
+
when Symbol
|
91
|
+
handler = Bellman.error_handler(id: config)
|
92
|
+
return handler if handler
|
93
|
+
when String
|
94
|
+
# If the string matches the ID of a handler defined in the Bellman
|
95
|
+
# default config, return that.
|
96
|
+
handler = Bellman.error_handler(id: config.to_sym)
|
97
|
+
return handler if handler
|
98
|
+
|
99
|
+
# rubocop:disable Lint/SuppressedException
|
100
|
+
begin
|
101
|
+
retval[:class] = config.safe_constantize
|
102
|
+
rescue StandardError
|
103
|
+
end
|
104
|
+
# rubocop:enable Lint/SuppressedException
|
105
|
+
when Class
|
106
|
+
retval[:class] = config
|
107
|
+
when BaseHandler
|
108
|
+
retval[:class] = config.class
|
109
|
+
else
|
110
|
+
raise 'Bellman: Unsupported handler. Handlers ' \
|
111
|
+
'must be an array of strings, classes, ' \
|
112
|
+
'or instances of Bellman::BaseHandler: ' \
|
113
|
+
"#{config}"
|
114
|
+
end
|
115
|
+
|
116
|
+
retval
|
117
|
+
end
|
118
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bellman
|
4
|
+
module Handlers
|
5
|
+
# Handle Rails logging
|
6
|
+
class RailsLogger < BaseHandler
|
7
|
+
def initialize(logger: nil)
|
8
|
+
super()
|
9
|
+
@logger = logger
|
10
|
+
end
|
11
|
+
|
12
|
+
# rubocop:disable Metrics/ParameterLists
|
13
|
+
def handle(
|
14
|
+
error, severity: nil, trace_id: nil, objects: nil, data: nil,
|
15
|
+
include_backtrace: false
|
16
|
+
)
|
17
|
+
logger.send(
|
18
|
+
severity,
|
19
|
+
build_message(
|
20
|
+
error, severity:, trace_id:, objects:, data:, include_backtrace:
|
21
|
+
)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
# rubocop:enable Metrics/ParameterLists
|
25
|
+
|
26
|
+
def logger
|
27
|
+
@logger || Rails.logger
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
33
|
+
# rubocop:disable Metrics/ParameterLists
|
34
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
35
|
+
def build_message(
|
36
|
+
error, severity: nil, trace_id: nil, data: nil, objects: nil,
|
37
|
+
include_backtrace: false
|
38
|
+
)
|
39
|
+
str = severity_to_s(severity)
|
40
|
+
str = "#{str} | TRACE_ID[#{trace_id}]" if trace_id
|
41
|
+
|
42
|
+
unless error.nil?
|
43
|
+
str = if error.respond_to?(:message)
|
44
|
+
"#{str} | #{error.message}"
|
45
|
+
else
|
46
|
+
"#{str} | #{error}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
str = "#{str} | #{objects_to_s(objects)}" if objects
|
50
|
+
str = "#{str} | DATA[#{data.to_json}]" if data
|
51
|
+
if !error.nil? && include_backtrace && error.respond_to?(:backtrace)
|
52
|
+
str = "#{str} | #{error.backtrace}"
|
53
|
+
end
|
54
|
+
str
|
55
|
+
end
|
56
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
57
|
+
# rubocop:enable Metrics/ParameterLists
|
58
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
59
|
+
|
60
|
+
def severity_to_s(severity)
|
61
|
+
Bellman.config.default_severity.to_s.upcase.to_s unless severity
|
62
|
+
|
63
|
+
severity.to_s.upcase.to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
def objects_to_s(objects)
|
67
|
+
"OBJECTS#{objects.map do |object|
|
68
|
+
"#{object.class.name}|#{object.id}"
|
69
|
+
end}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bellman
|
4
|
+
module Handlers
|
5
|
+
# Handle Sentry logging
|
6
|
+
class Sentry < BaseHandler
|
7
|
+
OBJECT_KEYS = [:profile_id, 'profile_id'].freeze
|
8
|
+
|
9
|
+
def initialize(sentry: nil)
|
10
|
+
super()
|
11
|
+
@sentry = sentry
|
12
|
+
end
|
13
|
+
|
14
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
15
|
+
# rubocop:disable Metrics/ParameterLists
|
16
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
17
|
+
def handle(
|
18
|
+
error, severity: nil, trace_id: nil, objects: nil, data: nil, **
|
19
|
+
)
|
20
|
+
sentry.with_scope do |scope|
|
21
|
+
scope.set_level(severity)
|
22
|
+
set_sentry_context(scope, objects) if objects.present?
|
23
|
+
|
24
|
+
if trace_id
|
25
|
+
data ||= {}
|
26
|
+
data[:trace_id] = trace_id
|
27
|
+
end
|
28
|
+
|
29
|
+
set_sentry_user_and_tags(scope, data) if data.present?
|
30
|
+
|
31
|
+
error = '[EMPTY MESSAGE]' if error.nil?
|
32
|
+
if error.respond_to?(:message) && error.respond_to?(:backtrace)
|
33
|
+
sentry.capture_exception(error)
|
34
|
+
else
|
35
|
+
sentry.capture_message(error.to_s)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
40
|
+
# rubocop:enable Metrics/ParameterLists
|
41
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
42
|
+
|
43
|
+
def sentry
|
44
|
+
@sentry || ::Sentry
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def set_sentry_context(scope, objects)
|
50
|
+
scope.set_context(
|
51
|
+
objects: objects.map { |object| "#{object.class.name}|#{object.id}" }
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_sentry_user_and_tags(scope, data)
|
56
|
+
data = data.with_indifferent_access
|
57
|
+
scope.set_user(id: data[:profile_id]) if data[:profile_id]
|
58
|
+
data.each do |key, val|
|
59
|
+
next if OBJECT_KEYS.include? key
|
60
|
+
|
61
|
+
scope.send(:set_tags, **{ key => val })
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/bellman.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bellman/version'
|
4
|
+
|
5
|
+
directories = [
|
6
|
+
File.join(File.dirname(__FILE__), 'bellman'),
|
7
|
+
File.join(File.dirname(__FILE__), 'bellman', 'handlers')
|
8
|
+
]
|
9
|
+
|
10
|
+
directories.each do |directory|
|
11
|
+
Dir[File.join(directory, '*.rb')].each do |file|
|
12
|
+
require file
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ActiveRecord::Base.instance_eval { include Bellman }
|
17
|
+
if defined?(Rails) && Rails.version.to_i < 4
|
18
|
+
raise 'This version of bellman requires Rails 4 or higher'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bellman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick R. Schmid
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.2.0
|
41
|
+
description: Unified way to take all of the log messages and direct them to the right
|
42
|
+
place.
|
43
|
+
email:
|
44
|
+
- prschmid@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- ".ruby-gemset"
|
51
|
+
- ".ruby-version"
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bellman.gemspec
|
58
|
+
- lib/bellman.rb
|
59
|
+
- lib/bellman/bellman.rb
|
60
|
+
- lib/bellman/handlers/base_handler.rb
|
61
|
+
- lib/bellman/handlers/handler.rb
|
62
|
+
- lib/bellman/handlers/rails_logger.rb
|
63
|
+
- lib/bellman/handlers/sentry.rb
|
64
|
+
- lib/bellman/version.rb
|
65
|
+
homepage: https://github.com/prschmid/bellman
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata:
|
69
|
+
homepage_uri: https://github.com/prschmid/bellman
|
70
|
+
source_code_uri: https://github.com/prschmid/bellman
|
71
|
+
changelog_uri: https://github.com/prschmid/bellman
|
72
|
+
rubygems_mfa_required: 'true'
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.2'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.4.10
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Unified way to take all of the log messages and direct them to the right
|
92
|
+
place.
|
93
|
+
test_files: []
|