class Airbrake::Configuration
Used to set up and modify settings for the notifier.
Constants
- DEFAULT_BACKTRACE_FILTERS
- DEFAULT_PARAMS_FILTERS
- DEFAULT_PARAMS_WHITELIST_FILTERS
- DEFAULT_USER_ATTRIBUTES
- IGNORE_DEFAULT
- OPTIONS
- VALID_USER_ATTRIBUTES
Attributes
The API key for your project, found on the project edit form.
A list of filters for cleaning and pruning the backtrace. See filter_backtrace
.
A list of environments in which notifications should not be sent.
true
if you want to check for production errors matching development errors, false
otherwise.
The name of the environment the application is running in
The framework Airbrake
is configured to use
The host to connect to (defaults to airbrake.io).
The HTTP open timeout in seconds (defaults to 2).
The HTTP read timeout in seconds (defaults to 5).
A list of exception classes to ignore during server requests. The array can be appended to.
A list of filters for ignoring exceptions. See ignore_by_filter
.
A list of exception classes to ignore during Rake tasks. The array can be appended to.
A list of user agents that are being ignored. The array can be appended to.
The logger used by Airbrake
The name of the notifier library being used to send notifications (such as “Airbrake Notifier”)
The url of the notifier library being used to send notifications
The version of the notifier library being used to send notifications (such as “1.0.2”)
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.
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).
The port on which your Airbrake
server runs (defaults to 443 for secure connections, 80 for insecure connections).
Only used for JSON API
The path to the project in which the error occurred, such as the Rails.root
The hostname of your proxy server (if using a proxy)
The password to use when logging into your proxy server (if using a proxy)
The port of your proxy server (if using a proxy)
The username to use when logging into your proxy server (if using a proxy)
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
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)
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)
true
for https connections, false
for http connections.
true
for https connections, false
for http connections.
Setting this to true will use the CollectingSender
instead of the default one which will cause storing the last notice locally
Setting this to true will use the CollectingSender
instead of the default one which will cause storing the last notice locally
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)
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)
User attributes that are being captured
The text that the placeholder is replaced with. {{error_id}} is the actual error number.
Public Class Methods
# 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
Public Instance Methods
Allows config options to be read like a hash
@param [Symbol] option Key for a given attribute
# File lib/airbrake/configuration.rb, line 238 def [](option) send(option) end
Should Airbrake
send notifications asynchronously (boolean, nil or callable; default is nil). Can be used as callable-setter when block provided.
# File lib/airbrake/configuration.rb, line 291 def async(&block) if block_given? @async = block end @async end
# 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
# File lib/airbrake/configuration.rb, line 312 def ca_bundle_path if use_system_ssl_cert_chain? OpenSSL::X509::DEFAULT_CERT_FILE if File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE) else local_cert_path # ca-bundle.crt built from source, see resources/README.md end end
Determines if the notifier will send notices. @return [Boolean] Returns true
if an api string exists, false
otherwise.
# File lib/airbrake/configuration.rb, line 259 def configured? !api_key.nil? && !api_key.empty? end
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.
@example
config.filter_bracktrace do |line| line.gsub(/^#{Rails.root}/, "[Rails.root]") end
@param [Proc] block The new backtrace filter. @yieldparam [String] line A line in the backtrace.
# File lib/airbrake/configuration.rb, line 196 def filter_backtrace(&block) self.backtrace_filters << block end
Takes a block and adds it to the list of ignore filters. When the filters run, the block will be handed the exception. @example
config.ignore_by_filter do |exception_data| true if exception_data[:error_class] == "RuntimeError" end
@param [Proc] block The new ignore filter @yieldparam [Hash] data The exception data given to Airbrake.notify
@yieldreturn [Boolean] If the block returns true the exception will be ignored, otherwise it will be processed by airbrake.
# File lib/airbrake/configuration.rb, line 210 def ignore_by_filter(&block) self.ignore_by_filters << block end
Overrides the list of default ignored errors.
@param [Array<Exception>] names A list of exceptions to ignore.
# File lib/airbrake/configuration.rb, line 217 def ignore_only=(names) @ignore = [names].flatten end
Overrides the list of default ignored errors during Rake tasks.
@param [Array<Exception>] names A list of rake exceptions to ignore.
# File lib/airbrake/configuration.rb, line 224 def ignore_rake_only=(names) @ignore_rake = [names].flatten end
Overrides the list of default ignored user agents
@param [Array<String>] A list of user agents to ignore
# File lib/airbrake/configuration.rb, line 231 def ignore_user_agent_only=(names) @ignore_user_agent = [names].flatten end
# File lib/airbrake/configuration.rb, line 320 def local_cert_path File.expand_path(File.join("..", "..", "..", "resources", "ca-bundle.crt"), __FILE__) end
Returns a hash of all configurable options merged with hash
@param [Hash] hash A set of configuration options that will take precedence over the defaults
# File lib/airbrake/configuration.rb, line 253 def merge(hash) to_hash.merge(hash) end
# File lib/airbrake/configuration.rb, line 269 def port @port || default_port end
# File lib/airbrake/configuration.rb, line 324 def project_id=(project_id) @project_id = "#{project_id}" end
Determines whether protocol should be “http” or “https”. @return [String] Returns +“http”+ if you’ve set secure to false
in configuration, and +“https”+ otherwise.
# File lib/airbrake/configuration.rb, line 276 def protocol if secure? 'https' else 'http' end end
Determines if the notifier will send notices. @return [Boolean] Returns false
if in a development environment, true
otherwise.
# File lib/airbrake/configuration.rb, line 265 def public? @public ||= !development_environments.include?(environment_name) end
# File lib/airbrake/configuration.rb, line 305 def rescue_rake_exceptions=(val) if val && !defined?(Airbrake::RakeHandler) raise LoadError, "you must require 'airbrake/rake_handler' to rescue from rake exceptions" end @rescue_rake_exceptions = val end
Returns a hash of all configurable options
# 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
# File lib/airbrake/configuration.rb, line 284 def user_attributes=(user_attributes) @user_attributes = validate_user_attributes user_attributes end
Private Instance Methods
Async notice delivery defaults to girl friday
# File lib/airbrake/configuration.rb, line 341 def default_async_processor if defined?(SuckerPunch) lambda {|notice| SendJob.new.async.perform(notice)} elsif defined?(GirlFriday) queue = GirlFriday::WorkQueue.new(nil, :size => 3) do |notice| Airbrake.sender.send_to_airbrake(notice) end lambda {|notice| queue << notice} else warn "[AIRBRAKE] You can't use the default async handler without sucker_punch or girl_friday."\ " Please make sure you have sucker_punch or girl_friday installed (sucker_punch is recommended)." end end
Determines what port should we use for sending notices. @return [Fixnum] Returns 443 if you’ve set secure to true in your configuration, and 80 otherwise.
# File lib/airbrake/configuration.rb, line 332 def default_port if secure? 443 else 80 end end
# File lib/airbrake/configuration.rb, line 355 def validate_user_attributes(user_attributes) user_attributes.reject do |attribute| unless VALID_USER_ATTRIBUTES.include? attribute.to_s warn "[AIRBRAKE] Unsupported user attribute: '#{attribute}'. "\ "This attribute will not be shown in the Airbrake UI. "\ "Check http://git.io/h6YRpA for more info." true end end end