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

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, :project_root, :port, :protocol, :proxy_host,
:proxy_pass, :proxy_port, :proxy_user, :secure, :framework,
:user_information, :rescue_rake_exceptions].freeze
DEFAULT_PARAMS_FILTERS =
%w(password password_confirmation).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|
    if defined?(Gem)
      Gem.path.inject(line) do |line, path|
        line.gsub(/#{path}/, "[GEM_ROOT]")
      end
    end
  },
  lambda { |line| line if line !~ %r{lib/airbrake} }
].freeze
IGNORE_DEFAULT =
['ActiveRecord::RecordNotFound',
'ActionController::RoutingError',
'ActionController::InvalidAuthenticityToken',
'CGI::Session::CookieStore::TamperedWithCookie',
'ActionController::UnknownAction',
'AbstractController::ActionNotFound']

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Configuration) initialize



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/airbrake/configuration.rb', line 124

def initialize
  @secure                   = false
  @host                     = 'airbrakeapp.com'
  @http_open_timeout        = 2
  @http_read_timeout        = 5
  @params_filters           = DEFAULT_PARAMS_FILTERS.dup
  @backtrace_filters        = DEFAULT_BACKTRACE_FILTERS.dup
  @ignore_by_filters        = []
  @ignore                   = IGNORE_DEFAULT.dup
  @ignore_user_agent        = []
  @development_environments = %w(development test cucumber)
  @development_lookup       = true
  @notifier_name            = 'Airbrake Notifier'
  @notifier_version         = VERSION
  @notifier_url             = 'http://airbrakeapp.com'
  @framework                = 'Standalone'
  @user_information         = 'Airbrake Error {{error_id}}'
  @rescue_rake_exceptions   = nil
end

Instance Attribute Details

- (Object) api_key

The API key for your project, found on the project edit form.



14
15
16
# File 'lib/airbrake/configuration.rb', line 14

def api_key
  @api_key
end

- (Object) backtrace_filters (readonly)

A list of filters for cleaning and pruning the backtrace. See #filter_backtrace.



49
50
51
# File 'lib/airbrake/configuration.rb', line 49

def backtrace_filters
  @backtrace_filters
end

- (Object) development_environments

A list of environments in which notifications should not be sent.



61
62
63
# File 'lib/airbrake/configuration.rb', line 61

def development_environments
  @development_environments
end

- (Object) development_lookup

true if you want to check for production errors matching development errors, false otherwise.



64
65
66
# File 'lib/airbrake/configuration.rb', line 64

def development_lookup
  @development_lookup
end

- (Object) environment_name

The name of the environment the application is running in



67
68
69
# File 'lib/airbrake/configuration.rb', line 67

def environment_name
  @environment_name
end

- (Object) framework

The framework Airbrake is configured to use



88
89
90
# File 'lib/airbrake/configuration.rb', line 88

def framework
  @framework
end

- (Object) host

The host to connect to (defaults to airbrakeapp.com).



17
18
19
# File 'lib/airbrake/configuration.rb', line 17

def host
  @host
end

- (Object) http_open_timeout

The HTTP open timeout in seconds (defaults to 2).



27
28
29
# File 'lib/airbrake/configuration.rb', line 27

def http_open_timeout
  @http_open_timeout
end

- (Object) http_read_timeout

The HTTP read timeout in seconds (defaults to 5).



30
31
32
# File 'lib/airbrake/configuration.rb', line 30

def http_read_timeout
  @http_read_timeout
end

- (Object) ignore (readonly)

A list of exception classes to ignore. The array can be appended to.



55
56
57
# File 'lib/airbrake/configuration.rb', line 55

def ignore
  @ignore
end

- (Object) ignore_by_filters (readonly)

A list of filters for ignoring exceptions. See #ignore_by_filter.



52
53
54
# File 'lib/airbrake/configuration.rb', line 52

def ignore_by_filters
  @ignore_by_filters
end

- (Object) ignore_user_agent (readonly)

A list of user agents that are being ignored. The array can be appended to.



58
59
60
# File 'lib/airbrake/configuration.rb', line 58

def ignore_user_agent
  @ignore_user_agent
end

- (Object) logger

The logger used by Airbrake



82
83
84
# File 'lib/airbrake/configuration.rb', line 82

def logger
  @logger
end

- (Object) notifier_name

The name of the notifier library being used to send notifications (such as “Airbrake Notifier”)



73
74
75
# File 'lib/airbrake/configuration.rb', line 73

def notifier_name
  @notifier_name
end

- (Object) notifier_url

The url of the notifier library being used to send notifications



79
80
81
# File 'lib/airbrake/configuration.rb', line 79

def notifier_url
  @notifier_url
end

- (Object) notifier_version

The version of the notifier library being used to send notifications (such as “1.0.2”)



76
77
78
# File 'lib/airbrake/configuration.rb', line 76

def notifier_version
  @notifier_version
end

- (Object) params_filters (readonly)

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.



46
47
48
# File 'lib/airbrake/configuration.rb', line 46

def params_filters
  @params_filters
end

- (Object) port

The port on which your Airbrake server runs (defaults to 443 for secure connections, 80 for insecure connections).



21
22
23
# File 'lib/airbrake/configuration.rb', line 21

def port
  @port
end

- (Object) project_root

The path to the project in which the error occurred, such as the RAILS_ROOT



70
71
72
# File 'lib/airbrake/configuration.rb', line 70

def project_root
  @project_root
end

- (Object) proxy_host

The hostname of your proxy server (if using a proxy)



33
34
35
# File 'lib/airbrake/configuration.rb', line 33

def proxy_host
  @proxy_host
end

- (Object) proxy_pass

The password to use when logging into your proxy server (if using a proxy)



42
43
44
# File 'lib/airbrake/configuration.rb', line 42

def proxy_pass
  @proxy_pass
end

- (Object) proxy_port

The port of your proxy server (if using a proxy)



36
37
38
# File 'lib/airbrake/configuration.rb', line 36

def proxy_port
  @proxy_port
end

- (Object) proxy_user

The username to use when logging into your proxy server (if using a proxy)



39
40
41
# File 'lib/airbrake/configuration.rb', line 39

def proxy_user
  @proxy_user
end

- (Object) 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)



92
93
94
# File 'lib/airbrake/configuration.rb', line 92

def rescue_rake_exceptions
  @rescue_rake_exceptions
end

- (Object) secure Also known as: secure?

true for https connections, false for http connections.



24
25
26
# File 'lib/airbrake/configuration.rb', line 24

def secure
  @secure
end

- (Object) user_information

The text that the placeholder is replaced with. {error_id} is the actual error number.



85
86
87
# File 'lib/airbrake/configuration.rb', line 85

def user_information
  @user_information
end

Instance Method Details

- (Object) [](option)

Allows config options to be read like a hash



190
191
192
# File 'lib/airbrake/configuration.rb', line 190

def [](option)
  send(option)
end

- (Object) environment_filters



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

def environment_filters
  warn 'config.environment_filters has been deprecated and has no effect.'
  []
end

- (Object) filter_backtrace(&block) {|line| ... }

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

Yield Parameters:

  • line (String)

    A line in the backtrace.



155
156
157
# File 'lib/airbrake/configuration.rb', line 155

def filter_backtrace(&block)
  self.backtrace_filters << block
end

- (Object) ignore_by_filter(&block) {|data| ... }

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

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.



169
170
171
# File 'lib/airbrake/configuration.rb', line 169

def ignore_by_filter(&block)
  self.ignore_by_filters << block
end

- (Object) ignore_only=(names)

Overrides the list of default ignored errors.



176
177
178
# File 'lib/airbrake/configuration.rb', line 176

def ignore_only=(names)
  @ignore = [names].flatten
end

- (Object) ignore_user_agent_only=(names)

Overrides the list of default ignored user agents



183
184
185
# File 'lib/airbrake/configuration.rb', line 183

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

- (Object) js_notifier=(*args)



226
227
228
# File 'lib/airbrake/configuration.rb', line 226

def js_notifier=(*args)
  warn '[AIRBRAKE] config.js_notifier has been deprecated and has no effect.  You should use <%= airbrake_javascript_notifier %> directly at the top of your layouts.  Be sure to place it before all other javascript.'
end

- (Object) merge(hash)

Returns a hash of all configurable options merged with hash



204
205
206
# File 'lib/airbrake/configuration.rb', line 204

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

- (Object) protocol



218
219
220
221
222
223
224
# File 'lib/airbrake/configuration.rb', line 218

def protocol
  if secure?
    'https'
  else
    'http'
  end
end

- (Boolean) public?

Determines if the notifier will send notices.



210
211
212
# File 'lib/airbrake/configuration.rb', line 210

def public?
  !development_environments.include?(environment_name)
end

- (Object) to_hash

Returns a hash of all configurable options



195
196
197
198
199
# File 'lib/airbrake/configuration.rb', line 195

def to_hash
  OPTIONS.inject({}) do |hash, option|
    hash.merge(option.to_sym => send(option))
  end
end