Skip to content

Records applications' exceptions into the separated redis database

License

Notifications You must be signed in to change notification settings

kolobock/global_error_handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GlobalErrorHandler

GlobalErrorHandler catches application exceptions on the middleware level and store them into the redis database. It adds Exceptions tab to Redis Web server in case to view, filter, delete or truncate them.

Installation

Add this line to your application's Gemfile:

gem 'global_error_handler', '~> 1.2.3'

And then execute:

$ bundle

Or install it yourself as:

$ gem install global_error_handler

Configuration

Add redis database configuration into global_exceptions_handler section of redis.yml. See redis_example.yml for more details.

Usage

Exceptions tab

Index page

Target your browser to /resque/exceptions/ path of your Rails Application server to view all Exceptions.

Filters

There are two types of filtering: by Error Class and Error Message. Select any Error Class Filter or Error Message Filter from drop-down to view filtered exceptions.

Show

Click on Timestamp or Error Class hyperlink to view details of the exception.

Truncate/Delete functionality

Truncate

Truncate all deletes all Exceptions by filter if filter is selected or ALL Exceptions otherwise.

Delete

  • Delete deletes exception from the database.
  • Delete selected deletes the selected exceptions from the database. Clicking on the table caption checkbox selects/deselects the list.

rescue_from

If rescue_from is used in your application, add following line at top of the method specified to with: parameter of resque_from helper.

GlobalErrorHandler::Handler.new(request.env, exception).process_exception!

Subscribe to Redis notifications

rake tasks

Following command should run on your server in case to automatically clear filters on deleting keys from redis due to expiration. Default expiration time is set to 4 weeks (GlobalErrorHandler::Redis::REDIS_TTL)

rake global_error_handler:subscribe_to_expired

In case to stop subscription, run following below command

rake global_error_handler:unsubscribe_from_expired

capistrano tasks

There are Capistrano recipes that run desired rake tasks on the remote server

  • global_error_handler:subscribe
  • global_error_handler:unsubscribe
  • global_error_handler:update_subscription

In case to subscribe automatically after being deployed, add following require into deploy.rb

require 'global_error_handler/capistrano_recipes'
after 'deploy:restart', 'global_error_handler:update_subscription'

init.d script

Subscribe to expiration keys should run on system start-up as well after you system has been restarted so there is an init.d script to do it. Note that script is for RedHat/CentOS systems only (chkconfig-dependent)!

To generate init.d script run following:

cap <RAILS_ENV> global_error_handler:initd:setup

To install init.d script run following:

cap <RAILS_ENV> global_error_handler:initd:install

To uninstall init.d script run following:

cap <RAILS_ENV> global_error_handler:initd:uninstall

Data structure

Redis database data structure contains following below keys:

  • 'global_error_handler:current_id' : STRING - stores current id of an exception. It is being incremented on adding new exception into database
  • 'global_error_handler:exceptions' : LIST - stores all the exception' keys.
  • 'global_error_handler:exception:<id>' : HASH - exception key, where <id>: number from current_id + 1. Exception key consists of the following attributes:
    • id - exception's internal id
    • error_class - error.class
    • error_message - error.message
    • error_trace - error.backtrace
    • user_agent - request.user_agent
    • request_method - request.method
    • request_params - request.params
    • target_url - request.url
    • referer_url - request.referer
    • user_info - IP Address information
    • timestamp - time when exception was raised
  • 'global_error_handler:filter:<field>:<filter>' : LIST - stores exception' keys that are filtered by field and filter. where <field>: either error_class or error_message, <filter>: string stored in the appropriated attribute.

Database consistency

To check the database consistency, there is a rake task that will check for filters without the keys assigned with.

rake global_error_handler:cleanup_database_dependencies

Contributing

  1. Fork it ( https://github.com/kolobock/global_error_handler/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Records applications' exceptions into the separated redis database

Resources

License

Stars

Watchers

Forks

Packages

No packages published