Skip to content

Easy-to-use Rails Instrumentation API

License

Notifications You must be signed in to change notification settings

yykamei/rails_band

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rails_band

GitHub Actions workflow status 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

Event name Supported
write_fragment.action_controller
read_fragment.action_controller
expire_fragment.action_controller
exist_fragment?.action_controller
start_processing.action_controller
process_action.action_controller
send_file.action_controller
send_stream.action_controller
send_data.action_controller
redirect_to.action_controller
halted_callback.action_controller
unpermitted_parameters.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

Event name Supported
cache_read.active_support
cache_read_multi.active_support
cache_generate.active_support
cache_fetch_hit.active_support
cache_write.active_support
cache_write_multi.active_support
cache_increment.active_support
cache_decrement.active_support
cache_delete.active_support
cache_delete_multi.active_support
cache_delete_matched.active_support
cache_cleanup.active_support
cache_prune.active_support
cache_exist?.active_support

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

Event name Supported
service_upload.active_storage
service_streaming_download.active_storage
service_download_chunk.active_storage
service_download.active_storage
service_delete.active_storage
service_delete_prefixed.active_storage
service_exist.active_storage
service_url.active_storage
service_update_metadata.active_storage
preview.active_storage
transform.active_storage
analyze.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.