prosopite 1.0.7 → 1.1.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/.github/workflows/ci.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +52 -6
- data/lib/prosopite/version.rb +1 -1
- data/lib/prosopite.rb +15 -2
- 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: 5e7209ed5070fd604f22b0e2a6c0256cf3e30bdc9492403f9c427edef00e5a3c
|
4
|
+
data.tar.gz: 75bd921fee0f39354db2fd7a4136f4c32387bd7b2373b5fc34028340105de9e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c393693a5477df4f7e1615c7d67c71cf77b060deb62a8b47e771604b5af5f2a52bcea1639c345173f50d1d11decc263522565cab89a64bea4974a08c6770d8e
|
7
|
+
data.tar.gz: 7eaece0588d418afb0fecc543b697ca3261567d1bed34e549b826800c2861f7be854999accac0b46e96a7bf7a24b00ea5e6485218b566456bfe76bfb7b3b20c6
|
data/.github/workflows/ci.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -115,10 +115,34 @@ Or install it yourself as:
|
|
115
115
|
|
116
116
|
The preferred type of notifications can be configured with:
|
117
117
|
|
118
|
+
* `Prosopite.raise = true`: Raise warnings as exceptions
|
118
119
|
* `Prosopite.rails_logger = true`: Send warnings to the Rails log
|
119
120
|
* `Prosopite.prosopite_logger = true`: Send warnings to `log/prosopite.log`
|
120
121
|
* `Prosopite.stderr_logger = true`: Send warnings to STDERR
|
121
|
-
* `Prosopite.
|
122
|
+
* `Prosopite.custom_logger = my_custom_logger`:
|
123
|
+
|
124
|
+
### Custom Logging Configuration
|
125
|
+
|
126
|
+
You can supply a custom logger with the `Prosopite.custom_logger` setting.
|
127
|
+
|
128
|
+
This is useful for circumstances where you don't want your logs to be
|
129
|
+
highlighted with red, or you want logs sent to a custom location.
|
130
|
+
|
131
|
+
One common scenario is that you may be generating json logs and sending them to
|
132
|
+
Datadog, ELK stack, or similar, and don't want to have to remove the default red
|
133
|
+
escaping data from messages sent to the Rails logger, or want to tag them
|
134
|
+
differently with your own custom logger.
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
# Turns off logging with red highlights, but still sends them to the Rails logger
|
138
|
+
Prosopite.custom_logger = Rails.logger
|
139
|
+
```
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
# Use a completely custom logging instance
|
143
|
+
Prosopite.custom_logger = MyLoggerClass.new
|
144
|
+
|
145
|
+
```
|
122
146
|
|
123
147
|
## Development Environment Usage
|
124
148
|
|
@@ -128,7 +152,7 @@ Prosopite auto-detection can be enabled on all controllers:
|
|
128
152
|
class ApplicationController < ActionController::Base
|
129
153
|
unless Rails.env.production?
|
130
154
|
around_action :n_plus_one_detection
|
131
|
-
|
155
|
+
|
132
156
|
def n_plus_one_detection
|
133
157
|
Prosopite.scan
|
134
158
|
yield
|
@@ -179,10 +203,10 @@ WARNING: scan/finish should run before/after **each** test and NOT before/after
|
|
179
203
|
|
180
204
|
## Allow list
|
181
205
|
|
182
|
-
Ignore notifications for call stacks containing one or more substrings:
|
206
|
+
Ignore notifications for call stacks containing one or more substrings / regex:
|
183
207
|
|
184
208
|
```ruby
|
185
|
-
Prosopite.allow_stack_paths = ['substring_in_call_stack']
|
209
|
+
Prosopite.allow_stack_paths = ['substring_in_call_stack', /regex/]
|
186
210
|
```
|
187
211
|
|
188
212
|
Ignore notifications matching a specific SQL query:
|
@@ -201,11 +225,19 @@ Prosopite.scan
|
|
201
225
|
Prosopite.finish
|
202
226
|
```
|
203
227
|
|
204
|
-
|
228
|
+
In block form the `Prosopite.finish` is called automatically for you at the end of the block:
|
205
229
|
|
206
230
|
```ruby
|
207
231
|
Prosopite.scan do
|
208
|
-
<code to scan>
|
232
|
+
<code to scan>
|
233
|
+
end
|
234
|
+
```
|
235
|
+
|
236
|
+
The result of the code block is also returned by `Prosopite.scan`, so you can wrap calls as follows:
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
my_object = Prosopite.scan do
|
240
|
+
MyObjectFactory.create(params)
|
209
241
|
end
|
210
242
|
```
|
211
243
|
|
@@ -223,6 +255,20 @@ Prosopite.resume
|
|
223
255
|
Prosopite.finish
|
224
256
|
```
|
225
257
|
|
258
|
+
You can also pause items in a block, and the `Prosopite.resume` will be done
|
259
|
+
for you automatically:
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
Prosopite.scan
|
263
|
+
# <code to scan>
|
264
|
+
|
265
|
+
result = Prosopite.pause do
|
266
|
+
# <code that has n+1s>
|
267
|
+
end
|
268
|
+
|
269
|
+
Prosopite.finish
|
270
|
+
```
|
271
|
+
|
226
272
|
An example of when you might use this is if you are [testing Active Jobs inline](https://guides.rubyonrails.org/testing.html#testing-jobs),
|
227
273
|
and don't want to run Prosopite on background job code, just foreground app code. In that case you could write an [Active Job callback](https://edgeguides.rubyonrails.org/active_job_basics.html#callbacks) that pauses the scan while the job is running.
|
228
274
|
|
data/lib/prosopite/version.rb
CHANGED
data/lib/prosopite.rb
CHANGED
@@ -8,6 +8,7 @@ module Prosopite
|
|
8
8
|
:stderr_logger,
|
9
9
|
:rails_logger,
|
10
10
|
:prosopite_logger,
|
11
|
+
:custom_logger,
|
11
12
|
:allow_stack_paths,
|
12
13
|
:ignore_queries
|
13
14
|
|
@@ -33,8 +34,9 @@ module Prosopite
|
|
33
34
|
|
34
35
|
if block_given?
|
35
36
|
begin
|
36
|
-
yield
|
37
|
+
block_result = yield
|
37
38
|
finish
|
39
|
+
block_result
|
38
40
|
ensure
|
39
41
|
tc[:prosopite_scan] = false
|
40
42
|
end
|
@@ -47,6 +49,14 @@ module Prosopite
|
|
47
49
|
|
48
50
|
def pause
|
49
51
|
tc[:prosopite_scan] = false
|
52
|
+
|
53
|
+
if block_given?
|
54
|
+
begin
|
55
|
+
yield
|
56
|
+
ensure
|
57
|
+
tc[:prosopite_scan] = true
|
58
|
+
end
|
59
|
+
end
|
50
60
|
end
|
51
61
|
|
52
62
|
def resume
|
@@ -83,7 +93,7 @@ module Prosopite
|
|
83
93
|
|
84
94
|
kaller = tc[:prosopite_query_caller][location_key]
|
85
95
|
allow_list = (@allow_stack_paths + DEFAULT_ALLOW_LIST)
|
86
|
-
is_allowed = kaller.any? { |f| allow_list.any? { |s| f.
|
96
|
+
is_allowed = kaller.any? { |f| allow_list.any? { |s| f.match?(s) } }
|
87
97
|
|
88
98
|
unless is_allowed
|
89
99
|
queries = tc[:prosopite_query_holder][location_key]
|
@@ -155,6 +165,7 @@ module Prosopite
|
|
155
165
|
end
|
156
166
|
|
157
167
|
def send_notifications
|
168
|
+
@custom_logger ||= false
|
158
169
|
@rails_logger ||= false
|
159
170
|
@stderr_logger ||= false
|
160
171
|
@prosopite_logger ||= false
|
@@ -172,6 +183,8 @@ module Prosopite
|
|
172
183
|
notifications_str << "\n"
|
173
184
|
end
|
174
185
|
|
186
|
+
@custom_logger.warn(notifications_str) if @custom_logger
|
187
|
+
|
175
188
|
Rails.logger.warn(red(notifications_str)) if @rails_logger
|
176
189
|
$stderr.puts(red(notifications_str)) if @stderr_logger
|
177
190
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prosopite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mpampis Kostas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|