### Sample log output Source: https://github.com/zombocom/rack-timeout/blob/main/doc/logging.md Example of the key=value log format produced by Rack::Timeout. ```text source=rack-timeout id=13793c wait=369ms timeout=10000ms state=ready at=info source=rack-timeout id=13793c wait=369ms timeout=10000ms service=15ms state=completed at=info source=rack-timeout id=ea7bd3 wait=371ms timeout=10000ms state=timed_out at=error ``` -------------------------------- ### Run Test Suite Source: https://github.com/zombocom/rack-timeout/blob/main/README.md Commands to install dependencies and execute the test suite for the project. ```console bundle bundle exec rake test ``` -------------------------------- ### Configure logger device and level Source: https://github.com/zombocom/rack-timeout/blob/main/doc/logging.md Use helper setters to define the output device and log level. These calls can be combined to configure the final logger instance. ```ruby Rack::Timeout::Logger.device = $stderr Rack::Timeout::Logger.level = Logger::INFO ``` -------------------------------- ### Rack::Timeout Configuration Settings Source: https://github.com/zombocom/rack-timeout/blob/main/README.md Default settings and their corresponding environment variable names. ```text service_timeout: 15 # RACK_TIMEOUT_SERVICE_TIMEOUT wait_timeout: 30 # RACK_TIMEOUT_WAIT_TIMEOUT wait_overtime: 60 # RACK_TIMEOUT_WAIT_OVERTIME service_past_wait: false # RACK_TIMEOUT_SERVICE_PAST_WAIT term_on_timeout: false # RACK_TIMEOUT_TERM_ON_TIMEOUT ``` -------------------------------- ### Configure Rack::Timeout for Sinatra or Rack Apps Source: https://github.com/zombocom/rack-timeout/blob/main/README.md Add the middleware to the config.ru file, ideally as early as possible in the stack. ```ruby # config.ru require "rack-timeout" # Call as early as possible so rack-timeout runs before all other middleware. # Setting service_timeout or `RACK_TIMEOUT_SERVICE_TIMEOUT` environment # variable is recommended. If omitted, defaults to 15 seconds. use Rack::Timeout, service_timeout: 15 ``` -------------------------------- ### Manually Configure Rack::Timeout in Rails Source: https://github.com/zombocom/rack-timeout/blob/main/README.md Use this approach if you need to control the middleware stack position or require the base library manually. ```ruby # Gemfile gem "rack-timeout", require: "rack/timeout/base" ``` ```ruby # config/initializers/rack_timeout.rb # insert middleware wherever you want in the stack, optionally pass # initialization arguments, or use environment variables Rails.application.config.middleware.insert_before Rack::Runtime, Rack::Timeout, service_timeout: 15 ``` -------------------------------- ### Register a state change observer Source: https://github.com/zombocom/rack-timeout/blob/main/doc/observers.md Registers a block to be executed whenever the request state changes. The observer receives the Rack environment as an argument. ```ruby Rack::Timeout.register_state_change_observer(:a_unique_name) { |env| do_things env } ``` -------------------------------- ### Override Settings via Middleware Source: https://github.com/zombocom/rack-timeout/blob/main/README.md Middleware parameters take precedence over environment variables when configuring timeouts. ```ruby use Rack::Timeout, service_timeout: 15, wait_timeout: 30 ``` -------------------------------- ### Add Rack::Timeout to Rails Gemfile Source: https://github.com/zombocom/rack-timeout/blob/main/README.md Include the gem in the Gemfile to automatically load and configure the middleware with default settings. ```ruby # Gemfile gem "rack-timeout" ``` -------------------------------- ### Monitor SIGTERM Logs Source: https://github.com/zombocom/rack-timeout/blob/main/doc/settings.md Identify when a process is being restarted by rack-timeout by checking for this specific log message. ```text Request ran for longer than 1000ms, sending SIGTERM to process 3925 ``` -------------------------------- ### Verify Puma Cluster Mode Source: https://github.com/zombocom/rack-timeout/blob/main/doc/settings.md Check server logs to confirm the application is running in cluster mode with multiple workers. ```text [3922] Puma starting in cluster mode... [3922] * Version 4.3.0 (ruby 2.6.5-p114), codename: Mysterious Traveller [3922] * Min threads: 0, max threads: 16 [3922] * Environment: development [3922] * Process workers: 2 [3922] * Phased restart available [3922] * Listening on tcp://0.0.0.0:9292 [3922] Use Ctrl-C to stop [3922] - Worker 0 (pid: 3924) booted, phase: 0 [3922] - Worker 1 (pid: 3925) booted, phase: 0 ``` -------------------------------- ### Enable term_on_timeout on Heroku Source: https://github.com/zombocom/rack-timeout/blob/main/doc/settings.md Set the RACK_TIMEOUT_TERM_ON_TIMEOUT environment variable to 1 to enable process termination on the first timeout. ```bash $ heroku config:set RACK_TIMEOUT_TERM_ON_TIMEOUT=1 ``` -------------------------------- ### Configure Rollbar Custom Fingerprints Source: https://github.com/zombocom/rack-timeout/blob/main/doc/rollbar.md Use this JSON configuration in Rollbar to group timeout exceptions by controller and action, preventing fragmented error reports. ```json [ { "condition": { "eq": "Rack::Timeout::RequestTimeoutException", "path": "body.trace.exception.class" }, "fingerprint": "Rack::Timeout::RequestTimeoutException {{context}}", "title": "Rack::Timeout::RequestTimeoutException {{context}}" } ] ``` -------------------------------- ### Rack::Timeout.register_state_change_observer Source: https://github.com/zombocom/rack-timeout/blob/main/doc/observers.md Registers a block to be executed whenever the request state changes. The block receives the Rack environment as an argument. ```APIDOC ## Rack::Timeout.register_state_change_observer ### Description Registers a block to be notified about state changes during a request's lifetime. The observer is triggered every time the state changes, including the 'active' state which is updated approximately every second. ### Signature `Rack::Timeout.register_state_change_observer(name) { |env| ... }` ### Parameters - **name** (Symbol/String) - Required - A unique identifier for the observer. - **block** (Proc) - Required - The code to execute, receiving the `env` object. ``` -------------------------------- ### Set a custom logger Source: https://github.com/zombocom/rack-timeout/blob/main/doc/logging.md Assign a custom logger instance to Rack::Timeout. This overrides automatic logger detection. ```ruby Rack::Timeout::Logger.logger = Logger.new ``` -------------------------------- ### Disable logging Source: https://github.com/zombocom/rack-timeout/blob/main/doc/logging.md Disable the default logging behavior. ```ruby Rack::Timeout::Logger.disable ``` -------------------------------- ### Rack::Timeout.unregister_state_change_observer Source: https://github.com/zombocom/rack-timeout/blob/main/doc/observers.md Removes a previously registered observer by its unique name. ```APIDOC ## Rack::Timeout.unregister_state_change_observer ### Description Removes an observer that was previously registered using the specified name. ### Signature `Rack::Timeout.unregister_state_change_observer(name)` ### Parameters - **name** (Symbol/String) - Required - The unique identifier used when the observer was registered. ``` -------------------------------- ### Unregister a state change observer Source: https://github.com/zombocom/rack-timeout/blob/main/doc/observers.md Removes a previously registered observer using its unique name. ```ruby Rack::Timeout.unregister_state_change_observer(:a_unique_name) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.