Easy-to-use Rails Instrumentation API.
Add this line to your application's Gemfile:
gem 'rails_band'
And then execute:
bundle
Or install it yourself as:
gem install rails_band
rails_band automatically replaces each LogSubscriber
with its own ones after it's loaded as a gem. And then, you
should configure how to consume Instrumentation hooks from core Rails implementations like this:
Rails.application.config.rails_band.consumers = ->(event) { Rails.logger.info(event.to_h) }
You can also configure it by specifying event names:
Rails.application.config.rails_band.consumers = {
default: ->(event) { Rails.logger.info(event.to_h) },
action_controller: ->(event) { Rails.logger.info(event.slice(:name, :method, :path, :status, :controller, :action)) },
'sql.active_record': ->(event) { Rails.logger.debug("#{event.sql_name}: #{event.sql}") },
}
Note :default
is the fallback of other non-specific event names. Other events will be ignored without :default
. In
other words, you can consume only events that you want to really consume without :default
.
rails_band does not limit you only to use logging purposes. Enjoy with Rails Instrumentation hooks!
These are Rails Instrumentation API hooks supported by this gem so far.
Event name | Supported |
---|---|
process_middleware.action_dispatch |
✅ |
redirect.action_dispatch |
✅ |
request.action_dispatch |
✅ |
Event name | Supported |
---|---|
render_template.action_view |
✅ |
render_partial.action_view |
✅ |
render_collection.action_view |
✅ |
render_layout.action_view |
✅ |
Event name | Supported |
---|---|
strict_loading_violation.active_record (Not yet documented. See the configuration of action_on_strict_loading_violation ) |
✅ |
sql.active_record |
✅ |
instantiation.active_record |
✅ |
transaction.active_record |
Event name | Supported |
---|---|
deliver.action_mailer |
✅ |
process.action_mailer |
✅ |
Event name | Supported |
---|---|
message_serializer_fallback.active_support |
✅ |
Event name | Supported |
---|---|
enqueue_at.active_job |
✅ |
enqueue.active_job |
✅ |
enqueue_retry.active_job |
✅ |
perform_start.active_job |
✅ |
perform.active_job |
✅ |
retry_stopped.active_job |
✅ |
discard.active_job |
✅ |
enqueue_all.active_job |
✅ |
Event name | Supported |
---|---|
perform_action.action_cable |
✅ |
transmit.action_cable |
✅ |
transmit_subscription_confirmation.action_cable |
✅ |
transmit_subscription_rejection.action_cable |
✅ |
broadcast.action_cable |
✅ |
Event name | Supported |
---|---|
process.action_mailbox |
✅ |
Event name | Supported |
---|---|
load_config_initializer.railties |
Event name | Supported |
---|---|
deprecation.rails |
✅ |
Contributing is welcome 😄 Please open a pull request!
The gem is available as open source under the terms of the MIT License.