rails_band 0.12.0 → 0.14.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 +18 -10
- data/lib/rails_band/action_controller/event/rate_limit.rb +48 -0
- data/lib/rails_band/action_controller/log_subscriber.rb +5 -0
- data/lib/rails_band/active_job/event/interrupt.rb +34 -0
- data/lib/rails_band/active_job/event/resume.rb +30 -0
- data/lib/rails_band/active_job/event/step.rb +29 -0
- data/lib/rails_band/active_job/event/step_skipped.rb +22 -0
- data/lib/rails_band/active_job/event/step_started.rb +22 -0
- data/lib/rails_band/active_job/log_subscriber.rb +25 -0
- data/lib/rails_band/active_record/event/deprecated_association.rb +28 -0
- data/lib/rails_band/active_record/event/start_transaction.rb +18 -0
- data/lib/rails_band/active_record/event/transaction.rb +24 -0
- data/lib/rails_band/active_record/log_subscriber.rb +15 -0
- data/lib/rails_band/base_event.rb +2 -2
- data/lib/rails_band/railtie.rb +27 -3
- data/lib/rails_band/railties/event/load_config_initializer.rb +14 -0
- data/lib/rails_band/railties/log_subscriber.rb +25 -0
- data/lib/rails_band/version.rb +1 -1
- data/lib/rails_band.rb +5 -0
- metadata +14 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cdd316cd8ffd879ac92f37192896d33d5e64929fec0fedecc2c872f69c30826
|
|
4
|
+
data.tar.gz: 289a57c8e09f7fa4d8e07689c2efe8c822d229b664eb23b027cb7b9a666458a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3696c07b0669153d9eee9fd5850aca0da0bc74f9f93122ec33ed7f271f2d1432713ff8a61454ceadc7189779561ba192d9c90267b843692a1b17ae33c8c3239a
|
|
7
|
+
data.tar.gz: 1bf5d9273fb54cff96f8f2fd02ba103802a2e3d48140b01492b5fb54f366429d7ec02c2617c4a3024234cba862c0f6e06ff6e438a45fd749fd5232c0dd2bc3d1
|
data/README.md
CHANGED
|
@@ -69,6 +69,7 @@ These are Rails Instrumentation API hooks supported by this gem so far.
|
|
|
69
69
|
| [`redirect_to.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#redirect-to-action-controller) | ✅ |
|
|
70
70
|
| [`halted_callback.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#halted-callback-action-controller) | ✅ |
|
|
71
71
|
| [`unpermitted_parameters.action_controller`](https://guides.rubyonrails.org/active_support_instrumentation.html#unpermitted-parameters-action-controller) | ✅ |
|
|
72
|
+
| [`rate_limit.action_controller`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#rate-limit-action-controller) | ✅ |
|
|
72
73
|
|
|
73
74
|
### Action Dispatch
|
|
74
75
|
|
|
@@ -89,12 +90,14 @@ These are Rails Instrumentation API hooks supported by this gem so far.
|
|
|
89
90
|
|
|
90
91
|
### Active Record
|
|
91
92
|
|
|
92
|
-
| Event name
|
|
93
|
-
|
|
|
94
|
-
| `strict_loading_violation.active_record` (Not yet documented. See the configuration of `action_on_strict_loading_violation`)
|
|
95
|
-
| [`sql.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#sql-active-record)
|
|
96
|
-
| [`instantiation.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#instantiation-active-record)
|
|
97
|
-
| [`
|
|
93
|
+
| Event name | Supported |
|
|
94
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
|
|
95
|
+
| `strict_loading_violation.active_record` (Not yet documented. See the configuration of `action_on_strict_loading_violation`) | ✅ |
|
|
96
|
+
| [`sql.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#sql-active-record) | ✅ |
|
|
97
|
+
| [`instantiation.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#instantiation-active-record) | ✅ |
|
|
98
|
+
| [`start_transaction.active_record`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#start-transaction-active-record) | ✅ |
|
|
99
|
+
| [`transaction.active_record`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#transaction-active-record) | ✅ |
|
|
100
|
+
| [`deprecated_association.active_record`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#deprecated-association-active-record) | ✅ |
|
|
98
101
|
|
|
99
102
|
### Action Mailer
|
|
100
103
|
|
|
@@ -114,7 +117,7 @@ These are Rails Instrumentation API hooks supported by this gem so far.
|
|
|
114
117
|
| [`cache_write.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-write-active-support) | ✅ |
|
|
115
118
|
| [`cache_write_multi.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-write-multi-active-support) | ✅ |
|
|
116
119
|
| [`cache_increment.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-increment-active-support) | ✅ |
|
|
117
|
-
| [`cache_decrement.active_support
|
|
120
|
+
| [`cache_decrement.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-decrement-active-support) | ✅ |
|
|
118
121
|
| [`cache_delete.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-delete-active-support) | ✅ |
|
|
119
122
|
| [`cache_delete_multi.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-delete-multi-active-support) | ✅ |
|
|
120
123
|
| [`cache_delete_matched.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-delete-matched-active-support) | ✅ |
|
|
@@ -140,6 +143,11 @@ These are Rails Instrumentation API hooks supported by this gem so far.
|
|
|
140
143
|
| [`retry_stopped.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#retry-stopped-active-job) | ✅ |
|
|
141
144
|
| [`discard.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#discard-active-job) | ✅ |
|
|
142
145
|
| [`enqueue_all.active_job`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#enqueue-all-active-job) | ✅ |
|
|
146
|
+
| [`interrupt.active_job`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#interrupt-active-job) | ✅ |
|
|
147
|
+
| [`resume.active_job`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#resume-active-job) | ✅ |
|
|
148
|
+
| [`step.active_job`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#step-active-job) | ✅ |
|
|
149
|
+
| [`step_skipped.active_job`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#step-skipped-active-job) | ✅ |
|
|
150
|
+
| [`step_started.active_job`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#step-started-active-job) | ✅ |
|
|
143
151
|
|
|
144
152
|
### Action Cable
|
|
145
153
|
|
|
@@ -176,9 +184,9 @@ These are Rails Instrumentation API hooks supported by this gem so far.
|
|
|
176
184
|
|
|
177
185
|
### Railties
|
|
178
186
|
|
|
179
|
-
| Event name
|
|
180
|
-
|
|
|
181
|
-
| [`load_config_initializer.railties`](https://
|
|
187
|
+
| Event name | Supported |
|
|
188
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
|
|
189
|
+
| [`load_config_initializer.railties`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#load-config-initializer-railties) | ✅ |
|
|
182
190
|
|
|
183
191
|
### Rails
|
|
184
192
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsBand
|
|
4
|
+
module ActionController
|
|
5
|
+
module Event
|
|
6
|
+
# A wrapper for the event that is passed to `rate_limit.action_controller`.
|
|
7
|
+
class RateLimit < BaseEvent
|
|
8
|
+
def request
|
|
9
|
+
@request ||= @event.payload.fetch(:request)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# @note The following attributes are only available in Rails 8.1+
|
|
13
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('8.1.0.alpha')
|
|
14
|
+
define_method(:count) do
|
|
15
|
+
@count ||= @event.payload.fetch(:count)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
define_method(:to) do
|
|
19
|
+
@to ||= @event.payload.fetch(:to)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
define_method(:within) do
|
|
23
|
+
@within ||= @event.payload.fetch(:within)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
define_method(:by) do
|
|
27
|
+
@by ||= @event.payload.fetch(:by)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @note This method is renamed in order to avoid conflicts with BaseEvent#name.
|
|
31
|
+
define_method(:rate_limit_name) do
|
|
32
|
+
return @rate_limit_name if defined? @rate_limit_name
|
|
33
|
+
|
|
34
|
+
@rate_limit_name = @event.payload[:name]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
define_method(:scope) do
|
|
38
|
+
@scope ||= @event.payload.fetch(:scope)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
define_method(:cache_key) do
|
|
42
|
+
@cache_key ||= @event.payload.fetch(:cache_key)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -12,6 +12,7 @@ require 'rails_band/action_controller/event/send_data'
|
|
|
12
12
|
require 'rails_band/action_controller/event/redirect_to'
|
|
13
13
|
require 'rails_band/action_controller/event/halted_callback'
|
|
14
14
|
require 'rails_band/action_controller/event/unpermitted_parameters'
|
|
15
|
+
require 'rails_band/action_controller/event/rate_limit'
|
|
15
16
|
|
|
16
17
|
module RailsBand
|
|
17
18
|
module ActionController
|
|
@@ -71,6 +72,10 @@ module RailsBand
|
|
|
71
72
|
consumer_of(__method__)&.call(Event::UnpermittedParameters.new(event))
|
|
72
73
|
end
|
|
73
74
|
|
|
75
|
+
def rate_limit(event)
|
|
76
|
+
consumer_of(__method__)&.call(Event::RateLimit.new(event))
|
|
77
|
+
end
|
|
78
|
+
|
|
74
79
|
private
|
|
75
80
|
|
|
76
81
|
def consumer_of(sub_event)
|
|
@@ -0,0 +1,34 @@
|
|
|
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 `interrupt.active_job`.
|
|
7
|
+
class Interrupt < 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 reason
|
|
17
|
+
@reason ||= @event.payload.fetch(:reason)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def description
|
|
21
|
+
@description ||= @event.payload.fetch(:description)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def completed_steps
|
|
25
|
+
@completed_steps ||= @event.payload.fetch(:completed_steps)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def current_step
|
|
29
|
+
@current_step ||= @event.payload[:current_step]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
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 `resume.active_job`.
|
|
7
|
+
class Resume < 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 description
|
|
17
|
+
@description ||= @event.payload.fetch(:description)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def completed_steps
|
|
21
|
+
@completed_steps ||= @event.payload.fetch(:completed_steps)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def current_step
|
|
25
|
+
@current_step ||= @event.payload[:current_step]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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 `step.active_job`.
|
|
7
|
+
# Unlike `StepSkipped#step`, this is the step itself, not the step name.
|
|
8
|
+
class Step < BaseEvent
|
|
9
|
+
def adapter
|
|
10
|
+
@adapter ||= @event.payload.fetch(:adapter)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def job
|
|
14
|
+
@job ||= @event.payload.fetch(:job)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def step
|
|
18
|
+
@step ||= @event.payload.fetch(:step)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def interrupted
|
|
22
|
+
return @interrupted if defined?(@interrupted)
|
|
23
|
+
|
|
24
|
+
@interrupted = @event.payload.fetch(:interrupted)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
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 `step_skipped.active_job`.
|
|
7
|
+
class StepSkipped < 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 step
|
|
17
|
+
@step ||= @event.payload.fetch(:step)
|
|
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 ActiveJob
|
|
5
|
+
module Event
|
|
6
|
+
# A wrapper for the event that is passed to `step_started.active_job`.
|
|
7
|
+
class StepStarted < 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 step
|
|
17
|
+
@step ||= @event.payload.fetch(:step)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -8,6 +8,11 @@ require 'rails_band/active_job/event/perform_start'
|
|
|
8
8
|
require 'rails_band/active_job/event/perform'
|
|
9
9
|
require 'rails_band/active_job/event/retry_stopped'
|
|
10
10
|
require 'rails_band/active_job/event/discard'
|
|
11
|
+
require 'rails_band/active_job/event/interrupt'
|
|
12
|
+
require 'rails_band/active_job/event/resume'
|
|
13
|
+
require 'rails_band/active_job/event/step'
|
|
14
|
+
require 'rails_band/active_job/event/step_skipped'
|
|
15
|
+
require 'rails_band/active_job/event/step_started'
|
|
11
16
|
|
|
12
17
|
module RailsBand
|
|
13
18
|
module ActiveJob
|
|
@@ -47,6 +52,26 @@ module RailsBand
|
|
|
47
52
|
consumer_of(__method__)&.call(Event::EnqueueAll.new(event))
|
|
48
53
|
end
|
|
49
54
|
|
|
55
|
+
def interrupt(event)
|
|
56
|
+
consumer_of(__method__)&.call(Event::Interrupt.new(event))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def resume(event)
|
|
60
|
+
consumer_of(__method__)&.call(Event::Resume.new(event))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def step(event)
|
|
64
|
+
consumer_of(__method__)&.call(Event::Step.new(event))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def step_skipped(event)
|
|
68
|
+
consumer_of(__method__)&.call(Event::StepSkipped.new(event))
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def step_started(event)
|
|
72
|
+
consumer_of(__method__)&.call(Event::StepStarted.new(event))
|
|
73
|
+
end
|
|
74
|
+
|
|
50
75
|
private
|
|
51
76
|
|
|
52
77
|
def consumer_of(sub_event)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsBand
|
|
4
|
+
module ActiveRecord
|
|
5
|
+
module Event
|
|
6
|
+
# A wrapper for the event that is passed to `deprecated_association.active_record`.
|
|
7
|
+
class DeprecatedAssociation < BaseEvent
|
|
8
|
+
def reflection
|
|
9
|
+
@reflection ||= @event.payload.fetch(:reflection)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def message
|
|
13
|
+
@message ||= @event.payload.fetch(:message)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def location
|
|
17
|
+
@location ||= @event.payload.fetch(:location)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# `:backtrace` is only present when the option is enabled; `fetch` would
|
|
21
|
+
# raise KeyError in the default configuration.
|
|
22
|
+
def backtrace
|
|
23
|
+
@backtrace ||= @event.payload[:backtrace]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsBand
|
|
4
|
+
module ActiveRecord
|
|
5
|
+
module Event
|
|
6
|
+
# A wrapper for the event that is passed to `start_transaction.active_record`.
|
|
7
|
+
class StartTransaction < BaseEvent
|
|
8
|
+
def transaction
|
|
9
|
+
@transaction ||= @event.payload.fetch(:transaction)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def connection
|
|
13
|
+
@connection ||= @event.payload.fetch(:connection)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsBand
|
|
4
|
+
module ActiveRecord
|
|
5
|
+
module Event
|
|
6
|
+
# A wrapper for the event that is passed to `transaction.active_record`.
|
|
7
|
+
class Transaction < BaseEvent
|
|
8
|
+
# The `:transaction` key was added in Rails 7.2. It is absent on Rails 7.1,
|
|
9
|
+
# where this event is also emitted with only `:connection` and `:outcome`.
|
|
10
|
+
def transaction
|
|
11
|
+
@transaction ||= @event.payload[:transaction]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def outcome
|
|
15
|
+
@outcome ||= @event.payload.fetch(:outcome)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def connection
|
|
19
|
+
@connection ||= @event.payload.fetch(:connection)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
require 'rails_band/active_record/event/sql'
|
|
4
4
|
require 'rails_band/active_record/event/instantiation'
|
|
5
5
|
require 'rails_band/active_record/event/strict_loading_violation'
|
|
6
|
+
require 'rails_band/active_record/event/start_transaction'
|
|
7
|
+
require 'rails_band/active_record/event/transaction'
|
|
8
|
+
require 'rails_band/active_record/event/deprecated_association'
|
|
6
9
|
|
|
7
10
|
module RailsBand
|
|
8
11
|
module ActiveRecord
|
|
@@ -22,6 +25,18 @@ module RailsBand
|
|
|
22
25
|
consumer_of(__method__)&.call(Event::Instantiation.new(event))
|
|
23
26
|
end
|
|
24
27
|
|
|
28
|
+
def start_transaction(event)
|
|
29
|
+
consumer_of(__method__)&.call(Event::StartTransaction.new(event))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def transaction(event)
|
|
33
|
+
consumer_of(__method__)&.call(Event::Transaction.new(event))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def deprecated_association(event)
|
|
37
|
+
consumer_of(__method__)&.call(Event::DeprecatedAssociation.new(event))
|
|
38
|
+
end
|
|
39
|
+
|
|
25
40
|
private
|
|
26
41
|
|
|
27
42
|
def consumer_of(sub_event)
|
|
@@ -24,8 +24,8 @@ module RailsBand
|
|
|
24
24
|
name: @name, time: @time, end: @end, transaction_id: @transaction_id,
|
|
25
25
|
cpu_time: @cpu_time, idle_time: @idle_time, allocations: @allocations, duration: @duration
|
|
26
26
|
}.merge!(
|
|
27
|
-
public_methods(false).reject { |meth| non_hash_keys.include?(meth) }.
|
|
28
|
-
|
|
27
|
+
public_methods(false).reject { |meth| non_hash_keys.include?(meth) }.to_h do |meth|
|
|
28
|
+
[meth, public_send(meth)]
|
|
29
29
|
end
|
|
30
30
|
)
|
|
31
31
|
end
|
data/lib/rails_band/railtie.rb
CHANGED
|
@@ -8,19 +8,27 @@ module RailsBand
|
|
|
8
8
|
class Railtie < ::Rails::Railtie
|
|
9
9
|
config.rails_band = Configuration.new
|
|
10
10
|
|
|
11
|
-
config.before_initialize do
|
|
11
|
+
config.before_initialize do |app|
|
|
12
12
|
# NOTE: `ActionDispatch::MiddlewareStack::InstrumentationProxy` will be called
|
|
13
13
|
# only when `ActionDispatch::MiddlewareStack#build` detects `process_middleware.action_dispatch`
|
|
14
14
|
# is listened to. So, `attach_to` must be called before Rack middlewares will be loaded.
|
|
15
|
-
|
|
15
|
+
if defined?(::ActionDispatch::LogSubscriber)
|
|
16
|
+
detach_log_subscriber(::ActionDispatch::LogSubscriber, :action_dispatch)
|
|
17
|
+
end
|
|
16
18
|
RailsBand::ActionDispatch::LogSubscriber.attach_to :action_dispatch
|
|
19
|
+
|
|
20
|
+
# NOTE: `load_config_initializer.railties` is emitted while Rails loads
|
|
21
|
+
# config/initializers/*. So, the subscriber must be attached before
|
|
22
|
+
# Rails loads them.
|
|
23
|
+
RailsBand::Railties::LogSubscriber.consumers = app.config.rails_band.consumers
|
|
24
|
+
RailsBand::Railties::LogSubscriber.attach_to :railties
|
|
17
25
|
end
|
|
18
26
|
|
|
19
27
|
config.after_initialize do |app|
|
|
20
28
|
consumers = app.config.rails_band.consumers
|
|
21
29
|
|
|
22
30
|
swap = lambda { |old_class, new_class, namespace|
|
|
23
|
-
old_class
|
|
31
|
+
detach_log_subscriber(old_class, namespace)
|
|
24
32
|
new_class.consumers = consumers
|
|
25
33
|
new_class.attach_to namespace
|
|
26
34
|
}
|
|
@@ -56,6 +64,8 @@ module RailsBand
|
|
|
56
64
|
RailsBand::DeprecationSubscriber.consumers = consumers
|
|
57
65
|
RailsBand::DeprecationSubscriber.attach_to :rails
|
|
58
66
|
|
|
67
|
+
RailsBand::Railties::LogSubscriber.consumers = consumers
|
|
68
|
+
|
|
59
69
|
if defined?(::ActiveJob)
|
|
60
70
|
require 'active_job/logging'
|
|
61
71
|
|
|
@@ -72,5 +82,19 @@ module RailsBand
|
|
|
72
82
|
RailsBand::ActionMailbox::LogSubscriber.attach_to :action_mailbox
|
|
73
83
|
end
|
|
74
84
|
end
|
|
85
|
+
|
|
86
|
+
# Helper method to detach log subscribers in a way that's compatible with both
|
|
87
|
+
# Rails < 8.1 (using detach_from) and Rails >= 8.1 (using unsubscribe)
|
|
88
|
+
def self.detach_log_subscriber(log_subscriber_class, namespace)
|
|
89
|
+
if log_subscriber_class.respond_to?(:detach_from)
|
|
90
|
+
# Rails < 8.1: use detach_from method
|
|
91
|
+
log_subscriber_class.detach_from namespace
|
|
92
|
+
elsif log_subscriber_class.respond_to?(:unsubscribe)
|
|
93
|
+
# Rails >= 8.1: use unsubscribe method
|
|
94
|
+
log_subscriber_class.unsubscribe
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
private_class_method :detach_log_subscriber
|
|
75
99
|
end
|
|
76
100
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsBand
|
|
4
|
+
module Railties
|
|
5
|
+
module Event
|
|
6
|
+
# A wrapper for the event that is passed to `load_config_initializer.railties`.
|
|
7
|
+
class LoadConfigInitializer < BaseEvent
|
|
8
|
+
def initializer
|
|
9
|
+
@initializer ||= @event.payload.fetch(:initializer)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_band/railties/event/load_config_initializer'
|
|
4
|
+
|
|
5
|
+
module RailsBand
|
|
6
|
+
module Railties
|
|
7
|
+
# LogSubscriber is responsible for calling the user-specified consumer for railties events.
|
|
8
|
+
class LogSubscriber < ::ActiveSupport::LogSubscriber
|
|
9
|
+
mattr_accessor :consumers
|
|
10
|
+
|
|
11
|
+
def load_config_initializer(event)
|
|
12
|
+
consumer&.call(Event::LoadConfigInitializer.new(event))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def consumer
|
|
18
|
+
# HACK: ActiveSupport::Subscriber has the instance variable @namespace, but it's not documented.
|
|
19
|
+
# This hack might possibly break in the future.
|
|
20
|
+
namespace = self.class.instance_variable_get(:@namespace)
|
|
21
|
+
consumers[:"load_config_initializer.#{namespace}"] || consumers[:railties] || consumers[:default]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/rails_band/version.rb
CHANGED
data/lib/rails_band.rb
CHANGED
|
@@ -58,4 +58,9 @@ module RailsBand
|
|
|
58
58
|
module ActionMailbox
|
|
59
59
|
autoload :LogSubscriber, 'rails_band/action_mailbox/log_subscriber'
|
|
60
60
|
end
|
|
61
|
+
|
|
62
|
+
# RailsBand::Railties is responsible for subscribing notifications from Railties.
|
|
63
|
+
module Railties
|
|
64
|
+
autoload :LogSubscriber, 'rails_band/railties/log_subscriber'
|
|
65
|
+
end
|
|
61
66
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_band
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yutaka Kamei
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rails
|
|
@@ -51,6 +50,7 @@ files:
|
|
|
51
50
|
- lib/rails_band/action_controller/event/expire_fragment.rb
|
|
52
51
|
- lib/rails_band/action_controller/event/halted_callback.rb
|
|
53
52
|
- lib/rails_band/action_controller/event/process_action.rb
|
|
53
|
+
- lib/rails_band/action_controller/event/rate_limit.rb
|
|
54
54
|
- lib/rails_band/action_controller/event/read_fragment.rb
|
|
55
55
|
- lib/rails_band/action_controller/event/redirect_to.rb
|
|
56
56
|
- lib/rails_band/action_controller/event/send_data.rb
|
|
@@ -80,13 +80,21 @@ files:
|
|
|
80
80
|
- lib/rails_band/active_job/event/enqueue_all.rb
|
|
81
81
|
- lib/rails_band/active_job/event/enqueue_at.rb
|
|
82
82
|
- lib/rails_band/active_job/event/enqueue_retry.rb
|
|
83
|
+
- lib/rails_band/active_job/event/interrupt.rb
|
|
83
84
|
- lib/rails_band/active_job/event/perform.rb
|
|
84
85
|
- lib/rails_band/active_job/event/perform_start.rb
|
|
86
|
+
- lib/rails_band/active_job/event/resume.rb
|
|
85
87
|
- lib/rails_band/active_job/event/retry_stopped.rb
|
|
88
|
+
- lib/rails_band/active_job/event/step.rb
|
|
89
|
+
- lib/rails_band/active_job/event/step_skipped.rb
|
|
90
|
+
- lib/rails_band/active_job/event/step_started.rb
|
|
86
91
|
- lib/rails_band/active_job/log_subscriber.rb
|
|
92
|
+
- lib/rails_band/active_record/event/deprecated_association.rb
|
|
87
93
|
- lib/rails_band/active_record/event/instantiation.rb
|
|
88
94
|
- lib/rails_band/active_record/event/sql.rb
|
|
95
|
+
- lib/rails_band/active_record/event/start_transaction.rb
|
|
89
96
|
- lib/rails_band/active_record/event/strict_loading_violation.rb
|
|
97
|
+
- lib/rails_band/active_record/event/transaction.rb
|
|
90
98
|
- lib/rails_band/active_record/log_subscriber.rb
|
|
91
99
|
- lib/rails_band/active_storage/event/analyze.rb
|
|
92
100
|
- lib/rails_band/active_storage/event/preview.rb
|
|
@@ -121,6 +129,8 @@ files:
|
|
|
121
129
|
- lib/rails_band/configuration.rb
|
|
122
130
|
- lib/rails_band/deprecation_subscriber.rb
|
|
123
131
|
- lib/rails_band/railtie.rb
|
|
132
|
+
- lib/rails_band/railties/event/load_config_initializer.rb
|
|
133
|
+
- lib/rails_band/railties/log_subscriber.rb
|
|
124
134
|
- lib/rails_band/version.rb
|
|
125
135
|
homepage: https://github.com/yykamei/rails_band
|
|
126
136
|
licenses:
|
|
@@ -129,7 +139,6 @@ metadata:
|
|
|
129
139
|
homepage_uri: https://github.com/yykamei/rails_band
|
|
130
140
|
source_code_uri: https://github.com/yykamei/rails_band
|
|
131
141
|
rubygems_mfa_required: 'true'
|
|
132
|
-
post_install_message:
|
|
133
142
|
rdoc_options: []
|
|
134
143
|
require_paths:
|
|
135
144
|
- lib
|
|
@@ -144,8 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
144
153
|
- !ruby/object:Gem::Version
|
|
145
154
|
version: '0'
|
|
146
155
|
requirements: []
|
|
147
|
-
rubygems_version: 3.
|
|
148
|
-
signing_key:
|
|
156
|
+
rubygems_version: 3.6.9
|
|
149
157
|
specification_version: 4
|
|
150
158
|
summary: Easy-to-use Rails Instrumentation API
|
|
151
159
|
test_files: []
|