Rnotifier
Events and Exception catcher libraray.
Installation
Add this line to your application's Gemfile:
gem 'rnotifier'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rnotifier
Usage
rnotifier install 'API-KEY' # This will create 'config/rnotifier.yaml' file.
Config file options
environments: development,test #default is production
capture_code: true #default false
ignore_exceptions: ActiveRecord::RecordNotFound,AbstractController::ActionNotFound,ActionController::RoutingError
ignore_bots: Googlebot
To test config
rnotifier test #this will send test exception to rnotifier.
Send exception with request manually
For this ':request' params require
Rnotifier.exception(exception, {:request => request, other_params => 'value'})
Add context data to exception
Rnotifier.context({user_email: current_user.email})
Send events and alerts
Rnotifier.event(:sign_up, {:username => 'Jiren', :email => 'jiren@example.com', :using => 'facebook' })
Rnotifier.alert(:order_fail, {:user => 'Jiren', :product => 'PS3', :order_id => '321' })
You can also sends tags with 'event' and 'alert' i.e
Rnotifier.event(
:sign_up,
{:username => 'Jiren', :email => 'jiren@example.com', :using => 'facebook' },
{:tags => ['newsletter']}
)
Benchmarking
- Code block benchamrking
Rnotifier.benchmark('sum') do
(1..100).inject(0){|i, result| result = result + i; result }
end
-
Method benchmarking
- For Instance object method
Paragraph.new.benchmark({args: true}).word_count(text)
- For class method
Paragraph.benchmark({args: true}).word_count(text)
- Using helper function
class Aggregator
def error_count(options = {})
# Code ...
end
# for instance method
benchmark_it :error_count, :time_condition => 0.5
def self.errors_by_date_range(start_date, end_date)
# Code ...
end
# For class method
benchmark_it :errors_by_date_range, :class_method => true
end
Options: time_condition and class_method
- For class method pass option ':class_method => true'
- Rails action In controller add following filter.
rnotifier_benchmarking #
Above will capture benchamrk for all controller action.
For particular action
rnotifier_benchmarking only: [:index, :show]
# or
rnotifier_benchmarking except: [:destroy]
With time condition
rnotifier_benchmarking only: [:index, :show], time_condition: 0.8
To capture page load benchmarking on client side add following tag to your view in the end of your view or in footer
rnotifier_tag
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
This is released under the MIT license.