class Airbrake::Config

Represents the Airbrake config. A config contains all the options that you can use to configure an Airbrake instance.

@api public @since v1.0.0

Attributes

instance[W]

@return [Config]

app_version[RW]

@return [String] the version of the user's application @api public

blacklist_keys[RW]

@return [Array<String, Symbol, Regexp>] the keys, which should be

filtered

@api public @since v1.2.0

code_hunks[RW]

@return [Boolean] true if the library should attach code hunks to each

frame in a backtrace, false otherwise

@api public @since v2.5.0

environment[RW]

@return [String, Symbol] the environment the application is running in @api public

host[RW]

@return [String] the host, which provides the API endpoint to which

exceptions should be sent

@api public

ignore_environments[RW]

@return [Array<String,Symbol,Regexp>] the array of environments that

forbids sending exceptions when the application is running in them.
Other possible environments not listed in the array will allow sending
occurring exceptions.

@api public

job_stats[RW]

@return [Boolean] true if the library should send job/queue/worker stats

to Airbrake, false otherwise

@api public @since v4.12.0

logger[R]

@return [Logger] the default logger used for debug output @api public

performance_stats[RW]

@return [Boolean] true if the library should send route performance stats

to Airbrake, false otherwise

@api public @since v3.2.0

performance_stats_flush_period[RW]

@return [Integer] how many seconds to wait before sending collected route

stats

@api private @since v3.2.0

project_id[RW]

@return [Integer] the project identificator. This value must be set. @api public

project_key[RW]

@return [String] the project key. This value must be set. @api public

proxy[RW]

@return [Hash] the proxy parameters such as (:host, :port, :user and

:password)

@api public

query_stats[RW]

@return [Boolean] true if the library should send SQL stats to Airbrake,

false otherwise

@api public @since v4.6.0

queue_size[RW]

@return [Integer] the max number of notices that can be queued up @api public

root_directory[RW]

@return [String, Pathname] the working directory of your project @api public

timeout[RW]

@return [Integer] The HTTP timeout in seconds. @api public

versions[RW]

@return [Hash{String=>String}] arbitrary versions that your app wants to

track

@api public @since v2.10.0

whitelist_keys[RW]

@return [Array<String, Symbol, Regexp>] the keys, which shouldn't be

filtered

@api public @since v1.2.0

workers[RW]

@return [Integer] the number of worker threads that process the notice

queue

@api public

Public Class Methods

instance() click to toggle source

@return [Config]

# File lib/airbrake-ruby/config.rb, line 115
def instance
  @instance ||= new
end
new(user_config = {}) click to toggle source

@param [Hash{Symbol=>Object}] user_config the hash to be used to build the

config
# File lib/airbrake-ruby/config.rb, line 122
def initialize(user_config = {})
  self.proxy = {}
  self.queue_size = 100
  self.workers = 1
  self.code_hunks = true
  self.logger = ::Logger.new(File::NULL)
  self.project_id = user_config[:project_id]
  self.project_key = user_config[:project_key]
  self.host = 'https://api.airbrake.io'

  self.ignore_environments = []

  self.timeout = user_config[:timeout]

  self.blacklist_keys = []
  self.whitelist_keys = []

  self.root_directory = File.realpath(
    (defined?(Bundler) && Bundler.root) ||
    Dir.pwd,
  )

  self.versions = {}
  self.performance_stats = true
  self.performance_stats_flush_period = 15
  self.query_stats = true
  self.job_stats = true

  merge(user_config)
end

Public Instance Methods

check_configuration() click to toggle source

@return [Promise] resolved promise if config is valid & can notify,

rejected otherwise
# File lib/airbrake-ruby/config.rb, line 207
def check_configuration
  promise = validate
  return promise if promise.rejected?

  check_notify_ability
end
check_notify_ability() click to toggle source

@return [Promise] @see Validator.check_notify_ability

# File lib/airbrake-ruby/config.rb, line 195
def check_notify_ability
  Validator.check_notify_ability(self)
end
check_performance_options(resource) click to toggle source

@return [Promise] resolved promise if neither of the performance options

reject it, false otherwise
# File lib/airbrake-ruby/config.rb, line 216
def check_performance_options(resource)
  promise = Airbrake::Promise.new

  if !performance_stats
    promise.reject("The Performance Stats feature is disabled")
  elsif resource.is_a?(Airbrake::Query) && !query_stats
    promise.reject("The Query Stats feature is disabled")
  elsif resource.is_a?(Airbrake::Queue) && !job_stats
    promise.reject("The Job Stats feature is disabled")
  else
    promise
  end
end
endpoint() click to toggle source

The full URL to the Airbrake Notice API. Based on the :host option. @return [URI] the endpoint address

# File lib/airbrake-ruby/config.rb, line 155
def endpoint
  @endpoint ||=
    begin
      self.host = ('https://' << host) if host !~ %r{\Ahttps?://}
      api = "api/v3/projects/#{project_id}/notices"
      URI.join(host, api)
    end
end
ignored_environment?() click to toggle source

@return [Boolean] true if the config ignores current environment, false

otherwise
# File lib/airbrake-ruby/config.rb, line 201
def ignored_environment?
  check_notify_ability.rejected?
end
logger=(logger) click to toggle source

Sets the logger. Never allows to assign `nil` as the logger. @return [Logger] the logger

# File lib/airbrake-ruby/config.rb, line 166
def logger=(logger)
  @logger = logger || @logger
end
merge(config_hash) click to toggle source

Merges the given config_hash with itself.

@example

config.merge(host: 'localhost:8080')

@return [self] the merged config

# File lib/airbrake-ruby/config.rb, line 176
def merge(config_hash)
  config_hash.each_pair { |option, value| set_option(option, value) }
  self
end
valid?() click to toggle source

@return [Boolean] true if the config meets the requirements, false

otherwise
# File lib/airbrake-ruby/config.rb, line 183
def valid?
  validate.resolved?
end
validate() click to toggle source

@return [Promise] @see Validator.validate

# File lib/airbrake-ruby/config.rb, line 189
def validate
  Validator.validate(self)
end

Private Instance Methods

set_option(option, value) click to toggle source
# File lib/airbrake-ruby/config.rb, line 232
def set_option(option, value)
  __send__("#{option}=", value)
rescue NoMethodError
  raise Airbrake::Error, "unknown option '#{option}'"
end