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

Constants

HOST_DEPRECATION_MSG

Attributes

instance[W]

@return [Config]

allowlist_keys[RW]

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

filtered

@api public @since v4.15.0

apm_host[RW]

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

APM data should be sent

@api public @since v5.0.0

app_version[RW]

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

backlog[RW]

@return [Boolean] true if the library should keep a backlog of failed

notices or APM events and retry them after an interval, false otherwise

@api public @since v6.2.0

blocklist_keys[RW]

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

filtered

@api public @since v4.15.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

error_host[RW]

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

exceptions should be sent

@api public @since v5.0.0

error_notifications[RW]

@return [Boolean] true if the library should send error reports to

Airbrake, false otherwise

@api public @since v5.0.0

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

remote_config[RW]

@return [String] true if notifier should periodically fetch remote

configuration, false otherwise

@api public @since v5.2.0

remote_config_host[RW]

@return [String] the host which should be used for fetching remote

configuration options

@api public @since v5.0.0

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

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 146
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

rubocop:disable Metrics/AbcSize, Metrics/MethodLength

# File lib/airbrake-ruby/config.rb, line 154
def initialize(user_config = {})
  self.proxy = {}
  self.queue_size = 100
  self.workers = 1
  self.code_hunks = true
  self.logger = ::Logger.new(File::NULL).tap { |l| l.level = Logger::WARN }
  self.project_id = user_config[:project_id]
  self.project_key = user_config[:project_key]
  self.error_host = self.apm_host = 'https://api.airbrake.io'
  self.remote_config_host = 'https://notifier-configs.airbrake.io'

  self.ignore_environments = []

  self.timeout = user_config[:timeout]

  self.blocklist_keys = []
  self.allowlist_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
  self.error_notifications = true
  self.remote_config = true
  self.backlog = 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 244
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 232
def check_notify_ability
  Validator.check_notify_ability(self)
end
check_performance_options(metric) 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 253
def check_performance_options(metric)
  promise = Airbrake::Promise.new

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

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

# File lib/airbrake-ruby/config.rb, line 192
def error_endpoint
  @error_endpoint ||=
    begin
      self.error_host = ('https://' << error_host) if error_host !~ %r{\Ahttps?://}
      api = "api/v3/projects/#{project_id}/notices"
      URI.join(error_host, api)
    end
end
host() click to toggle source
# File lib/airbrake-ruby/config.rb, line 270
def host
  logger.warn(HOST_DEPRECATION_MSG)
  @error_host
end
host=(value) click to toggle source
# File lib/airbrake-ruby/config.rb, line 275
def host=(value)
  logger.warn(HOST_DEPRECATION_MSG)
  @error_host = value
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 238
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 203
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 213
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 220
def valid?
  validate.resolved?
end
validate() click to toggle source

@return [Promise] @see Validator.validate

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

Private Instance Methods

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