prosopite 1.0.7 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77b0146b180d4bf96cf36dc03c4579f44b7e8aff4693742bfcce6321057027b2
4
- data.tar.gz: 8203dc334b5787907b5d1d25a29927b228f51c62d3814edfacd22424f0a9d20f
3
+ metadata.gz: 5e7209ed5070fd604f22b0e2a6c0256cf3e30bdc9492403f9c427edef00e5a3c
4
+ data.tar.gz: 75bd921fee0f39354db2fd7a4136f4c32387bd7b2373b5fc34028340105de9e8
5
5
  SHA512:
6
- metadata.gz: 07ec42c20dc33120d6ae393f9272aa9bce89d0c18e29544ddbf9d6da02688b110d85700b4d9913ca1abcb6468f0eb57ba1259ff7990ec80f2600e02321845f63
7
- data.tar.gz: c8194ba025357e7afba769c163fad93cc2dfc1adf489d497acc9c94efdd5f50949b724517e8d9032b1e7267e3c4075c51ed67e4a6a63de5139ed284b7277fb51
6
+ metadata.gz: 2c393693a5477df4f7e1615c7d67c71cf77b060deb62a8b47e771604b5af5f2a52bcea1639c345173f50d1d11decc263522565cab89a64bea4974a08c6770d8e
7
+ data.tar.gz: 7eaece0588d418afb0fecc543b697ca3261567d1bed34e549b826800c2861f7be854999accac0b46e96a7bf7a24b00ea5e6485218b566456bfe76bfb7b3b20c6
@@ -4,7 +4,7 @@ jobs:
4
4
  test:
5
5
  strategy:
6
6
  matrix:
7
- ruby: [2.5, 2.6, 2.7, '3.0', head]
7
+ ruby: [2.5, 2.6, 2.7, '3.0', 3.1, head]
8
8
  runs-on: ubuntu-latest
9
9
  steps:
10
10
  - uses: actions/checkout@v2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prosopite (1.0.7)
4
+ prosopite (1.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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.raise = true`: Raise warnings as exceptions
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
- or
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prosopite
4
- VERSION = "1.0.7"
4
+ VERSION = "1.1.1"
5
5
  end
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.include?(s) } }
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.0.7
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-01-20 00:00:00.000000000 Z
11
+ date: 2022-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry