Module: HoptoadNotifier
- Defined in:
- lib/hoptoad_notifier.rb
Overview
Plugin for applications to automatically post errors to the Hoptoad of their choice.
Defined Under Namespace
Modules: Catcher Classes: Sender
Constant Summary collapse
- IGNORE_DEFAULT =
['ActiveRecord::RecordNotFound', 'ActionController::RoutingError', 'ActionController::InvalidAuthenticityToken', 'CGI::Session::CookieStore::TamperedWithCookie', 'ActionController::UnknownAction']
- IGNORE_USER_AGENT_DEFAULT =
[]
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.application_path ⇒ Object
The file path of the application.
-
.current_environment ⇒ Object
Returns the value of attribute current_environment.
-
.host ⇒ Object
The host to connect to.
-
.http_open_timeout ⇒ Object
The HTTP open timeout (defaults to 2 seconds).
-
.http_read_timeout ⇒ Object
The HTTP read timeout (defaults to 5 seconds).
-
.port ⇒ Object
The port on which your Hoptoad server runs.
-
.proxy_host ⇒ Object
Returns the value of attribute proxy_host.
-
.proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
-
.proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
.proxy_user ⇒ Object
Returns the value of attribute proxy_user.
-
.public_environments ⇒ Object
An array of environments that are considered ‘public’ Default is: [‘production’, ‘staging’].
-
.secure ⇒ Object
Returns the value of attribute secure.
Class Method Summary collapse
- .add_default_filters ⇒ Object
- .backtrace_filters ⇒ Object
-
.configure {|_self| ... } ⇒ Object
Call this method to modify defaults in your initializers.
-
.default_notice_options ⇒ Object
:nodoc:.
- .environment_filters ⇒ Object
-
.filter_backtrace(&block) ⇒ Object
Takes a block and adds it to the list of backtrace filters.
-
.ignore ⇒ Object
Returns the list of errors that are being ignored.
-
.ignore_only=(names) ⇒ Object
Sets the list of ignored errors to only what is passed in here.
-
.ignore_user_agent ⇒ Object
Returns the list of user agents that are being ignored.
-
.ignore_user_agent_only=(names) ⇒ Object
Sets the list of ignored user agents to only what is passed in here.
-
.notify(notice = {}) ⇒ Object
You can send an exception manually using this method, even when you are not in a controller.
-
.params_filters ⇒ Object
Returns a list of parameters that should be filtered out of what is sent to Hoptoad.
-
.protocol ⇒ Object
:nodoc:.
-
.url ⇒ Object
:nodoc:.
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
22 23 24 |
# File 'lib/hoptoad_notifier.rb', line 22 def api_key @api_key end |
.application_path ⇒ Object
The file path of the application. If RAILS_ROOT is defined it will default to that, otherwise the default will be FileUtils.pwd.
50 51 52 |
# File 'lib/hoptoad_notifier.rb', line 50 def application_path @application_path end |
.current_environment ⇒ Object
Returns the value of attribute current_environment.
22 23 24 |
# File 'lib/hoptoad_notifier.rb', line 22 def current_environment @current_environment end |
.host ⇒ Object
The host to connect to.
44 45 46 |
# File 'lib/hoptoad_notifier.rb', line 44 def host @host end |
.http_open_timeout ⇒ Object
The HTTP open timeout (defaults to 2 seconds).
70 71 72 |
# File 'lib/hoptoad_notifier.rb', line 70 def http_open_timeout @http_open_timeout end |
.http_read_timeout ⇒ Object
The HTTP read timeout (defaults to 5 seconds).
75 76 77 |
# File 'lib/hoptoad_notifier.rb', line 75 def http_read_timeout @http_read_timeout end |
.port ⇒ Object
The port on which your Hoptoad server runs.
39 40 41 |
# File 'lib/hoptoad_notifier.rb', line 39 def port @port end |
.proxy_host ⇒ Object
Returns the value of attribute proxy_host.
22 23 24 |
# File 'lib/hoptoad_notifier.rb', line 22 def proxy_host @proxy_host end |
.proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
22 23 24 |
# File 'lib/hoptoad_notifier.rb', line 22 def proxy_pass @proxy_pass end |
.proxy_port ⇒ Object
Returns the value of attribute proxy_port.
22 23 24 |
# File 'lib/hoptoad_notifier.rb', line 22 def proxy_port @proxy_port end |
.proxy_user ⇒ Object
Returns the value of attribute proxy_user.
22 23 24 |
# File 'lib/hoptoad_notifier.rb', line 22 def proxy_user @proxy_user end |
.public_environments ⇒ Object
An array of environments that are considered ‘public’ Default is:
- ‘production’, ‘staging’
56 57 58 |
# File 'lib/hoptoad_notifier.rb', line 56 def public_environments @public_environments end |
.secure ⇒ Object
Returns the value of attribute secure.
22 23 24 |
# File 'lib/hoptoad_notifier.rb', line 22 def secure @secure end |
Class Method Details
.add_default_filters ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/hoptoad_notifier.rb', line 164 def add_default_filters self.backtrace_filters.clear filter_backtrace do |line| line.gsub(/#{application_path}/, "[RAILS_ROOT]") end filter_backtrace do |line| line.gsub(/^\.\//, "") end filter_backtrace do |line| if defined?(Gem) Gem.path.inject(line) do |line, path| line.gsub(/#{path}/, "[GEM_ROOT]") end end end filter_backtrace do |line| line if line !~ /lib\/#{File.basename(__FILE__)}/ end end |
.backtrace_filters ⇒ Object
26 27 28 |
# File 'lib/hoptoad_notifier.rb', line 26 def backtrace_filters @backtrace_filters ||= [] end |
.configure {|_self| ... } ⇒ Object
Call this method to modify defaults in your initializers.
HoptoadNotifier.configure do |config|
config.api_key = '1234567890abcdef'
config.secure = false
end
NOTE: secure connections are not yet supported.
123 124 125 126 127 128 129 |
# File 'lib/hoptoad_notifier.rb', line 123 def configure add_default_filters yield self if defined?(ActionController::Base) && !ActionController::Base.include?(HoptoadNotifier::Catcher) ActionController::Base.send(:include, HoptoadNotifier::Catcher) end end |
.default_notice_options ⇒ Object
:nodoc:
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/hoptoad_notifier.rb', line 139 def #:nodoc: { :api_key => HoptoadNotifier.api_key, :error_message => 'Notification', :backtrace => caller, :request => {}, :session => {}, :environment => ENV.to_hash } end |
.environment_filters ⇒ Object
111 112 113 |
# File 'lib/hoptoad_notifier.rb', line 111 def environment_filters @environment_filters ||= %w() end |
.filter_backtrace(&block) ⇒ Object
Takes a block and adds it to the list of backtrace filters. When the filters run, the block will be handed each line of the backtrace and can modify it as necessary. For example, by default a path matching the RAILS_ROOT constant will be transformed into “[RAILS_ROOT]”
34 35 36 |
# File 'lib/hoptoad_notifier.rb', line 34 def filter_backtrace &block self.backtrace_filters << block end |
.ignore ⇒ Object
Returns the list of errors that are being ignored. The array can be appended to.
80 81 82 83 84 |
# File 'lib/hoptoad_notifier.rb', line 80 def ignore @ignore ||= (HoptoadNotifier::IGNORE_DEFAULT.dup) @ignore.flatten! @ignore end |
.ignore_only=(names) ⇒ Object
Sets the list of ignored errors to only what is passed in here. This method can be passed a single error or a list of errors.
88 89 90 |
# File 'lib/hoptoad_notifier.rb', line 88 def ignore_only=(names) @ignore = [names].flatten end |
.ignore_user_agent ⇒ Object
Returns the list of user agents that are being ignored. The array can be appended to.
93 94 95 96 97 |
# File 'lib/hoptoad_notifier.rb', line 93 def ignore_user_agent @ignore_user_agent ||= (HoptoadNotifier::IGNORE_USER_AGENT_DEFAULT.dup) @ignore_user_agent.flatten! @ignore_user_agent end |
.ignore_user_agent_only=(names) ⇒ Object
Sets the list of ignored user agents to only what is passed in here. This method can be passed a single user agent or a list of user agents.
101 102 103 |
# File 'lib/hoptoad_notifier.rb', line 101 def ignore_user_agent_only=(names) @ignore_user_agent = [names].flatten end |
.notify(notice = {}) ⇒ Object
You can send an exception manually using this method, even when you are not in a controller. You can pass an exception or a hash that contains the attributes that would be sent to Hoptoad:
-
api_key: The API key for this project. The API key is a unique identifier that Hoptoad uses for identification.
-
error_message: The error returned by the exception (or the message you want to log).
-
backtrace: A backtrace, usually obtained with
caller. -
request: The controller’s request object.
-
session: The contents of the user’s session.
-
environment: ENV merged with the contents of the request’s environment.
160 161 162 |
# File 'lib/hoptoad_notifier.rb', line 160 def notify notice = {} Sender.new.notify_hoptoad( notice ) end |
.params_filters ⇒ Object
Returns a list of parameters that should be filtered out of what is sent to Hoptoad. By default, all “password” attributes will have their contents replaced.
107 108 109 |
# File 'lib/hoptoad_notifier.rb', line 107 def params_filters @params_filters ||= %w(password) end |
.protocol ⇒ Object
:nodoc:
131 132 133 |
# File 'lib/hoptoad_notifier.rb', line 131 def protocol #:nodoc: secure ? "https" : "http" end |
.url ⇒ Object
:nodoc:
135 136 137 |
# File 'lib/hoptoad_notifier.rb', line 135 def url #:nodoc: URI.parse("#{protocol}://#{host}:#{port}/notices/") end |