rails_band
Easy-to-use Rails Instrumentation API.
Installation
Add this line to your application’s Gemfile:
gem 'rails_band'
And then execute:
bundle
Or install it yourself as:
gem install rails_band
Usage
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!
Supported Instrumentation API hooks
These are Rails Instrumentation API hooks supported by this gem so far.
Action Controller
Action Dispatch
Event name | Supported |
---|---|
process_middleware.action_dispatch |
✅ |
redirect.action_dispatch |
✅ |
request.action_dispatch |
✅ |
Action View
Event name | Supported |
---|---|
render_template.action_view |
✅ |
render_partial.action_view |
✅ |
render_collection.action_view |
✅ |
render_layout.action_view |
✅ |
Active Record
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 |
Action Mailer
Event name | Supported |
---|---|
deliver.action_mailer |
✅ |
process.action_mailer |
✅ |
Active Support — Caching
Active Support — Messages
Event name | Supported |
---|---|
message_serializer_fallback.active_support |
✅ |
Active Job
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 |
✅ |
Action Cable
Event name | Supported |
---|---|
perform_action.action_cable |
✅ |
transmit.action_cable |
✅ |
transmit_subscription_confirmation.action_cable |
✅ |
transmit_subscription_rejection.action_cable |
✅ |
broadcast.action_cable |
✅ |
Active Storage
Action Mailbox
Event name | Supported |
---|---|
process.action_mailbox |
✅ |
Railties
Event name | Supported |
---|---|
load_config_initializer.railties |
Rails
Event name | Supported |
---|---|
deprecation.rails |
✅ |
Contributing
Contributing is welcome 😄 Please open a pull request!
License
The gem is available as open source under the terms of the MIT License.