Class: Airbrake::Configuration
- Inherits:
-
Object
- Object
- Airbrake::Configuration
- Defined in:
- lib/airbrake/configuration.rb
Overview
Used to set up and modify settings for the notifier.
Constant Summary collapse
- OPTIONS =
[:api_key, :backtrace_filters, :development_environments, :development_lookup, :environment_name, :host, :http_open_timeout, :http_read_timeout, :ignore, :ignore_by_filters, :ignore_user_agent, :notifier_name, :notifier_url, :notifier_version, :params_filters, :params_whitelist_filters, :project_root, :port, :protocol, :proxy_host, :proxy_pass, :proxy_port, :proxy_user, :secure, :use_system_ssl_cert_chain, :framework, :user_information, :rescue_rake_exceptions, :rake_environment_filters, :test_mode].freeze
- DEFAULT_PARAMS_FILTERS =
%w(password password_confirmation).freeze
- DEFAULT_PARAMS_WHITELIST_FILTERS =
[].freeze
- DEFAULT_USER_ATTRIBUTES =
%w(id).freeze
- VALID_USER_ATTRIBUTES =
%w(id name username email).freeze
- DEFAULT_BACKTRACE_FILTERS =
[ lambda { |line| if defined?(Airbrake.configuration.project_root) && Airbrake.configuration.project_root.to_s != '' line.sub(/#{Airbrake.configuration.project_root}/, "[PROJECT_ROOT]") else line end }, lambda { |line| line.gsub(/^\.\//, "") }, lambda { |line| Gem.path.each{ |path| line.sub!(/#{path}/, "[GEM_ROOT]") unless path.to_s.strip.empty? } if defined?(Gem) line }, lambda { |line| line if line !~ %r{lib/airbrake} } ].freeze
- IGNORE_DEFAULT =
['ActiveRecord::RecordNotFound', 'ActionController::RoutingError', 'ActionController::InvalidAuthenticityToken', 'CGI::Session::CookieStore::TamperedWithCookie', 'ActionController::UnknownHttpMethod', 'ActionController::UnknownAction', 'AbstractController::ActionNotFound', 'Mongoid::Errors::DocumentNotFound', 'ActionController::UnknownFormat']
Instance Attribute Summary collapse
-
#api_key ⇒ Object
The API key for your project, found on the project edit form.
-
#backtrace_filters ⇒ Object
readonly
A list of filters for cleaning and pruning the backtrace.
-
#development_environments ⇒ Object
A list of environments in which notifications should not be sent.
-
#development_lookup ⇒ Object
true
if you want to check for production errors matching development errors,false
otherwise. -
#environment_name ⇒ Object
The name of the environment the application is running in.
-
#framework ⇒ Object
The framework Airbrake is configured to use.
-
#host ⇒ Object
The host to connect to (defaults to airbrake.io).
-
#http_open_timeout ⇒ Object
The HTTP open timeout in seconds (defaults to 2).
-
#http_read_timeout ⇒ Object
The HTTP read timeout in seconds (defaults to 5).
-
#ignore ⇒ Object
readonly
A list of exception classes to ignore during server requests.
-
#ignore_by_filters ⇒ Object
readonly
A list of filters for ignoring exceptions.
-
#ignore_rake ⇒ Object
readonly
A list of exception classes to ignore during Rake tasks.
-
#ignore_user_agent ⇒ Object
readonly
A list of user agents that are being ignored.
-
#logger ⇒ Object
The logger used by Airbrake.
-
#notifier_name ⇒ Object
The name of the notifier library being used to send notifications (such as “Airbrake Notifier”).
-
#notifier_url ⇒ Object
The url of the notifier library being used to send notifications.
-
#notifier_version ⇒ Object
The version of the notifier library being used to send notifications (such as “1.0.2”).
-
#params_filters ⇒ Object
A list of parameters that should be filtered out of what is sent to Airbrake.
-
#params_whitelist_filters ⇒ Object
A list of whitelisted parameters that will be sent to Airbrake.
- #port ⇒ Object
-
#project_id ⇒ Object
Only used for JSON API.
-
#project_root ⇒ Object
The path to the project in which the error occurred, such as the Rails.root.
-
#proxy_host ⇒ Object
The hostname of your proxy server (if using a proxy).
-
#proxy_pass ⇒ Object
The password to use when logging into your proxy server (if using a proxy).
-
#proxy_port ⇒ Object
The port of your proxy server (if using a proxy).
-
#proxy_user ⇒ Object
The username to use when logging into your proxy server (if using a proxy).
-
#rake_environment_filters ⇒ Object
readonly
A list of environment keys that will be ignored from what is sent to Airbrake server Empty by default and used only in rake handler.
-
#rescue_rake_exceptions ⇒ Object
(also: #rescue_rake_exceptions?)
Should Airbrake catch exceptions from Rake tasks? (boolean or nil; set to nil to catch exceptions when rake isn’t running from a terminal; default is nil).
-
#secure ⇒ Object
(also: #secure?)
true
for https connections,false
for http connections. -
#test_mode ⇒ Object
(also: #test_mode?)
Setting this to true will use the CollectingSender instead of the default one which will cause storing the last notice locally.
-
#use_system_ssl_cert_chain ⇒ Object
(also: #use_system_ssl_cert_chain?)
true
to use whatever CAs OpenSSL has installed on your system. -
#user_attributes ⇒ Object
User attributes that are being captured.
-
#user_information ⇒ Object
The text that the placeholder is replaced with.
Instance Method Summary collapse
-
#[](option) ⇒ Object
Allows config options to be read like a hash.
-
#async(&block) ⇒ Object
(also: #async?)
Should Airbrake send notifications asynchronously (boolean, nil or callable; default is nil).
- #async=(use_default_or_this) ⇒ Object
- #ca_bundle_path ⇒ Object
-
#configured? ⇒ Boolean
Determines if the notifier will send notices.
-
#filter_backtrace(&block) {|line| ... } ⇒ Object
Takes a block and adds it to the list of backtrace filters.
-
#ignore_by_filter(&block) {|data| ... } ⇒ Object
Takes a block and adds it to the list of ignore filters.
-
#ignore_only=(names) ⇒ Object
Overrides the list of default ignored errors.
-
#ignore_rake_only=(names) ⇒ Object
Overrides the list of default ignored errors during Rake tasks.
-
#ignore_user_agent_only=(names) ⇒ Object
Overrides the list of default ignored user agents.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #local_cert_path ⇒ Object
-
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with
hash
. -
#protocol ⇒ String
Determines whether protocol should be “http” or “https”.
-
#public? ⇒ Boolean
Determines if the notifier will send notices.
-
#to_hash ⇒ Object
Returns a hash of all configurable options.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/airbrake/configuration.rb', line 158 def initialize @secure = false @use_system_ssl_cert_chain= false @host = 'api.airbrake.io' @port = nil @http_open_timeout = 2 @http_read_timeout = 5 @params_filters = DEFAULT_PARAMS_FILTERS.dup @params_whitelist_filters = DEFAULT_PARAMS_WHITELIST_FILTERS.dup @backtrace_filters = DEFAULT_BACKTRACE_FILTERS.dup @ignore_by_filters = [] # These filters are applied to both server requests and Rake tasks @ignore = IGNORE_DEFAULT.dup @ignore_rake = [] # Rake tasks don't ignore any exception classes by default @ignore_user_agent = [] @development_environments = %w(development test cucumber) @development_lookup = true @notifier_name = 'Airbrake Notifier' @notifier_version = VERSION @notifier_url = 'https://github.com/airbrake/airbrake' @framework = 'Standalone' @user_information = 'Airbrake Error {{error_id}}' @rescue_rake_exceptions = nil @user_attributes = DEFAULT_USER_ATTRIBUTES.dup @rake_environment_filters = [] @async = nil end |
Instance Attribute Details
#api_key ⇒ Object
The API key for your project, found on the project edit form.
15 16 17 |
# File 'lib/airbrake/configuration.rb', line 15 def api_key @api_key end |
#backtrace_filters ⇒ Object (readonly)
A list of filters for cleaning and pruning the backtrace. See #filter_backtrace.
58 59 60 |
# File 'lib/airbrake/configuration.rb', line 58 def backtrace_filters @backtrace_filters end |
#development_environments ⇒ Object
A list of environments in which notifications should not be sent.
77 78 79 |
# File 'lib/airbrake/configuration.rb', line 77 def development_environments @development_environments end |
#development_lookup ⇒ Object
true
if you want to check for production errors matching development errors, false
otherwise.
80 81 82 |
# File 'lib/airbrake/configuration.rb', line 80 def development_lookup @development_lookup end |
#environment_name ⇒ Object
The name of the environment the application is running in
83 84 85 |
# File 'lib/airbrake/configuration.rb', line 83 def environment_name @environment_name end |
#framework ⇒ Object
The framework Airbrake is configured to use
104 105 106 |
# File 'lib/airbrake/configuration.rb', line 104 def framework @framework end |
#host ⇒ Object
The host to connect to (defaults to airbrake.io).
18 19 20 |
# File 'lib/airbrake/configuration.rb', line 18 def host @host end |
#http_open_timeout ⇒ Object
The HTTP open timeout in seconds (defaults to 2).
31 32 33 |
# File 'lib/airbrake/configuration.rb', line 31 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Object
The HTTP read timeout in seconds (defaults to 5).
34 35 36 |
# File 'lib/airbrake/configuration.rb', line 34 def http_read_timeout @http_read_timeout end |
#ignore ⇒ Object (readonly)
A list of exception classes to ignore during server requests. The array can be appended to.
68 69 70 |
# File 'lib/airbrake/configuration.rb', line 68 def ignore @ignore end |
#ignore_by_filters ⇒ Object (readonly)
A list of filters for ignoring exceptions. See #ignore_by_filter.
61 62 63 |
# File 'lib/airbrake/configuration.rb', line 61 def ignore_by_filters @ignore_by_filters end |
#ignore_rake ⇒ Object (readonly)
A list of exception classes to ignore during Rake tasks. The array can be appended to.
71 72 73 |
# File 'lib/airbrake/configuration.rb', line 71 def ignore_rake @ignore_rake end |
#ignore_user_agent ⇒ Object (readonly)
A list of user agents that are being ignored. The array can be appended to.
74 75 76 |
# File 'lib/airbrake/configuration.rb', line 74 def ignore_user_agent @ignore_user_agent end |
#logger ⇒ Object
The logger used by Airbrake
98 99 100 |
# File 'lib/airbrake/configuration.rb', line 98 def logger @logger end |
#notifier_name ⇒ Object
The name of the notifier library being used to send notifications (such as “Airbrake Notifier”)
89 90 91 |
# File 'lib/airbrake/configuration.rb', line 89 def notifier_name @notifier_name end |
#notifier_url ⇒ Object
The url of the notifier library being used to send notifications
95 96 97 |
# File 'lib/airbrake/configuration.rb', line 95 def notifier_url @notifier_url end |
#notifier_version ⇒ Object
The version of the notifier library being used to send notifications (such as “1.0.2”)
92 93 94 |
# File 'lib/airbrake/configuration.rb', line 92 def notifier_version @notifier_version end |
#params_filters ⇒ Object
A list of parameters that should be filtered out of what is sent to Airbrake. By default, all “password” attributes will have their contents replaced.
50 51 52 |
# File 'lib/airbrake/configuration.rb', line 50 def params_filters @params_filters end |
#params_whitelist_filters ⇒ Object
A list of whitelisted parameters that will be sent to Airbrake. All other parameters will be filtered and their content replaced. By default this list is empty (all parameters are whitelisted).
55 56 57 |
# File 'lib/airbrake/configuration.rb', line 55 def params_whitelist_filters @params_whitelist_filters end |
#port ⇒ Object
269 270 271 |
# File 'lib/airbrake/configuration.rb', line 269 def port @port || default_port end |
#project_id ⇒ Object
Only used for JSON API
115 116 117 |
# File 'lib/airbrake/configuration.rb', line 115 def project_id @project_id end |
#project_root ⇒ Object
The path to the project in which the error occurred, such as the Rails.root
86 87 88 |
# File 'lib/airbrake/configuration.rb', line 86 def project_root @project_root end |
#proxy_host ⇒ Object
The hostname of your proxy server (if using a proxy)
37 38 39 |
# File 'lib/airbrake/configuration.rb', line 37 def proxy_host @proxy_host end |
#proxy_pass ⇒ Object
The password to use when logging into your proxy server (if using a proxy)
46 47 48 |
# File 'lib/airbrake/configuration.rb', line 46 def proxy_pass @proxy_pass end |
#proxy_port ⇒ Object
The port of your proxy server (if using a proxy)
40 41 42 |
# File 'lib/airbrake/configuration.rb', line 40 def proxy_port @proxy_port end |
#proxy_user ⇒ Object
The username to use when logging into your proxy server (if using a proxy)
43 44 45 |
# File 'lib/airbrake/configuration.rb', line 43 def proxy_user @proxy_user end |
#rake_environment_filters ⇒ Object (readonly)
A list of environment keys that will be ignored from what is sent to Airbrake server Empty by default and used only in rake handler
65 66 67 |
# File 'lib/airbrake/configuration.rb', line 65 def rake_environment_filters @rake_environment_filters end |
#rescue_rake_exceptions ⇒ Object Also known as: rescue_rake_exceptions?
Should Airbrake catch exceptions from Rake tasks? (boolean or nil; set to nil to catch exceptions when rake isn’t running from a terminal; default is nil)
108 109 110 |
# File 'lib/airbrake/configuration.rb', line 108 def rescue_rake_exceptions @rescue_rake_exceptions end |
#secure ⇒ Object Also known as: secure?
true
for https connections, false
for http connections.
25 26 27 |
# File 'lib/airbrake/configuration.rb', line 25 def secure @secure end |
#test_mode ⇒ Object Also known as: test_mode?
Setting this to true will use the CollectingSender instead of the default one which will cause storing the last notice locally
119 120 121 |
# File 'lib/airbrake/configuration.rb', line 119 def test_mode @test_mode end |
#use_system_ssl_cert_chain ⇒ Object Also known as: use_system_ssl_cert_chain?
true
to use whatever CAs OpenSSL has installed on your system. false
to use the ca-bundle.crt file included in Airbrake itself (reccomended and default)
28 29 30 |
# File 'lib/airbrake/configuration.rb', line 28 def use_system_ssl_cert_chain @use_system_ssl_cert_chain end |
#user_attributes ⇒ Object
User attributes that are being captured
112 113 114 |
# File 'lib/airbrake/configuration.rb', line 112 def user_attributes @user_attributes end |
#user_information ⇒ Object
The text that the placeholder is replaced with. {error_id} is the actual error number.
101 102 103 |
# File 'lib/airbrake/configuration.rb', line 101 def user_information @user_information end |
Instance Method Details
#[](option) ⇒ Object
Allows config options to be read like a hash
238 239 240 |
# File 'lib/airbrake/configuration.rb', line 238 def [](option) send(option) end |
#async(&block) ⇒ Object Also known as: async?
Should Airbrake send notifications asynchronously (boolean, nil or callable; default is nil). Can be used as callable-setter when block provided.
291 292 293 294 295 296 |
# File 'lib/airbrake/configuration.rb', line 291 def async(&block) if block_given? @async = block end @async end |
#async=(use_default_or_this) ⇒ Object
299 300 301 302 303 |
# File 'lib/airbrake/configuration.rb', line 299 def async=(use_default_or_this) @async = use_default_or_this == true ? default_async_processor : use_default_or_this end |
#ca_bundle_path ⇒ Object
312 313 314 315 316 317 318 |
# File 'lib/airbrake/configuration.rb', line 312 def ca_bundle_path if use_system_ssl_cert_chain? && File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE) OpenSSL::X509::DEFAULT_CERT_FILE else local_cert_path # ca-bundle.crt built from source, see resources/README.md end end |
#configured? ⇒ Boolean
Determines if the notifier will send notices.
259 260 261 |
# File 'lib/airbrake/configuration.rb', line 259 def configured? !api_key.nil? && !api_key.empty? end |
#filter_backtrace(&block) {|line| ... } ⇒ 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.
196 197 198 |
# File 'lib/airbrake/configuration.rb', line 196 def filter_backtrace(&block) self.backtrace_filters << block end |
#ignore_by_filter(&block) {|data| ... } ⇒ Object
Takes a block and adds it to the list of ignore filters. When the filters run, the block will be handed the exception.
210 211 212 |
# File 'lib/airbrake/configuration.rb', line 210 def ignore_by_filter(&block) self.ignore_by_filters << block end |
#ignore_only=(names) ⇒ Object
Overrides the list of default ignored errors.
217 218 219 |
# File 'lib/airbrake/configuration.rb', line 217 def ignore_only=(names) @ignore = [names].flatten end |
#ignore_rake_only=(names) ⇒ Object
Overrides the list of default ignored errors during Rake tasks.
224 225 226 |
# File 'lib/airbrake/configuration.rb', line 224 def ignore_rake_only=(names) @ignore_rake = [names].flatten end |
#ignore_user_agent_only=(names) ⇒ Object
Overrides the list of default ignored user agents
231 232 233 |
# File 'lib/airbrake/configuration.rb', line 231 def ignore_user_agent_only=(names) @ignore_user_agent = [names].flatten end |
#local_cert_path ⇒ Object
320 321 322 |
# File 'lib/airbrake/configuration.rb', line 320 def local_cert_path File.(File.join("..", "..", "..", "resources", "ca-bundle.crt"), __FILE__) end |
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with hash
253 254 255 |
# File 'lib/airbrake/configuration.rb', line 253 def merge(hash) to_hash.merge(hash) end |
#protocol ⇒ String
Determines whether protocol should be “http” or “https”. configuration, and “https” otherwise.
276 277 278 279 280 281 282 |
# File 'lib/airbrake/configuration.rb', line 276 def protocol if secure? 'https' else 'http' end end |
#public? ⇒ Boolean
Determines if the notifier will send notices.
265 266 267 |
# File 'lib/airbrake/configuration.rb', line 265 def public? @public ||= !development_environments.include?(environment_name) end |
#to_hash ⇒ Object
Returns a hash of all configurable options
243 244 245 246 247 248 |
# File 'lib/airbrake/configuration.rb', line 243 def to_hash OPTIONS.inject({}) do |hash, option| hash[option.to_sym] = self.send(option) hash end end |