rails_band 0.1.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +122 -4
  3. data/lib/rails_band/action_cable/event/broadcast.rb +22 -0
  4. data/lib/rails_band/action_cable/event/perform_action.rb +22 -0
  5. data/lib/rails_band/action_cable/event/transmit.rb +22 -0
  6. data/lib/rails_band/action_cable/event/transmit_subscription_confirmation.rb +14 -0
  7. data/lib/rails_band/action_cable/event/transmit_subscription_rejection.rb +14 -0
  8. data/lib/rails_band/action_cable/log_subscriber.rb +42 -0
  9. data/lib/rails_band/action_mailer/event/deliver.rb +50 -0
  10. data/lib/rails_band/action_mailer/event/process.rb +22 -0
  11. data/lib/rails_band/action_mailer/log_subscriber.rb +27 -0
  12. data/lib/rails_band/active_job/event/discard.rb +22 -0
  13. data/lib/rails_band/active_job/event/enqueue.rb +18 -0
  14. data/lib/rails_band/active_job/event/enqueue_at.rb +18 -0
  15. data/lib/rails_band/active_job/event/enqueue_retry.rb +26 -0
  16. data/lib/rails_band/active_job/event/perform.rb +18 -0
  17. data/lib/rails_band/active_job/event/perform_start.rb +18 -0
  18. data/lib/rails_band/active_job/event/retry_stopped.rb +22 -0
  19. data/lib/rails_band/active_job/log_subscriber.rb +52 -0
  20. data/lib/rails_band/active_support/event/cache_delete.rb +20 -0
  21. data/lib/rails_band/active_support/event/cache_delete_multi.rb +20 -0
  22. data/lib/rails_band/active_support/event/cache_exist.rb +20 -0
  23. data/lib/rails_band/active_support/event/cache_fetch_hit.rb +20 -0
  24. data/lib/rails_band/active_support/event/cache_generate.rb +20 -0
  25. data/lib/rails_band/active_support/event/cache_read.rb +32 -0
  26. data/lib/rails_band/active_support/event/cache_read_multi.rb +30 -0
  27. data/lib/rails_band/active_support/event/cache_write.rb +20 -0
  28. data/lib/rails_band/active_support/event/cache_write_multi.rb +20 -0
  29. data/lib/rails_band/active_support/log_subscriber.rb +62 -0
  30. data/lib/rails_band/railtie.rb +22 -0
  31. data/lib/rails_band/version.rb +1 -1
  32. data/lib/rails_band.rb +16 -0
  33. metadata +33 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97783d31ff40a28fa21181d954f365769bfcaf03a08557572363d90399e32347
4
- data.tar.gz: 9e32469800f4a9b9e818e928283278975fd50408f24bee7d0241a7018e86e1f6
3
+ metadata.gz: 3b347e10fae66e28648aca3427b76fe456fbaf21f1f45aaea5b4e3daed74bc44
4
+ data.tar.gz: 102f48535f8cbf10db8b670d57cf671c8f0a839ae0e312fd706631b39e1ad55a
5
5
  SHA512:
6
- metadata.gz: e63696203569e2126281fa79e7ec42ad4c8a09fdd04597eb41ae73cc1fd98b977776513e4f701304a8eb58a1597cb5940f2f920b3fe683c8df7262bc40adfffe
7
- data.tar.gz: f267534e31f135a5a216eab5e41a0298f4b59c9ba17f4a683fb212bb1d10bf8eb2e024646fae669e16b315399a0e412f814dbd7d432222b60a2e6345b44fa0c5
6
+ metadata.gz: be4a7fbb271fd7bca9c47a23f7ee474b57ad06e047278476670d335fa22461a45a13d02e3d79be0578f5bcf40662aa7229e921e23a2919d9d838b9f718e1ff52
7
+ data.tar.gz: fe2e8deba94abbd8f44ea0c940dd4f23f132952f668de68aa06a221eb465f9c78e4ba5d69151f192e20491492f9aaca86662801c89a891ac1c3ba4f199cf31bd
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # rails_band
2
2
 
3
+ <a href="https://github.com/yykamei/rails_band/actions/workflows/ci.yml"><img alt="GitHub Actions workflow status" src="https://github.com/yykamei/rails_band/actions/workflows/ci.yml/badge.svg"></a>
4
+ <a href="https://rubygems.org/gems/rails_band"><img alt="rails_band" src="https://img.shields.io/gem/v/rails_band"></a>
5
+
3
6
  Easy-to-use Rails Instrumentation API.
4
7
 
5
8
  ## Installation
@@ -17,14 +20,15 @@ bundle
17
20
  ```
18
21
 
19
22
  Or install it yourself as:
23
+
20
24
  ```console
21
25
  gem install rails_band
22
26
  ```
23
27
 
24
28
  ## Usage
25
29
 
26
- rails_band automatically replaces each `LogSubscriber` with its own ones after it's loaded as a gem.
27
- 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:
28
32
 
29
33
  ```ruby
30
34
  Rails.application.config.rails_band.consumers = ->(event) { Rails.logger.info(event.to_h) }
@@ -40,11 +44,125 @@ Rails.application.config.rails_band.consumers = {
40
44
  }
41
45
  ```
42
46
 
43
- Note `:default` is the fallback of other non-specific event names. Other events will be ignored without `:default`.
44
- 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`.
45
49
 
46
50
  rails_band does not limit you only to use logging purposes. Enjoy with Rails Instrumentation hooks!
47
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
+ | [`render_layout.action_view`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#render-layout-action-view) | |
86
+
87
+ ### Active Record
88
+
89
+ | Event name | Supported |
90
+ | ------------------------------------------------------------------------------------------------------------------------------- | --------- |
91
+ | `strict_loading_violation.active_record` (Not yet documented. See the configuration of `action_on_strict_loading_violation`) | ✅ |
92
+ | [`sql.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#sql-active-record) | ✅ |
93
+ | [`instantiation.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#instantiation-active-record) | ✅ |
94
+
95
+ ### Action Mailer
96
+
97
+ | Event name | Supported |
98
+ | ------------------------------------------------------------------------------------------------------------------- | --------- |
99
+ | [`deliver.action_mailer`](https://guides.rubyonrails.org/active_support_instrumentation.html#deliver-action-mailer) | ✅ |
100
+ | [`process.action_mailer`](https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-mailer) | ✅ |
101
+
102
+ ### Active Support
103
+
104
+ | Event name | Supported |
105
+ | ------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
106
+ | [`cache_read.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-read-active-support) | ✅ |
107
+ | `cache_read_multi.active_support` (Not yet documented) | ✅ |
108
+ | [`cache_generate.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-generate-active-support) | ✅ |
109
+ | [`cache_fetch_hit.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-fetch-hit-active-support) | ✅ |
110
+ | [`cache_write.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-write-active-support) | ✅ |
111
+ | `cache_write_multi.active_support` (Not yet documented) | ✅ |
112
+ | [`cache_delete.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-delete-active-support) | ✅ |
113
+ | `cache_delete_multi.active_support` (Not yet documented, supported since Rails 6.1) | ✅ |
114
+ | [`cache_exist?.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-exist-questionmark-active-support) | ✅ |
115
+
116
+ ### Active Job
117
+
118
+ | Event name | Supported |
119
+ | ------------------------------------------------------------------------------------------------------------------------- | --------- |
120
+ | [`enqueue_at.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-at-active-job) | ✅ |
121
+ | [`enqueue.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-active-job) | ✅ |
122
+ | [`enqueue_retry.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-retry-active-job) | ✅ |
123
+ | [`perform_start.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-start-active-job) | ✅ |
124
+ | [`perform.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-active-job) | ✅ |
125
+ | [`retry_stopped.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#retry-stopped-active-job) | ✅ |
126
+ | [`discard.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#discard-active-job) | ✅ |
127
+
128
+ ### Action Cable
129
+
130
+ | Event name | Supported |
131
+ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
132
+ | [`perform_action.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-action-action-cable) | ✅ |
133
+ | [`transmit.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#transmit-action-cable) | ✅ |
134
+ | [`transmit_subscription_confirmation.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#transmit-subscription-confirmation-action-cable) | ✅ |
135
+ | [`transmit_subscription_rejection.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#transmit-subscription-rejection-action-cable) | ✅ |
136
+ | [`broadcast.action_cable`](https://guides.rubyonrails.org/active_support_instrumentation.html#broadcast-action-cable) | ✅ |
137
+
138
+ ### Active Storage
139
+
140
+ | Event name | Supported |
141
+ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
142
+ | [`service_upload.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-upload-active-storage) | |
143
+ | [`service_streaming_download.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-streaming-download-active-storage) | |
144
+ | [`service_download_chunk.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-download-chunk-active-storage) | |
145
+ | [`service_download.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-download-active-storage) | |
146
+ | [`service_delete.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-delete-active-storage) | |
147
+ | [`service_delete_prefixed.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-delete-prefixed-active-storage) | |
148
+ | [`service_exist.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-exist-active-storage) | |
149
+ | [`service_url.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-url-active-storage) | |
150
+ | [`service_update_metadata.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#service-update-metadata-active-storage) | |
151
+ | [`preview.active_storage`](https://guides.rubyonrails.org/active_support_instrumentation.html#preview-active-storage) | |
152
+ | [`analyze.active_storage`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#analyze-active-storage) | |
153
+
154
+ ### Railties
155
+
156
+ | Event name | Supported |
157
+ | ----------------------------------------------------------------------------------------------------------------------------------------- | --------- |
158
+ | [`load_config_initializer.railties`](https://guides.rubyonrails.org/active_support_instrumentation.html#load-config-initializer-railties) | |
159
+
160
+ ### Rails
161
+
162
+ | Event name | Supported |
163
+ | ----------------------------------------------------------------------------------------------------------- | --------- |
164
+ | [`deprecation.rails`](https://guides.rubyonrails.org/active_support_instrumentation.html#deprecation-rails) | |
165
+
48
166
  ## Contributing
49
167
 
50
168
  Contributing is welcome 😄 Please open a pull request!
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionCable
5
+ module Event
6
+ # A wrapper for the event that is passed to `broadcast.action_cable`.
7
+ class Broadcast < BaseEvent
8
+ def broadcasting
9
+ @broadcasting ||= @event.payload.fetch(:broadcasting)
10
+ end
11
+
12
+ def message
13
+ @message ||= @event.payload.fetch(:message)
14
+ end
15
+
16
+ def coder
17
+ @coder ||= @event.payload.fetch(:coder)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionCable
5
+ module Event
6
+ # A wrapper for the event that is passed to `perform_action.action_cable`.
7
+ class PerformAction < BaseEvent
8
+ def channel_class
9
+ @channel_class ||= @event.payload.fetch(:channel_class)
10
+ end
11
+
12
+ def action
13
+ @action ||= @event.payload.fetch(:action)
14
+ end
15
+
16
+ def data
17
+ @data ||= @event.payload.fetch(:data)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionCable
5
+ module Event
6
+ # A wrapper for the event that is passed to `transmit.action_cable`.
7
+ class Transmit < BaseEvent
8
+ def channel_class
9
+ @channel_class ||= @event.payload.fetch(:channel_class)
10
+ end
11
+
12
+ def data
13
+ @data ||= @event.payload.fetch(:data)
14
+ end
15
+
16
+ def via
17
+ @via ||= @event.payload.fetch(:via)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionCable
5
+ module Event
6
+ # A wrapper for the event that is passed to `transmit_subscription_confirmation.action_cable`.
7
+ class TransmitSubscriptionConfirmation < BaseEvent
8
+ def channel_class
9
+ @channel_class ||= @event.payload.fetch(:channel_class)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionCable
5
+ module Event
6
+ # A wrapper for the event that is passed to `transmit_subscription_rejection.action_cable`.
7
+ class TransmitSubscriptionRejection < BaseEvent
8
+ def channel_class
9
+ @channel_class ||= @event.payload.fetch(:channel_class)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_band/action_cable/event/perform_action'
4
+ require 'rails_band/action_cable/event/transmit'
5
+ require 'rails_band/action_cable/event/transmit_subscription_confirmation'
6
+ require 'rails_band/action_cable/event/transmit_subscription_rejection'
7
+ require 'rails_band/action_cable/event/broadcast'
8
+
9
+ module RailsBand
10
+ module ActionCable
11
+ # The custom LogSubscriber for ActionCable.
12
+ class LogSubscriber < ::ActiveSupport::LogSubscriber
13
+ mattr_accessor :consumers
14
+
15
+ def perform_action(event)
16
+ consumer_of(__method__)&.call(Event::PerformAction.new(event))
17
+ end
18
+
19
+ def transmit(event)
20
+ consumer_of(__method__)&.call(Event::Transmit.new(event))
21
+ end
22
+
23
+ def transmit_subscription_confirmation(event)
24
+ consumer_of(__method__)&.call(Event::TransmitSubscriptionConfirmation.new(event))
25
+ end
26
+
27
+ def transmit_subscription_rejection(event)
28
+ consumer_of(__method__)&.call(Event::TransmitSubscriptionRejection.new(event))
29
+ end
30
+
31
+ def broadcast(event)
32
+ consumer_of(__method__)&.call(Event::Broadcast.new(event))
33
+ end
34
+
35
+ private
36
+
37
+ def consumer_of(sub_event)
38
+ consumers[:"#{sub_event}.action_cable"] || consumers[:action_cable] || consumers[:default]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionMailer
5
+ module Event
6
+ # A wrapper for the event that is passed to `deliver.action_mailer`.
7
+ class Deliver < BaseEvent
8
+ def mailer
9
+ @mailer ||= @event.payload.fetch(:mailer)
10
+ end
11
+
12
+ def message_id
13
+ @message_id ||= @event.payload.fetch(:message_id)
14
+ end
15
+
16
+ def subject
17
+ @subject ||= @event.payload.fetch(:subject)
18
+ end
19
+
20
+ def to
21
+ @to ||= @event.payload.fetch(:to)
22
+ end
23
+
24
+ def from
25
+ @from ||= @event.payload.fetch(:from)
26
+ end
27
+
28
+ def bcc
29
+ @bcc ||= @event.payload[:bcc] || []
30
+ end
31
+
32
+ def cc
33
+ @cc ||= @event.payload[:cc] || []
34
+ end
35
+
36
+ def date
37
+ @date ||= @event.payload.fetch(:date)
38
+ end
39
+
40
+ def mail
41
+ @mail ||= @event.payload.fetch(:mail)
42
+ end
43
+
44
+ def perform_deliveries
45
+ @perform_deliveries ||= @event.payload.fetch(:perform_deliveries)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionMailer
5
+ module Event
6
+ # A wrapper for the event that is passed to `process.action_mailer`.
7
+ class Process < BaseEvent
8
+ def mailer
9
+ @mailer ||= @event.payload.fetch(:mailer)
10
+ end
11
+
12
+ def action
13
+ @action ||= @event.payload.fetch(:action)
14
+ end
15
+
16
+ def args
17
+ @args ||= @event.payload.fetch(:args)
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_mailer/event/deliver'
4
+ require 'rails_band/action_mailer/event/process'
5
+
6
+ module RailsBand
7
+ module ActionMailer
8
+ # The custom LogSubscriber for ActionMailer.
9
+ class LogSubscriber < ::ActiveSupport::LogSubscriber
10
+ mattr_accessor :consumers
11
+
12
+ def deliver(event)
13
+ consumer_of(__method__)&.call(Event::Deliver.new(event))
14
+ end
15
+
16
+ def process(event)
17
+ consumer_of(__method__)&.call(Event::Process.new(event))
18
+ end
19
+
20
+ private
21
+
22
+ def consumer_of(sub_event)
23
+ consumers[:"#{sub_event}.action_mailer"] || consumers[:action_mailer] || consumers[:default]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `discard.active_job`.
7
+ class Discard < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+
16
+ def error
17
+ @error ||= @event.payload.fetch(:error)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `enqueue.active_job`.
7
+ class Enqueue < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `enqueue_at.active_job`.
7
+ class EnqueueAt < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `enqueue_retry.active_job`.
7
+ class EnqueueRetry < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+
16
+ def wait
17
+ @wait ||= @event.payload.fetch(:wait)
18
+ end
19
+
20
+ def error
21
+ @error ||= @event.payload.fetch(:error)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `perform.active_job`.
7
+ class Perform < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `perform_start.active_job`.
7
+ class PerformStart < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `retry_stopped.active_job`.
7
+ class RetryStopped < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+
16
+ def error
17
+ @error ||= @event.payload.fetch(:error)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_band/active_job/event/enqueue_at'
4
+ require 'rails_band/active_job/event/enqueue'
5
+ require 'rails_band/active_job/event/enqueue_retry'
6
+ require 'rails_band/active_job/event/perform_start'
7
+ require 'rails_band/active_job/event/perform'
8
+ require 'rails_band/active_job/event/retry_stopped'
9
+ require 'rails_band/active_job/event/discard'
10
+
11
+ module RailsBand
12
+ module ActiveJob
13
+ # The custom LogSubscriber for ActiveJob.
14
+ class LogSubscriber < ::ActiveSupport::LogSubscriber
15
+ mattr_accessor :consumers
16
+
17
+ def enqueue_at(event)
18
+ consumer_of(__method__)&.call(Event::EnqueueAt.new(event))
19
+ end
20
+
21
+ def enqueue(event)
22
+ consumer_of(__method__)&.call(Event::Enqueue.new(event))
23
+ end
24
+
25
+ def enqueue_retry(event)
26
+ consumer_of(__method__)&.call(Event::EnqueueRetry.new(event))
27
+ end
28
+
29
+ def perform_start(event)
30
+ consumer_of(__method__)&.call(Event::PerformStart.new(event))
31
+ end
32
+
33
+ def perform(event)
34
+ consumer_of(__method__)&.call(Event::Perform.new(event))
35
+ end
36
+
37
+ def retry_stopped(event)
38
+ consumer_of(__method__)&.call(Event::RetryStopped.new(event))
39
+ end
40
+
41
+ def discard(event)
42
+ consumer_of(__method__)&.call(Event::Discard.new(event))
43
+ end
44
+
45
+ private
46
+
47
+ def consumer_of(sub_event)
48
+ consumers[:"#{sub_event}.active_job"] || consumers[:active_job] || consumers[:default]
49
+ end
50
+ end
51
+ end
52
+ 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.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
@@ -24,6 +24,28 @@ module RailsBand
24
24
  require 'active_record/log_subscriber'
25
25
  swap.call(::ActiveRecord::LogSubscriber, RailsBand::ActiveRecord::LogSubscriber, :active_record)
26
26
  end
27
+
28
+ if defined?(::ActionMailer)
29
+ require 'action_mailer/log_subscriber'
30
+ swap.call(::ActionMailer::LogSubscriber, RailsBand::ActionMailer::LogSubscriber, :action_mailer)
31
+ end
32
+
33
+ if defined?(::ActionCable)
34
+ RailsBand::ActionCable::LogSubscriber.attach_to :action_cable
35
+ end
36
+
37
+ RailsBand::ActiveSupport::LogSubscriber.attach_to :active_support
38
+
39
+ if defined?(::ActiveJob)
40
+ require 'active_job/logging'
41
+
42
+ if defined?(::ActiveJob::Logging::LogSubscriber)
43
+ swap.call(::ActiveJob::Logging::LogSubscriber, RailsBand::ActiveJob::LogSubscriber, :active_job)
44
+ else
45
+ require 'active_job/log_subscriber'
46
+ swap.call(::ActiveJob::LogSubscriber, RailsBand::ActiveJob::LogSubscriber, :active_job)
47
+ end
48
+ end
27
49
  end
28
50
  end
29
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBand
4
- VERSION = '0.1.0'
4
+ VERSION = '0.5.0'
5
5
  end
data/lib/rails_band.rb CHANGED
@@ -19,4 +19,20 @@ module RailsBand
19
19
  module ActiveRecord
20
20
  autoload :LogSubscriber, 'rails_band/active_record/log_subscriber'
21
21
  end
22
+
23
+ module ActionMailer
24
+ autoload :LogSubscriber, 'rails_band/action_mailer/log_subscriber'
25
+ end
26
+
27
+ module ActiveSupport
28
+ autoload :LogSubscriber, 'rails_band/active_support/log_subscriber'
29
+ end
30
+
31
+ module ActiveJob
32
+ autoload :LogSubscriber, 'rails_band/active_job/log_subscriber'
33
+ end
34
+
35
+ module ActionCable
36
+ autoload :LogSubscriber, 'rails_band/action_cable/log_subscriber'
37
+ end
22
38
  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.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yutaka Kamei
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-19 00:00:00.000000000 Z
11
+ date: 2021-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -35,6 +35,12 @@ files:
35
35
  - README.md
36
36
  - Rakefile
37
37
  - lib/rails_band.rb
38
+ - lib/rails_band/action_cable/event/broadcast.rb
39
+ - lib/rails_band/action_cable/event/perform_action.rb
40
+ - lib/rails_band/action_cable/event/transmit.rb
41
+ - lib/rails_band/action_cable/event/transmit_subscription_confirmation.rb
42
+ - lib/rails_band/action_cable/event/transmit_subscription_rejection.rb
43
+ - lib/rails_band/action_cable/log_subscriber.rb
38
44
  - lib/rails_band/action_controller/event/exist_fragment.rb
39
45
  - lib/rails_band/action_controller/event/expire_fragment.rb
40
46
  - lib/rails_band/action_controller/event/halted_callback.rb
@@ -47,15 +53,36 @@ files:
47
53
  - lib/rails_band/action_controller/event/unpermitted_parameters.rb
48
54
  - lib/rails_band/action_controller/event/write_fragment.rb
49
55
  - lib/rails_band/action_controller/log_subscriber.rb
56
+ - lib/rails_band/action_mailer/event/deliver.rb
57
+ - lib/rails_band/action_mailer/event/process.rb
58
+ - lib/rails_band/action_mailer/log_subscriber.rb
50
59
  - lib/rails_band/action_view/event/render_collection.rb
51
60
  - lib/rails_band/action_view/event/render_partial.rb
52
61
  - lib/rails_band/action_view/event/render_template.rb
53
62
  - lib/rails_band/action_view/from_views.rb
54
63
  - lib/rails_band/action_view/log_subscriber.rb
64
+ - lib/rails_band/active_job/event/discard.rb
65
+ - lib/rails_band/active_job/event/enqueue.rb
66
+ - lib/rails_band/active_job/event/enqueue_at.rb
67
+ - lib/rails_band/active_job/event/enqueue_retry.rb
68
+ - lib/rails_band/active_job/event/perform.rb
69
+ - lib/rails_band/active_job/event/perform_start.rb
70
+ - lib/rails_band/active_job/event/retry_stopped.rb
71
+ - lib/rails_band/active_job/log_subscriber.rb
55
72
  - lib/rails_band/active_record/event/instantiation.rb
56
73
  - lib/rails_band/active_record/event/sql.rb
57
74
  - lib/rails_band/active_record/event/strict_loading_violation.rb
58
75
  - lib/rails_band/active_record/log_subscriber.rb
76
+ - lib/rails_band/active_support/event/cache_delete.rb
77
+ - lib/rails_band/active_support/event/cache_delete_multi.rb
78
+ - lib/rails_band/active_support/event/cache_exist.rb
79
+ - lib/rails_band/active_support/event/cache_fetch_hit.rb
80
+ - lib/rails_band/active_support/event/cache_generate.rb
81
+ - lib/rails_band/active_support/event/cache_read.rb
82
+ - lib/rails_band/active_support/event/cache_read_multi.rb
83
+ - lib/rails_band/active_support/event/cache_write.rb
84
+ - lib/rails_band/active_support/event/cache_write_multi.rb
85
+ - lib/rails_band/active_support/log_subscriber.rb
59
86
  - lib/rails_band/base_event.rb
60
87
  - lib/rails_band/configuration.rb
61
88
  - lib/rails_band/railtie.rb
@@ -67,7 +94,7 @@ metadata:
67
94
  homepage_uri: https://github.com/yykamei/rails_band
68
95
  source_code_uri: https://github.com/yykamei/rails_band
69
96
  changelog_uri: https://github.com/yykamei/rails_band/blob/main/CHANGELOG.md
70
- post_install_message:
97
+ post_install_message:
71
98
  rdoc_options: []
72
99
  require_paths:
73
100
  - lib
@@ -82,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
109
  - !ruby/object:Gem::Version
83
110
  version: '0'
84
111
  requirements: []
85
- rubygems_version: 3.2.22
86
- signing_key:
112
+ rubygems_version: 3.2.32
113
+ signing_key:
87
114
  specification_version: 4
88
115
  summary: Easy-to-use Rails Instrumentation API
89
116
  test_files: []