rails_band 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0252268a8e05795a32afaf52c744143ad84aa806d8b06fe45ff480572b4e3d12'
4
- data.tar.gz: ae7ef45e64e0b645afe122d54da499274d5281f4182e7beb831b33ccd118c25a
3
+ metadata.gz: 84c17289076af2e04e037b011c18c6ff3d0206401b67c1e68354979410e545a7
4
+ data.tar.gz: 3133417c2eecf067f8e5f402a49b6143ee7e2944f92d95567289262c85af02ea
5
5
  SHA512:
6
- metadata.gz: 8d077ace78ac6724596f894854076b6fb9d6863423452e1af2e9fd23be765247827f4e446b310fc2dcb8cdddb6c565453f7b3b7cd90d8b7714d5b634b207510f
7
- data.tar.gz: be8704ee197bc96fce8ec5f68921cab394d7b96a77500a2e6a267d41cfd2e8a5a9efd310a345a6b5b2967033c4824cd39cb478f8467de83eb02eacfe674f1212
6
+ metadata.gz: 90f9b92421330c436f3968219be3a7ebf936d4b3b3a47f1906fdf3d1a9c65b4615fb2a3e6c8b76bdaa5f7dc2596c1e67d28f347bc5262420e66a72c69bdb087b
7
+ data.tar.gz: 5d852e1baafe0632013fede3b0278deb886f9cf0347848e3cb960b9e153c79096384bc9d8449b974cfbb7c54d576f2d13e60583e5b0be5993ec2a815ae8449ff
data/README.md CHANGED
@@ -20,14 +20,15 @@ bundle
20
20
  ```
21
21
 
22
22
  Or install it yourself as:
23
+
23
24
  ```console
24
25
  gem install rails_band
25
26
  ```
26
27
 
27
28
  ## Usage
28
29
 
29
- rails_band automatically replaces each `LogSubscriber` with its own ones after it's loaded as a gem.
30
- And then, you should configure how to consume Instrumentation hooks from core Rails implementations like this:
30
+ rails_band automatically replaces each `LogSubscriber` with its own ones after it's loaded as a gem. And then, you
31
+ should configure how to consume Instrumentation hooks from core Rails implementations like this:
31
32
 
32
33
  ```ruby
33
34
  Rails.application.config.rails_band.consumers = ->(event) { Rails.logger.info(event.to_h) }
@@ -43,11 +44,124 @@ Rails.application.config.rails_band.consumers = {
43
44
  }
44
45
  ```
45
46
 
46
- Note `:default` is the fallback of other non-specific event names. Other events will be ignored without `:default`.
47
- In other words, you can consume only events that you want to really consume without `:default`.
47
+ Note `:default` is the fallback of other non-specific event names. Other events will be ignored without `:default`. In
48
+ other words, you can consume only events that you want to really consume without `:default`.
48
49
 
49
50
  rails_band does not limit you only to use logging purposes. Enjoy with Rails Instrumentation hooks!
50
51
 
52
+ ## Supported Instrumentation API hooks
53
+
54
+ These are Rails Instrumentation API hooks supported by this gem so far.
55
+
56
+ ### Action Controller
57
+
58
+ | Event name | Supported |
59
+ | --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
60
+ | [`write_fragment.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#write-fragment-action-controller) | ✅ |
61
+ | [`read_fragment.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#read-fragment-action-controller) | ✅ |
62
+ | [`expire_fragment.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#expire-fragment-action-controller) | ✅ |
63
+ | [`exist_fragment?.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#exist-fragment-questionmark-action-controller) | ✅ |
64
+ | [`start_processing.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#start-processing-action-controller) | ✅ |
65
+ | [`process_action.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller) | ✅ |
66
+ | [`send_file.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#send-file-action-controller) | ✅ |
67
+ | [`send_data.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#send-data-action-controller) | ✅ |
68
+ | [`redirect_to.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#redirect-to-action-controller) | ✅ |
69
+ | [`halted_callback.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#halted-callback-action-controller) | ✅ |
70
+ | [`unpermitted_parameters.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#unpermitted-parameters-action-controller) | ✅ |
71
+
72
+ ### Action Dispatch
73
+
74
+ | Event name | Supported |
75
+ | --------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
76
+ | [`process_middleware.action_dispatch`](https://guides.rubyonrails.org/active_support_instrumentation.html#process-middleware-action-dispatch) | |
77
+
78
+ ### Action View
79
+
80
+ | Event name | Supported |
81
+ | ----------------------------------------------------------------------------------------------------------------------------------- | --------- |
82
+ | [`render_template.action_view`](https://guides.rubyonrails.org/active_support_instrumentation.html#render-template-action-view) | ✅ |
83
+ | [`render_partial.action_view`](https://guides.rubyonrails.org/active_support_instrumentation.html#render-partial-action-view) | ✅ |
84
+ | [`render_collection.action_view`](https://guides.rubyonrails.org/active_support_instrumentation.html#render-collection-action-view) | ✅ |
85
+
86
+ ### Active Record
87
+
88
+ | Event name | Supported |
89
+ | ------------------------------------------------------------------------------------------------------------------------------- | --------- |
90
+ | `strict_loading_violation.active_record` (Not yet documented. See the configuration of `action_on_strict_loading_violation`) | ✅ |
91
+ | [`sql.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#sql-active-record) | ✅ |
92
+ | [`instantiation.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#instantiation-active-record) | ✅ |
93
+
94
+ ### Action Mailer
95
+
96
+ | Event name | Supported |
97
+ | ------------------------------------------------------------------------------------------------------------------- | --------- |
98
+ | [`deliver.action_mailer`](https://guides.rubyonrails.org/active_support_instrumentation.html#deliver-action-mailer) | ✅ |
99
+ | [`process.action_mailer`](https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-mailer) | ✅ |
100
+
101
+ ### Active Support
102
+
103
+ | Event name | Supported |
104
+ | ------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
105
+ | [`cache_read.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-read-active-support) | ✅ |
106
+ | `cache_read_multi.active_support` (Not yet documented) | ✅ |
107
+ | [`cache_generate.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-generate-active-support) | ✅ |
108
+ | [`cache_fetch_hit.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-fetch-hit-active-support) | ✅ |
109
+ | [`cache_write.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-write-active-support) | ✅ |
110
+ | `cache_write_multi.active_support` (Not yet documented) | ✅ |
111
+ | [`cache_delete.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-delete-active-support) | ✅ |
112
+ | `cache_delete_multi.active_support` (Not yet documented, supported since Rails 6.1) | ✅ |
113
+ | [`cache_exist?.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-exist-questionmark-active-support) | ✅ |
114
+
115
+ ### Active Job
116
+
117
+ | Event name | Supported |
118
+ | ------------------------------------------------------------------------------------------------------------------------- | --------- |
119
+ | [`enqueue_at.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-at-active-job) | |
120
+ | [`enqueue.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-active-job) | |
121
+ | [`enqueue_retry.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-retry-active-job) | |
122
+ | [`perform_start.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-start-active-job) | |
123
+ | [`perform.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-active-job) | |
124
+ | [`retry_stopped.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#retry-stopped-active-job) | |
125
+ | [`discard.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#discard-active-job) | |
126
+
127
+ ### Action Cable
128
+
129
+ | Event name | Supported |
130
+ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
131
+ | [`perform_action.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-action-action-cable) | |
132
+ | [`transmit.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#transmit-action-cable) | |
133
+ | [`transmit_subscription_confirmation.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#transmit-subscription-confirmation-action-cable) | |
134
+ | [`transmit_subscription_rejection.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#transmit-subscription-rejection-action-cable) | |
135
+ | [`broadcast.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#broadcast-action-cable) | |
136
+
137
+ ### Active Storage
138
+
139
+ | Event name | Supported |
140
+ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
141
+ | [`service_upload.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-upload-active-storage) | |
142
+ | [`service_streaming_download.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-streaming-download-active-storage) | |
143
+ | [`service_download_chunk.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-download-chunk-active-storage) | |
144
+ | [`service_download.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-download-active-storage) | |
145
+ | [`service_delete.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-delete-active-storage) | |
146
+ | [`service_delete_prefixed.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-delete-prefixed-active-storage) | |
147
+ | [`service_exist.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-exist-active-storage) | |
148
+ | [`service_url.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-url-active-storage) | |
149
+ | [`service_update_metadata.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-update-metadata-active-storage) | |
150
+ | [`preview.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#preview-active-storage) | |
151
+ | [`analyze.active_storage`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#analyze-active-storage) | |
152
+
153
+ ### Railties
154
+
155
+ | Event name | Supported |
156
+ | ----------------------------------------------------------------------------------------------------------------------------------------- | --------- |
157
+ | [`load_config_initializer.railties`](https://guides.rubyonrails.org/active_support_instrumentation.html#load-config-initializer-railties) | |
158
+
159
+ ### Rails
160
+
161
+ | Event name | Supported |
162
+ | ----------------------------------------------------------------------------------------------------------- | --------- |
163
+ | [`deprecation.rails`](https://guides.rubyonrails.org/active_support_instrumentation.html#deprecation-rails) | |
164
+
51
165
  ## Contributing
52
166
 
53
167
  Contributing is welcome 😄 Please open a pull request!
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveSupport
5
+ module Event
6
+ # A wrapper for the event that is passed to `cache_delete.active_support`.
7
+ class CacheDelete < BaseEvent
8
+ def key
9
+ @key ||= @event.payload.fetch(:key)
10
+ end
11
+
12
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
13
+ define_method(:store) do
14
+ @store ||= @event.payload.fetch(:store)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveSupport
5
+ module Event
6
+ # A wrapper for the event that is passed to `cache_delete_multi.active_support`.
7
+ class CacheDeleteMulti < BaseEvent
8
+ def key
9
+ @key ||= @event.payload.fetch(:key)
10
+ end
11
+
12
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
13
+ define_method(:store) do
14
+ @store ||= @event.payload.fetch(:store)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveSupport
5
+ module Event
6
+ # A wrapper for the event that is passed to `cache_exist?.active_support`.
7
+ class CacheExist < BaseEvent
8
+ def key
9
+ @key ||= @event.payload.fetch(:key)
10
+ end
11
+
12
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
13
+ define_method(:store) do
14
+ @store ||= @event.payload.fetch(:store)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveSupport
5
+ module Event
6
+ # A wrapper for the event that is passed to `cache_fetch_hit.active_support`.
7
+ class CacheFetchHit < BaseEvent
8
+ def key
9
+ @key ||= @event.payload.fetch(:key)
10
+ end
11
+
12
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
13
+ define_method(:store) do
14
+ @store ||= @event.payload.fetch(:store)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveSupport
5
+ module Event
6
+ # A wrapper for the event that is passed to `cache_generate.active_support`.
7
+ class CacheGenerate < BaseEvent
8
+ def key
9
+ @key ||= @event.payload.fetch(:key)
10
+ end
11
+
12
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
13
+ define_method(:store) do
14
+ @store ||= @event.payload.fetch(:store)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveSupport
5
+ module Event
6
+ # A wrapper for the event that is passed to `cache_read.active_support`.
7
+ class CacheRead < BaseEvent
8
+ def key
9
+ @key ||= @event.payload.fetch(:key)
10
+ end
11
+
12
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
13
+ define_method(:store) do
14
+ @store ||= @event.payload.fetch(:store)
15
+ end
16
+ end
17
+
18
+ def hit
19
+ return @hit if defined? @hit
20
+
21
+ @hit = @event.payload[:hit]
22
+ end
23
+
24
+ def super_operation
25
+ return @super_operation if defined? @super_operation
26
+
27
+ @super_operation = @event.payload[:super_operation]
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveSupport
5
+ module Event
6
+ # A wrapper for the event that is passed to `cache_read_multi.active_support`.
7
+ class CacheReadMulti < BaseEvent
8
+ def key
9
+ @key ||= @event.payload.fetch(:key)
10
+ end
11
+
12
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
13
+ define_method(:store) do
14
+ @store ||= @event.payload.fetch(:store)
15
+ end
16
+ end
17
+
18
+ def hits
19
+ @hits ||= @event.payload[:hits] || []
20
+ end
21
+
22
+ def super_operation
23
+ return @super_operation if defined? @super_operation
24
+
25
+ @super_operation = @event.payload[:super_operation]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveSupport
5
+ module Event
6
+ # A wrapper for the event that is passed to `cache_write.active_support`.
7
+ class CacheWrite < BaseEvent
8
+ def key
9
+ @key ||= @event.payload.fetch(:key)
10
+ end
11
+
12
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
13
+ define_method(:store) do
14
+ @store ||= @event.payload.fetch(:store)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveSupport
5
+ module Event
6
+ # A wrapper for the event that is passed to `cache_write_multi.active_support`.
7
+ class CacheWriteMulti < BaseEvent
8
+ def key
9
+ @key ||= @event.payload.fetch(:key)
10
+ end
11
+
12
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
13
+ define_method(:store) do
14
+ @store ||= @event.payload.fetch(:store)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_band/active_support/event/cache_read'
4
+ require 'rails_band/active_support/event/cache_read_multi'
5
+ require 'rails_band/active_support/event/cache_generate'
6
+ require 'rails_band/active_support/event/cache_fetch_hit'
7
+ require 'rails_band/active_support/event/cache_write'
8
+ require 'rails_band/active_support/event/cache_write_multi'
9
+ require 'rails_band/active_support/event/cache_delete'
10
+ require 'rails_band/active_support/event/cache_delete_multi'
11
+ require 'rails_band/active_support/event/cache_exist'
12
+
13
+ module RailsBand
14
+ module ActiveSupport
15
+ # The custom LogSubscriber for ActiveSupport.
16
+ class LogSubscriber < ::ActiveSupport::LogSubscriber
17
+ mattr_accessor :consumers
18
+
19
+ def cache_read(event)
20
+ consumer_of(__method__)&.call(Event::CacheRead.new(event))
21
+ end
22
+
23
+ def cache_read_multi(event)
24
+ consumer_of(__method__)&.call(Event::CacheReadMulti.new(event))
25
+ end
26
+
27
+ def cache_generate(event)
28
+ consumer_of(__method__)&.call(Event::CacheGenerate.new(event))
29
+ end
30
+
31
+ def cache_fetch_hit(event)
32
+ consumer_of(__method__)&.call(Event::CacheFetchHit.new(event))
33
+ end
34
+
35
+ def cache_write(event)
36
+ consumer_of(__method__)&.call(Event::CacheWrite.new(event))
37
+ end
38
+
39
+ def cache_write_multi(event)
40
+ consumer_of(__method__)&.call(Event::CacheWriteMulti.new(event))
41
+ end
42
+
43
+ def cache_delete(event)
44
+ consumer_of(__method__)&.call(Event::CacheDelete.new(event))
45
+ end
46
+
47
+ def cache_delete_multi(event)
48
+ consumer_of(__method__)&.call(Event::CacheDeleteMulti.new(event))
49
+ end
50
+
51
+ def cache_exist?(event)
52
+ consumer_of(__method__)&.call(Event::CacheExist.new(event))
53
+ end
54
+
55
+ private
56
+
57
+ def consumer_of(sub_event)
58
+ consumers[:"#{sub_event}.active_support"] || consumers[:active_support] || consumers[:default]
59
+ end
60
+ end
61
+ end
62
+ end
@@ -29,6 +29,8 @@ module RailsBand
29
29
  require 'action_mailer/log_subscriber'
30
30
  swap.call(::ActionMailer::LogSubscriber, RailsBand::ActionMailer::LogSubscriber, :action_mailer)
31
31
  end
32
+
33
+ RailsBand::ActiveSupport::LogSubscriber.attach_to :active_support
32
34
  end
33
35
  end
34
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBand
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/rails_band.rb CHANGED
@@ -23,4 +23,8 @@ module RailsBand
23
23
  module ActionMailer
24
24
  autoload :LogSubscriber, 'rails_band/action_mailer/log_subscriber'
25
25
  end
26
+
27
+ module ActiveSupport
28
+ autoload :LogSubscriber, 'rails_band/active_support/log_subscriber'
29
+ end
26
30
  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.2.0
4
+ version: 0.3.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: 2021-11-01 00:00:00.000000000 Z
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,6 +59,16 @@ files:
59
59
  - lib/rails_band/active_record/event/sql.rb
60
60
  - lib/rails_band/active_record/event/strict_loading_violation.rb
61
61
  - lib/rails_band/active_record/log_subscriber.rb
62
+ - lib/rails_band/active_support/event/cache_delete.rb
63
+ - lib/rails_band/active_support/event/cache_delete_multi.rb
64
+ - lib/rails_band/active_support/event/cache_exist.rb
65
+ - lib/rails_band/active_support/event/cache_fetch_hit.rb
66
+ - lib/rails_band/active_support/event/cache_generate.rb
67
+ - lib/rails_band/active_support/event/cache_read.rb
68
+ - lib/rails_band/active_support/event/cache_read_multi.rb
69
+ - lib/rails_band/active_support/event/cache_write.rb
70
+ - lib/rails_band/active_support/event/cache_write_multi.rb
71
+ - lib/rails_band/active_support/log_subscriber.rb
62
72
  - lib/rails_band/base_event.rb
63
73
  - lib/rails_band/configuration.rb
64
74
  - lib/rails_band/railtie.rb