Class: Airbrake::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_keyObject

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_filtersObject (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_environmentsObject

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_lookupObject

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_nameObject

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

#frameworkObject

The framework Airbrake is configured to use



104
105
106
# File 'lib/airbrake/configuration.rb', line 104

def framework
  @framework
end

#hostObject

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_timeoutObject

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_timeoutObject

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

#ignoreObject (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_filtersObject (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_rakeObject (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_agentObject (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

#loggerObject

The logger used by Airbrake



98
99
100
# File 'lib/airbrake/configuration.rb', line 98

def logger
  @logger
end

#notifier_nameObject

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_urlObject

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_versionObject

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_filtersObject

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_filtersObject

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

#portObject



269
270
271
# File 'lib/airbrake/configuration.rb', line 269

def port
  @port || default_port
end

#project_idObject

Only used for JSON API



115
116
117
# File 'lib/airbrake/configuration.rb', line 115

def project_id
  @project_id
end

#project_rootObject

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_hostObject

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_passObject

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_portObject

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_userObject

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_filtersObject (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_exceptionsObject 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

#secureObject 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_modeObject 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_chainObject 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_attributesObject

User attributes that are being captured



112
113
114
# File 'lib/airbrake/configuration.rb', line 112

def user_attributes
  @user_attributes
end

#user_informationObject

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

Parameters:

  • option (Symbol)

    Key for a given attribute



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_pathObject



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.

Returns:

  • (Boolean)

    Returns true if an api string exists, false otherwise.



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.

Examples:

config.filter_bracktrace do |line|
  line.gsub(/^#{Rails.root}/, "[Rails.root]")
end

Parameters:

  • block (Proc)

    The new backtrace filter.

Yield Parameters:

  • line (String)

    A line in the backtrace.



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.

Examples:

config.ignore_by_filter do |exception_data|
  true if exception_data[:error_class] == "RuntimeError"
end

Parameters:

  • block (Proc)

    The new ignore filter

Yield Parameters:

  • data (Hash)

    The exception data given to Airbrake.notify

Yield Returns:

  • (Boolean)

    If the block returns true the exception will be ignored, otherwise it will be processed by airbrake.



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.

Parameters:

  • names (Array<Exception>)

    A list of exceptions to ignore.



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.

Parameters:

  • names (Array<Exception>)

    A list of rake exceptions to ignore.



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

Parameters:

  • A (Array<String>)

    list of user agents to ignore



231
232
233
# File 'lib/airbrake/configuration.rb', line 231

def ignore_user_agent_only=(names)
  @ignore_user_agent = [names].flatten
end

#local_cert_pathObject



320
321
322
# File 'lib/airbrake/configuration.rb', line 320

def local_cert_path
  File.expand_path(File.join("..", "..", "..", "resources", "ca-bundle.crt"), __FILE__)
end

#merge(hash) ⇒ Object

Returns a hash of all configurable options merged with hash

Parameters:

  • hash (Hash)

    A set of configuration options that will take precedence over the defaults



253
254
255
# File 'lib/airbrake/configuration.rb', line 253

def merge(hash)
  to_hash.merge(hash)
end

#protocolString

Determines whether protocol should be “http” or “https”. configuration, and “https” otherwise.

Returns:

  • (String)

    Returns “http” if you’ve set secure to false in



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.

Returns:

  • (Boolean)

    Returns false if in a development environment, true otherwise.



265
266
267
# File 'lib/airbrake/configuration.rb', line 265

def public?
  @public ||= !development_environments.include?(environment_name)
end

#to_hashObject

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