rails_band 0.6.1 → 0.8.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/README.md +4 -3
- 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_collection.rb +1 -1
- data/lib/rails_band/action_view/event/render_layout.rb +18 -0
- data/lib/rails_band/action_view/event/render_partial.rb +7 -1
- data/lib/rails_band/action_view/event/render_template.rb +7 -1
- data/lib/rails_band/action_view/log_subscriber.rb +5 -0
- data/lib/rails_band/active_job/event/enqueue.rb +8 -0
- data/lib/rails_band/active_job/event/enqueue_at.rb +8 -0
- data/lib/rails_band/active_job/event/perform.rb +12 -0
- data/lib/rails_band/base_event.rb +2 -3
- data/lib/rails_band/deprecation_subscriber.rb +40 -0
- data/lib/rails_band/railtie.rb +13 -0
- data/lib/rails_band/version.rb +1 -1
- data/lib/rails_band.rb +14 -0
- metadata +8 -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
|
|
@@ -82,7 +83,7 @@ These are Rails Instrumentation API hooks supported by this gem so far.
|
|
82
83
|
| [`render_template.action_view`](https://guides.rubyonrails.org/active_support_instrumentation.html#render-template-action-view) | ✅ |
|
83
84
|
| [`render_partial.action_view`](https://guides.rubyonrails.org/active_support_instrumentation.html#render-partial-action-view) | ✅ |
|
84
85
|
| [`render_collection.action_view`](https://guides.rubyonrails.org/active_support_instrumentation.html#render-collection-action-view) | ✅ |
|
85
|
-
| [`render_layout.action_view`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#render-layout-action-view) |
|
86
|
+
| [`render_layout.action_view`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#render-layout-action-view) | ✅ |
|
86
87
|
|
87
88
|
### Active Record
|
88
89
|
|
@@ -162,7 +163,7 @@ These are Rails Instrumentation API hooks supported by this gem so far.
|
|
162
163
|
|
163
164
|
| Event name | Supported |
|
164
165
|
| ----------------------------------------------------------------------------------------------------------- | --------- |
|
165
|
-
| [`deprecation.rails`](https://guides.rubyonrails.org/active_support_instrumentation.html#deprecation-rails) |
|
166
|
+
| [`deprecation.rails`](https://guides.rubyonrails.org/active_support_instrumentation.html#deprecation-rails) | ✅ |
|
166
167
|
|
167
168
|
## Contributing
|
168
169
|
|
@@ -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
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_band/action_view/from_views'
|
4
|
+
|
5
|
+
module RailsBand
|
6
|
+
module ActionView
|
7
|
+
module Event
|
8
|
+
# A wrapper for the event that is passed to `render_layout.action_view`.
|
9
|
+
class RenderLayout < BaseEvent
|
10
|
+
include FromViews
|
11
|
+
|
12
|
+
def identifier
|
13
|
+
@identifier ||= from_views(@event.payload.fetch(:identifier))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -16,12 +16,18 @@ module RailsBand
|
|
16
16
|
def layout
|
17
17
|
return @layout if defined? @layout
|
18
18
|
|
19
|
-
@layout = @event.payload[:layout]&.
|
19
|
+
@layout = @event.payload[:layout]&.then { |layout| from_views(layout) }
|
20
20
|
end
|
21
21
|
|
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
|
@@ -16,7 +16,13 @@ module RailsBand
|
|
16
16
|
def layout
|
17
17
|
return @layout if defined? @layout
|
18
18
|
|
19
|
-
@layout = @event.payload[:layout]&.
|
19
|
+
@layout = @event.payload[:layout]&.then { |layout| from_views(layout) }
|
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
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'rails_band/action_view/event/render_template'
|
4
4
|
require 'rails_band/action_view/event/render_partial'
|
5
5
|
require 'rails_band/action_view/event/render_collection'
|
6
|
+
require 'rails_band/action_view/event/render_layout'
|
6
7
|
|
7
8
|
module RailsBand
|
8
9
|
module ActionView
|
@@ -22,6 +23,10 @@ module RailsBand
|
|
22
23
|
consumer_of(__method__)&.call(Event::RenderCollection.new(event))
|
23
24
|
end
|
24
25
|
|
26
|
+
def render_layout(event)
|
27
|
+
consumer_of(__method__)&.call(Event::RenderLayout.new(event))
|
28
|
+
end
|
29
|
+
|
25
30
|
private
|
26
31
|
|
27
32
|
def consumer_of(sub_event)
|
@@ -12,6 +12,14 @@ module RailsBand
|
|
12
12
|
def job
|
13
13
|
@job ||= @event.payload.fetch(:job)
|
14
14
|
end
|
15
|
+
|
16
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
|
17
|
+
define_method(:aborted) do
|
18
|
+
return @aborted if defined?(@aborted)
|
19
|
+
|
20
|
+
@aborted = @event.payload[:aborted]
|
21
|
+
end
|
22
|
+
end
|
15
23
|
end
|
16
24
|
end
|
17
25
|
end
|
@@ -12,6 +12,14 @@ module RailsBand
|
|
12
12
|
def job
|
13
13
|
@job ||= @event.payload.fetch(:job)
|
14
14
|
end
|
15
|
+
|
16
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
|
17
|
+
define_method(:aborted) do
|
18
|
+
return @aborted if defined?(@aborted)
|
19
|
+
|
20
|
+
@aborted = @event.payload[:aborted]
|
21
|
+
end
|
22
|
+
end
|
15
23
|
end
|
16
24
|
end
|
17
25
|
end
|
@@ -12,6 +12,18 @@ module RailsBand
|
|
12
12
|
def job
|
13
13
|
@job ||= @event.payload.fetch(:job)
|
14
14
|
end
|
15
|
+
|
16
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
|
17
|
+
define_method(:aborted) do
|
18
|
+
return @aborted if defined?(@aborted)
|
19
|
+
|
20
|
+
@aborted = @event.payload[:aborted]
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method(:db_runtime) do
|
24
|
+
@db_runtime ||= @event.payload[:db_runtime]
|
25
|
+
end
|
26
|
+
end
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RailsBand
|
4
4
|
# The base class of each Event class.
|
5
5
|
class BaseEvent
|
6
|
-
attr_reader :name, :time, :end, :transaction_id,
|
6
|
+
attr_reader :name, :time, :end, :transaction_id,
|
7
7
|
:cpu_time, :idle_time, :allocations, :duration
|
8
8
|
|
9
9
|
# @param event [ActiveSupport::Notifications::Event]
|
@@ -13,7 +13,6 @@ module RailsBand
|
|
13
13
|
@time = event.time
|
14
14
|
@end = event.end
|
15
15
|
@transaction_id = event.transaction_id
|
16
|
-
@children = event.children
|
17
16
|
@cpu_time = event.cpu_time
|
18
17
|
@idle_time = event.idle_time
|
19
18
|
@allocations = event.allocations
|
@@ -22,7 +21,7 @@ module RailsBand
|
|
22
21
|
|
23
22
|
def to_h
|
24
23
|
@to_h ||= {
|
25
|
-
name: @name, time: @time, end: @end, transaction_id: @transaction_id,
|
24
|
+
name: @name, time: @time, end: @end, transaction_id: @transaction_id,
|
26
25
|
cpu_time: @cpu_time, idle_time: @idle_time, allocations: @allocations, duration: @duration
|
27
26
|
}.merge!(
|
28
27
|
public_methods(false).reject { |meth| non_hash_keys.include?(meth) }.each_with_object({}) do |meth, h|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsBand
|
4
|
+
# DeprecationSubscriber is responsible for logging deprecation warnings.
|
5
|
+
class DeprecationSubscriber < ::ActiveSupport::LogSubscriber
|
6
|
+
# DeprecationEvent is a wrapper around a deprecation notification event.
|
7
|
+
class DeprecationEvent < BaseEvent
|
8
|
+
def message
|
9
|
+
@message ||= @event.payload.fetch(:message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def callstack
|
13
|
+
@callstack ||= @event.payload.fetch(:callstack)
|
14
|
+
end
|
15
|
+
|
16
|
+
def gem_name
|
17
|
+
@gem_name ||= @event.payload.fetch(:gem_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def deprecation_horizon
|
21
|
+
@deprecation_horizon ||= @event.payload.fetch(:deprecation_horizon)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
mattr_accessor :consumers
|
26
|
+
|
27
|
+
def deprecation(event)
|
28
|
+
consumer&.call(DeprecationEvent.new(event))
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def consumer
|
34
|
+
# HACK: ActiveSupport::Subscriber has the instance variable @namespace, but it's not documented.
|
35
|
+
# This hack might possibly break in the future.
|
36
|
+
namespace = self.class.instance_variable_get(:@namespace)
|
37
|
+
consumers[:"deprecation.#{namespace}"] || consumers[:deprecation] || consumers[:default]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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,9 +48,14 @@ 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
|
|
56
|
+
RailsBand::DeprecationSubscriber.consumers = consumers
|
57
|
+
RailsBand::DeprecationSubscriber.attach_to :rails
|
58
|
+
|
46
59
|
if defined?(::ActiveJob)
|
47
60
|
require 'active_job/logging'
|
48
61
|
|
data/lib/rails_band/version.rb
CHANGED
data/lib/rails_band.rb
CHANGED
@@ -3,39 +3,53 @@
|
|
3
3
|
require 'rails_band/version'
|
4
4
|
require 'rails_band/configuration'
|
5
5
|
require 'rails_band/base_event'
|
6
|
+
require 'rails_band/deprecation_subscriber'
|
6
7
|
require 'rails_band/railtie'
|
7
8
|
|
8
9
|
# Rails::Band unsubscribes all default LogSubscribers from Rails Instrumentation API,
|
9
10
|
# and it subscribes our own custom LogSubscribers to make it easy to access Rails Instrumentation API.
|
10
11
|
module RailsBand
|
12
|
+
# RailsBand::ActionController is responsible for subscribing notifications from ActionController.
|
11
13
|
module ActionController
|
12
14
|
autoload :LogSubscriber, 'rails_band/action_controller/log_subscriber'
|
13
15
|
end
|
14
16
|
|
17
|
+
# RailsBand::ActionView is responsible for subscribing notifications from ActionView.
|
15
18
|
module ActionView
|
16
19
|
autoload :LogSubscriber, 'rails_band/action_view/log_subscriber'
|
17
20
|
end
|
18
21
|
|
22
|
+
# RailsBand::ActiveRecord is responsible for subscribing notifications from ActiveRecord.
|
19
23
|
module ActiveRecord
|
20
24
|
autoload :LogSubscriber, 'rails_band/active_record/log_subscriber'
|
21
25
|
end
|
22
26
|
|
27
|
+
# RailsBand::ActionMailer is responsible for subscribing notifications from ActionMailer.
|
23
28
|
module ActionMailer
|
24
29
|
autoload :LogSubscriber, 'rails_band/action_mailer/log_subscriber'
|
25
30
|
end
|
26
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.
|
27
38
|
module ActiveSupport
|
28
39
|
autoload :LogSubscriber, 'rails_band/active_support/log_subscriber'
|
29
40
|
end
|
30
41
|
|
42
|
+
# RailsBand::ActiveJob is responsible for subscribing notifications from ActiveJob.
|
31
43
|
module ActiveJob
|
32
44
|
autoload :LogSubscriber, 'rails_band/active_job/log_subscriber'
|
33
45
|
end
|
34
46
|
|
47
|
+
# RailsBand::ActionCable is responsible for subscribing notifications from ActionCable.
|
35
48
|
module ActionCable
|
36
49
|
autoload :LogSubscriber, 'rails_band/action_cable/log_subscriber'
|
37
50
|
end
|
38
51
|
|
52
|
+
# RailsBand::ActiveStorage is responsible for subscribing notifications from ActiveStorage.
|
39
53
|
module ActiveStorage
|
40
54
|
autoload :LogSubscriber, 'rails_band/active_storage/log_subscriber'
|
41
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,10 +59,14 @@ 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
|
65
68
|
- lib/rails_band/action_view/event/render_collection.rb
|
69
|
+
- lib/rails_band/action_view/event/render_layout.rb
|
66
70
|
- lib/rails_band/action_view/event/render_partial.rb
|
67
71
|
- lib/rails_band/action_view/event/render_template.rb
|
68
72
|
- lib/rails_band/action_view/from_views.rb
|
@@ -104,6 +108,7 @@ files:
|
|
104
108
|
- lib/rails_band/active_support/log_subscriber.rb
|
105
109
|
- lib/rails_band/base_event.rb
|
106
110
|
- lib/rails_band/configuration.rb
|
111
|
+
- lib/rails_band/deprecation_subscriber.rb
|
107
112
|
- lib/rails_band/railtie.rb
|
108
113
|
- lib/rails_band/version.rb
|
109
114
|
homepage: https://github.com/yykamei/rails_band
|
@@ -129,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
134
|
- !ruby/object:Gem::Version
|
130
135
|
version: '0'
|
131
136
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
137
|
+
rubygems_version: 3.4.1
|
133
138
|
signing_key:
|
134
139
|
specification_version: 4
|
135
140
|
summary: Easy-to-use Rails Instrumentation API
|