rails_band 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/rails_band/action_dispatch/event/process_middleware.rb +14 -0
- data/lib/rails_band/action_dispatch/event/redirect.rb +22 -0
- data/lib/rails_band/action_dispatch/log_subscriber.rb +27 -0
- data/lib/rails_band/action_view/event/render_partial.rb +6 -0
- data/lib/rails_band/action_view/event/render_template.rb +6 -0
- data/lib/rails_band/active_job/event/enqueue.rb +1 -1
- data/lib/rails_band/active_job/event/enqueue_at.rb +1 -1
- data/lib/rails_band/active_job/event/perform.rb +5 -1
- data/lib/rails_band/railtie.rb +10 -0
- data/lib/rails_band/version.rb +1 -1
- data/lib/rails_band.rb +13 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a25f05dedb0e797005029c002702b3f54d08f9be39b2f66fb3ca24de6a256b19
|
4
|
+
data.tar.gz: 24648cbe75b62df3f919e9809b40e93f30c985971c9fe8bc38fac6cfe41746fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f60fd033f93bc2c1716a8e3f950e2b0dc5e38d109f7bcefdff93d4bbf132cb29b4dacfc0b2387eab46f8c9879bc75673938003d9b2401dfb99b11a6c0ef1ffc1
|
7
|
+
data.tar.gz: 3fec1674cea01cfa0e1031b7bd7759fde79e9b43367e12484737b1110240e9c9557345827ed4811c974a2bcf3cf285d6d5c78f4c236637132731a489d7cf2352
|
data/README.md
CHANGED
@@ -73,7 +73,8 @@ These are Rails Instrumentation API hooks supported by this gem so far.
|
|
73
73
|
|
74
74
|
| Event name | Supported |
|
75
75
|
| --------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
|
76
|
-
| [`process_middleware.action_dispatch`](https://guides.rubyonrails.org/active_support_instrumentation.html#process-middleware-action-dispatch) |
|
76
|
+
| [`process_middleware.action_dispatch`](https://guides.rubyonrails.org/active_support_instrumentation.html#process-middleware-action-dispatch) | ✅ |
|
77
|
+
| [`redirect.action_dispatch`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#redirect-action-dispatch) | ✅ |
|
77
78
|
|
78
79
|
### Action View
|
79
80
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsBand
|
4
|
+
module ActionDispatch
|
5
|
+
module Event
|
6
|
+
# A wrapper for the event that is passed to `process_middleware.action_dispatch`.
|
7
|
+
class ProcessMiddleware < BaseEvent
|
8
|
+
def middleware
|
9
|
+
@middleware ||= @event.payload.fetch(:middleware)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsBand
|
4
|
+
module ActionDispatch
|
5
|
+
module Event
|
6
|
+
# A wrapper for the event that is passed to `redirect.action_dispatch`.
|
7
|
+
class Redirect < BaseEvent
|
8
|
+
def status
|
9
|
+
@status ||= @event.payload.fetch(:status)
|
10
|
+
end
|
11
|
+
|
12
|
+
def location
|
13
|
+
@location ||= @event.payload.fetch(:location)
|
14
|
+
end
|
15
|
+
|
16
|
+
def request
|
17
|
+
@request ||= @event.payload.fetch(:request)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_band/action_dispatch/event/process_middleware'
|
4
|
+
require 'rails_band/action_dispatch/event/redirect'
|
5
|
+
|
6
|
+
module RailsBand
|
7
|
+
module ActionDispatch
|
8
|
+
# The custom LogSubscriber for ActionDispatch.
|
9
|
+
class LogSubscriber < ::ActiveSupport::LogSubscriber
|
10
|
+
mattr_accessor :consumers
|
11
|
+
|
12
|
+
def process_middleware(event)
|
13
|
+
consumer_of(__method__)&.call(Event::ProcessMiddleware.new(event))
|
14
|
+
end
|
15
|
+
|
16
|
+
def redirect(event)
|
17
|
+
consumer_of(__method__)&.call(Event::Redirect.new(event))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def consumer_of(sub_event)
|
23
|
+
consumers[:"#{sub_event}.action_dispatch"] || consumers[:action_dispatch] || consumers[:default]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -22,6 +22,12 @@ module RailsBand
|
|
22
22
|
def cache_hit
|
23
23
|
@cache_hit ||= @event.payload.fetch(:cache_hit)
|
24
24
|
end
|
25
|
+
|
26
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
|
27
|
+
define_method(:locals) do
|
28
|
+
@locals ||= @event.payload[:locals]
|
29
|
+
end
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
@@ -18,6 +18,12 @@ module RailsBand
|
|
18
18
|
|
19
19
|
@layout = @event.payload[:layout]&.then { |layout| from_views(layout) }
|
20
20
|
end
|
21
|
+
|
22
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
|
23
|
+
define_method(:locals) do
|
24
|
+
@locals ||= @event.payload[:locals]
|
25
|
+
end
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
@@ -13,7 +13,7 @@ module RailsBand
|
|
13
13
|
@job ||= @event.payload.fetch(:job)
|
14
14
|
end
|
15
15
|
|
16
|
-
if Gem::Version.new(Rails.version)
|
16
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
|
17
17
|
define_method(:aborted) do
|
18
18
|
return @aborted if defined?(@aborted)
|
19
19
|
|
@@ -13,7 +13,7 @@ module RailsBand
|
|
13
13
|
@job ||= @event.payload.fetch(:job)
|
14
14
|
end
|
15
15
|
|
16
|
-
if Gem::Version.new(Rails.version)
|
16
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
|
17
17
|
define_method(:aborted) do
|
18
18
|
return @aborted if defined?(@aborted)
|
19
19
|
|
@@ -13,12 +13,16 @@ module RailsBand
|
|
13
13
|
@job ||= @event.payload.fetch(:job)
|
14
14
|
end
|
15
15
|
|
16
|
-
if Gem::Version.new(Rails.version)
|
16
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
|
17
17
|
define_method(:aborted) do
|
18
18
|
return @aborted if defined?(@aborted)
|
19
19
|
|
20
20
|
@aborted = @event.payload[:aborted]
|
21
21
|
end
|
22
|
+
|
23
|
+
define_method(:db_runtime) do
|
24
|
+
@db_runtime ||= @event.payload[:db_runtime]
|
25
|
+
end
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
data/lib/rails_band/railtie.rb
CHANGED
@@ -8,6 +8,14 @@ module RailsBand
|
|
8
8
|
class Railtie < ::Rails::Railtie
|
9
9
|
config.rails_band = Configuration.new
|
10
10
|
|
11
|
+
config.before_initialize do
|
12
|
+
# NOTE: `ActionDispatch::MiddlewareStack::InstrumentationProxy` will be called
|
13
|
+
# only when `ActionDispatch::MiddlewareStack#build` detects `process_middleware.action_dispatch`
|
14
|
+
# is listened to. So, `attach_to` must be called before Rack middlewares will be loaded.
|
15
|
+
::ActionDispatch::LogSubscriber.detach_from :action_dispatch if defined?(::ActionDispatch::LogSubscriber)
|
16
|
+
RailsBand::ActionDispatch::LogSubscriber.attach_to :action_dispatch
|
17
|
+
end
|
18
|
+
|
11
19
|
config.after_initialize do |app|
|
12
20
|
consumers = app.config.rails_band.consumers
|
13
21
|
|
@@ -40,6 +48,8 @@ module RailsBand
|
|
40
48
|
RailsBand::ActiveStorage::LogSubscriber.attach_to :active_storage
|
41
49
|
end
|
42
50
|
|
51
|
+
RailsBand::ActionDispatch::LogSubscriber.consumers = consumers
|
52
|
+
|
43
53
|
RailsBand::ActiveSupport::LogSubscriber.consumers = consumers
|
44
54
|
RailsBand::ActiveSupport::LogSubscriber.attach_to :active_support
|
45
55
|
|
data/lib/rails_band/version.rb
CHANGED
data/lib/rails_band.rb
CHANGED
@@ -9,34 +9,47 @@ require 'rails_band/railtie'
|
|
9
9
|
# Rails::Band unsubscribes all default LogSubscribers from Rails Instrumentation API,
|
10
10
|
# and it subscribes our own custom LogSubscribers to make it easy to access Rails Instrumentation API.
|
11
11
|
module RailsBand
|
12
|
+
# RailsBand::ActionController is responsible for subscribing notifications from ActionController.
|
12
13
|
module ActionController
|
13
14
|
autoload :LogSubscriber, 'rails_band/action_controller/log_subscriber'
|
14
15
|
end
|
15
16
|
|
17
|
+
# RailsBand::ActionView is responsible for subscribing notifications from ActionView.
|
16
18
|
module ActionView
|
17
19
|
autoload :LogSubscriber, 'rails_band/action_view/log_subscriber'
|
18
20
|
end
|
19
21
|
|
22
|
+
# RailsBand::ActiveRecord is responsible for subscribing notifications from ActiveRecord.
|
20
23
|
module ActiveRecord
|
21
24
|
autoload :LogSubscriber, 'rails_band/active_record/log_subscriber'
|
22
25
|
end
|
23
26
|
|
27
|
+
# RailsBand::ActionMailer is responsible for subscribing notifications from ActionMailer.
|
24
28
|
module ActionMailer
|
25
29
|
autoload :LogSubscriber, 'rails_band/action_mailer/log_subscriber'
|
26
30
|
end
|
27
31
|
|
32
|
+
# RailsBand::ActionDispatch is responsible for subscribing notifications from ActionDispatch.
|
33
|
+
module ActionDispatch
|
34
|
+
autoload :LogSubscriber, 'rails_band/action_dispatch/log_subscriber'
|
35
|
+
end
|
36
|
+
|
37
|
+
# RailsBand::ActiveSupport is responsible for subscribing notifications from ActiveSupport.
|
28
38
|
module ActiveSupport
|
29
39
|
autoload :LogSubscriber, 'rails_band/active_support/log_subscriber'
|
30
40
|
end
|
31
41
|
|
42
|
+
# RailsBand::ActiveJob is responsible for subscribing notifications from ActiveJob.
|
32
43
|
module ActiveJob
|
33
44
|
autoload :LogSubscriber, 'rails_band/active_job/log_subscriber'
|
34
45
|
end
|
35
46
|
|
47
|
+
# RailsBand::ActionCable is responsible for subscribing notifications from ActionCable.
|
36
48
|
module ActionCable
|
37
49
|
autoload :LogSubscriber, 'rails_band/action_cable/log_subscriber'
|
38
50
|
end
|
39
51
|
|
52
|
+
# RailsBand::ActiveStorage is responsible for subscribing notifications from ActiveStorage.
|
40
53
|
module ActiveStorage
|
41
54
|
autoload :LogSubscriber, 'rails_band/active_storage/log_subscriber'
|
42
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_band
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yutaka Kamei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -59,6 +59,9 @@ files:
|
|
59
59
|
- lib/rails_band/action_controller/event/unpermitted_parameters.rb
|
60
60
|
- lib/rails_band/action_controller/event/write_fragment.rb
|
61
61
|
- lib/rails_band/action_controller/log_subscriber.rb
|
62
|
+
- lib/rails_band/action_dispatch/event/process_middleware.rb
|
63
|
+
- lib/rails_band/action_dispatch/event/redirect.rb
|
64
|
+
- lib/rails_band/action_dispatch/log_subscriber.rb
|
62
65
|
- lib/rails_band/action_mailer/event/deliver.rb
|
63
66
|
- lib/rails_band/action_mailer/event/process.rb
|
64
67
|
- lib/rails_band/action_mailer/log_subscriber.rb
|
@@ -131,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
134
|
- !ruby/object:Gem::Version
|
132
135
|
version: '0'
|
133
136
|
requirements: []
|
134
|
-
rubygems_version: 3.
|
137
|
+
rubygems_version: 3.4.1
|
135
138
|
signing_key:
|
136
139
|
specification_version: 4
|
137
140
|
summary: Easy-to-use Rails Instrumentation API
|