prosopite 1.3.2 → 1.4.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +32 -0
- data/lib/prosopite/middleware/rack.rb +13 -0
- data/lib/prosopite/middleware/sidekiq.rb +14 -0
- data/lib/prosopite/version.rb +1 -1
- data/lib/prosopite.rb +24 -8
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b53b2e152727ab756b2ddb8ae7b34e36c82f0bdb84a59a7345cdf3a8866daf88
|
4
|
+
data.tar.gz: b7aed1d1436d6fb14347b826eed46802ee7c0bb9069a22cdf4bf01d5ce1fbad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c42247c6d608841951aeec07580528578581856dff3f24a0bd72655036c9aace5de4db18587e2db489e6f5a44662531b45e0a2ec900da37e65d3c3e2a1c10a3e
|
7
|
+
data.tar.gz: b164c81ea349b7b537e09c286110316fe8d36b5b2343df425543786ef92f7448d6e1632d792a37146f2af77d418f9bb17a1dbe8c146af643f2c2362fe9bf99b3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -122,6 +122,7 @@ The preferred type of notifications can be configured with:
|
|
122
122
|
* `Prosopite.stderr_logger = true`: Send warnings to STDERR
|
123
123
|
* `Prosopite.backtrace_cleaner = my_custom_backtrace_cleaner`: use a different [ActiveSupport::BacktraceCleaner](https://api.rubyonrails.org/classes/ActiveSupport/BacktraceCleaner.html). Defaults to `Rails.backtrace_cleaner`.
|
124
124
|
* `Prosopite.custom_logger = my_custom_logger`:
|
125
|
+
* `Prosopite.enabled = true`: Enables or disables the gem. Defaults to `true`.
|
125
126
|
|
126
127
|
### Custom Logging Configuration
|
127
128
|
|
@@ -203,6 +204,37 @@ end
|
|
203
204
|
|
204
205
|
WARNING: scan/finish should run before/after **each** test and NOT before/after the whole suite.
|
205
206
|
|
207
|
+
## Middleware
|
208
|
+
|
209
|
+
### Rack
|
210
|
+
|
211
|
+
Instead of using an `around_action` hook in a Rails Controller, you can also use the rack middleware instead
|
212
|
+
implementing auto detect for all controllers.
|
213
|
+
|
214
|
+
Add the following line into your `config/initializers/prosopite.rb` file.
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
unless Rails.production?
|
218
|
+
require 'prosopite/middleware/rack'
|
219
|
+
Rails.configuration.middleware.use(Prosopite::Middleware::Rack)
|
220
|
+
end
|
221
|
+
|
222
|
+
|
223
|
+
### Sidekiq
|
224
|
+
We also provide a middleware for sidekiq so that you can auto detect n+1 queries that may occur in a sidekiq job.
|
225
|
+
You just need to add the following to your sidekiq initializer.
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
Sidekiq.configure_server do |config|
|
229
|
+
unless Rails.production?
|
230
|
+
config.server_middleware do |chain|
|
231
|
+
require 'prosopite/middleware/sidekiq'
|
232
|
+
chain.add(Prosopite::Middleware::Sidekiq)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
```
|
237
|
+
|
206
238
|
## Allow list
|
207
239
|
|
208
240
|
Ignore notifications for call stacks containing one or more substrings / regex:
|
data/lib/prosopite/version.rb
CHANGED
data/lib/prosopite.rb
CHANGED
@@ -12,11 +12,13 @@ module Prosopite
|
|
12
12
|
:rails_logger,
|
13
13
|
:prosopite_logger,
|
14
14
|
:custom_logger,
|
15
|
-
:allow_stack_paths,
|
16
|
-
:ignore_queries,
|
17
15
|
:ignore_pauses,
|
18
|
-
:
|
19
|
-
:
|
16
|
+
:backtrace_cleaner,
|
17
|
+
:enabled
|
18
|
+
|
19
|
+
attr_accessor :allow_stack_paths,
|
20
|
+
:ignore_queries,
|
21
|
+
:min_n_queries
|
20
22
|
|
21
23
|
def allow_list=(value)
|
22
24
|
puts "Prosopite.allow_list= is deprecated. Use Prosopite.allow_stack_paths= instead."
|
@@ -28,9 +30,21 @@ module Prosopite
|
|
28
30
|
@backtrace_cleaner ||= Rails.backtrace_cleaner
|
29
31
|
end
|
30
32
|
|
33
|
+
def enabled?
|
34
|
+
@enabled = true if @enabled.nil?
|
35
|
+
|
36
|
+
@enabled
|
37
|
+
end
|
38
|
+
|
39
|
+
def disabled?
|
40
|
+
!enabled?
|
41
|
+
end
|
42
|
+
|
31
43
|
def scan
|
32
44
|
tc[:prosopite_scan] ||= false
|
33
|
-
|
45
|
+
if scan? || disabled?
|
46
|
+
return block_given? ? yield : nil
|
47
|
+
end
|
34
48
|
|
35
49
|
subscribe
|
36
50
|
|
@@ -130,7 +144,8 @@ module Prosopite
|
|
130
144
|
end
|
131
145
|
|
132
146
|
def fingerprint(query)
|
133
|
-
|
147
|
+
db_adapter = ActiveRecord::Base.connection.adapter_name.downcase
|
148
|
+
if db_adapter.include?('mysql') || db_adapter.include?('trilogy')
|
134
149
|
mysql_fingerprint(query)
|
135
150
|
else
|
136
151
|
begin
|
@@ -246,13 +261,14 @@ module Prosopite
|
|
246
261
|
sql, name = data[:sql], data[:name]
|
247
262
|
|
248
263
|
if scan? && name != "SCHEMA" && sql.include?('SELECT') && data[:cached].nil? && !ignore_query?(sql)
|
249
|
-
|
264
|
+
query_caller = caller
|
265
|
+
location_key = Digest::SHA256.hexdigest(query_caller.join)
|
250
266
|
|
251
267
|
tc[:prosopite_query_counter][location_key] += 1
|
252
268
|
tc[:prosopite_query_holder][location_key] << sql
|
253
269
|
|
254
270
|
if tc[:prosopite_query_counter][location_key] > 1
|
255
|
-
tc[:prosopite_query_caller][location_key] =
|
271
|
+
tc[:prosopite_query_caller][location_key] = query_caller.dup
|
256
272
|
end
|
257
273
|
end
|
258
274
|
end
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mpampis Kostas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -123,6 +123,8 @@ files:
|
|
123
123
|
- README.md
|
124
124
|
- Rakefile
|
125
125
|
- lib/prosopite.rb
|
126
|
+
- lib/prosopite/middleware/rack.rb
|
127
|
+
- lib/prosopite/middleware/sidekiq.rb
|
126
128
|
- lib/prosopite/version.rb
|
127
129
|
- prosopite.gemspec
|
128
130
|
homepage: https://github.com/charkost/prosopite
|