rails_band 0.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25195f352d9f1105a0dc497aff31a087310185a09133674516ec77e1f44b00ab
4
- data.tar.gz: 62a96059041df354354cbb871997bc367c0fd5132e526c3888ac955796b326df
3
+ metadata.gz: 8cdd316cd8ffd879ac92f37192896d33d5e64929fec0fedecc2c872f69c30826
4
+ data.tar.gz: 289a57c8e09f7fa4d8e07689c2efe8c822d229b664eb23b027cb7b9a666458a0
5
5
  SHA512:
6
- metadata.gz: a4518ad9565c64461de711c8d73e6567046e81385ed5b05fb17a63e35495b767b02d6177ca6952a6496a7152e6c75a82351d805fdcbbc9e977cd348dffe14db9
7
- data.tar.gz: d8b7090706903ba8dc95bd7e1ff7823c1354577483407829fc94ed5194d6e9443b6f1c36de106998641be1549834fdb2c135002b5981f4fa0e83b19bd97bd521
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
 
@@ -95,7 +96,8 @@ These are Rails Instrumentation API hooks supported by this gem so far.
95
96
  | [`sql.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#sql-active-record) | ✅ |
96
97
  | [`instantiation.active_record`](https://guides.rubyonrails.org/active_support_instrumentation.html#instantiation-active-record) | ✅ |
97
98
  | [`start_transaction.active_record`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#start-transaction-active-record) | ✅ |
98
- | [`transaction.active_record`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#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) | ✅ |
99
101
 
100
102
  ### Action Mailer
101
103
 
@@ -115,7 +117,7 @@ These are Rails Instrumentation API hooks supported by this gem so far.
115
117
  | [`cache_write.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-write-active-support) | ✅ |
116
118
  | [`cache_write_multi.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-write-multi-active-support) | ✅ |
117
119
  | [`cache_increment.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-increment-active-support) | ✅ |
118
- | [`cache_decrement.active_support `](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-decrement-active-support) | ✅ |
120
+ | [`cache_decrement.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-decrement-active-support) | ✅ |
119
121
  | [`cache_delete.active_support`](https://guides.rubyonrails.org/active_support_instrumentation.html#cache-delete-active-support) | ✅ |
120
122
  | [`cache_delete_multi.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-delete-multi-active-support) | ✅ |
121
123
  | [`cache_delete_matched.active_support`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#cache-delete-matched-active-support) | ✅ |
@@ -141,6 +143,11 @@ These are Rails Instrumentation API hooks supported by this gem so far.
141
143
  | [`retry_stopped.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#retry-stopped-active-job) | ✅ |
142
144
  | [`discard.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#discard-active-job) | ✅ |
143
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) | ✅ |
144
151
 
145
152
  ### Action Cable
146
153
 
@@ -179,7 +186,7 @@ These are Rails Instrumentation API hooks supported by this gem so far.
179
186
 
180
187
  | Event name | Supported |
181
188
  | --------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
182
- | [`load_config_initializer.railties`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#load-config-initializer-railties) | |
189
+ | [`load_config_initializer.railties`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#load-config-initializer-railties) | ✅ |
183
190
 
184
191
  ### Rails
185
192
 
@@ -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,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
@@ -4,6 +4,8 @@ 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
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'
7
9
 
8
10
  module RailsBand
9
11
  module ActiveRecord
@@ -27,6 +29,14 @@ module RailsBand
27
29
  consumer_of(__method__)&.call(Event::StartTransaction.new(event))
28
30
  end
29
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
+
30
40
  private
31
41
 
32
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) }.each_with_object({}) do |meth, h|
28
- h[meth] = public_send(meth)
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
@@ -8,7 +8,7 @@ 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.
@@ -16,6 +16,12 @@ module RailsBand
16
16
  detach_log_subscriber(::ActionDispatch::LogSubscriber, :action_dispatch)
17
17
  end
18
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
19
25
  end
20
26
 
21
27
  config.after_initialize do |app|
@@ -58,6 +64,8 @@ module RailsBand
58
64
  RailsBand::DeprecationSubscriber.consumers = consumers
59
65
  RailsBand::DeprecationSubscriber.attach_to :rails
60
66
 
67
+ RailsBand::Railties::LogSubscriber.consumers = consumers
68
+
61
69
  if defined?(::ActiveJob)
62
70
  require 'active_job/logging'
63
71
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBand
4
- VERSION = '0.13.0'
4
+ VERSION = '0.14.0'
5
5
  end
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_band
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yutaka Kamei
@@ -80,14 +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
89
95
  - lib/rails_band/active_record/event/start_transaction.rb
90
96
  - lib/rails_band/active_record/event/strict_loading_violation.rb
97
+ - lib/rails_band/active_record/event/transaction.rb
91
98
  - lib/rails_band/active_record/log_subscriber.rb
92
99
  - lib/rails_band/active_storage/event/analyze.rb
93
100
  - lib/rails_band/active_storage/event/preview.rb
@@ -122,6 +129,8 @@ files:
122
129
  - lib/rails_band/configuration.rb
123
130
  - lib/rails_band/deprecation_subscriber.rb
124
131
  - lib/rails_band/railtie.rb
132
+ - lib/rails_band/railties/event/load_config_initializer.rb
133
+ - lib/rails_band/railties/log_subscriber.rb
125
134
  - lib/rails_band/version.rb
126
135
  homepage: https://github.com/yykamei/rails_band
127
136
  licenses: