Miscellaneous Features

Last synchronized at 2026-01-12T22:47:32Z

CurrentAttributes

Rails’ CurrentAttributes allows you to set request-specific attributes which are accessible to any code executing during that request. For example, you can implement multi-tenancy by setting a tenant_id associated with each request.

Sidekiq supports persisting these attributes into every job payload to preserve any implicit state. Sidekiq will restore these attributes when the job executes.

# Put this in config/initializers/sidekiq.rb
#
require "sidekiq/middleware/current_attributes"

# Your AS::CurrentAttributes singleton, don't use
# the class directly as you shouldn't load app classes
# in your initializers.
Sidekiq::CurrentAttributes.persist("Myapp::Current")

CurrentAttributes are not visible within Sidekiq’s sidekiq_retry_in and sidekiq_retries_exhausted hooks since those hooks are called outside of the middleware context. See issue #6766 for discussion.