Class: Airbrake::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake-ruby/config.rb,
lib/airbrake-ruby/config/processor.rb,
lib/airbrake-ruby/config/validator.rb

Overview

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

Since:

  • v1.0.0

Defined Under Namespace

Classes: Processor, Validator

Constant Summary collapse

HOST_DEPRECATION_MSG =

Since:

  • v1.0.0

"**Airbrake: the 'host' option is deprecated. Use " \
"'error_host' instead".freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_config = {}) ⇒ Config

rubocop:disable Metrics/AbcSize, Metrics/MethodLength

Parameters:

  • user_config (Hash{Symbol=>Object}) (defaults to: {})

    the hash to be used to build the config

Since:

  • v1.0.0



154
155
156
157
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
184
185
186
187
# 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

Class Attribute Details

.instanceConfig

Returns:

Since:

  • v1.0.0



146
147
148
# File 'lib/airbrake-ruby/config.rb', line 146

def instance
  @instance ||= new
end

Instance Attribute Details

#allowlist_keysArray<String, Symbol, Regexp>

Returns the keys, which should be filtered.

Returns:

  • (Array<String, Symbol, Regexp>)

    the keys, which should be filtered

Since:

  • v4.15.0



79
80
81
# File 'lib/airbrake-ruby/config.rb', line 79

def allowlist_keys
  @allowlist_keys
end

#apm_hostString

Returns the host, which provides the API endpoint to which APM data should be sent.

Returns:

  • (String)

    the host, which provides the API endpoint to which APM data should be sent

Since:

  • v5.0.0



54
55
56
# File 'lib/airbrake-ruby/config.rb', line 54

def apm_host
  @apm_host
end

#app_versionString

Returns the version of the user’s application.

Returns:

  • (String)

    the version of the user’s application

Since:

  • v1.0.0



27
28
29
# File 'lib/airbrake-ruby/config.rb', line 27

def app_version
  @app_version
end

#backlogBoolean

Returns true if the library should keep a backlog of failed notices or APM events and retry them after an interval, false otherwise.

Returns:

  • (Boolean)

    true if the library should keep a backlog of failed notices or APM events and retry them after an interval, false otherwise

Since:

  • v6.2.0



139
140
141
# File 'lib/airbrake-ruby/config.rb', line 139

def backlog
  @backlog
end

#blocklist_keysArray<String, Symbol, Regexp>

Returns the keys, which should be filtered.

Returns:

  • (Array<String, Symbol, Regexp>)

    the keys, which should be filtered

Since:

  • v4.15.0



85
86
87
# File 'lib/airbrake-ruby/config.rb', line 85

def blocklist_keys
  @blocklist_keys
end

#code_hunksBoolean

Returns true if the library should attach code hunks to each frame in a backtrace, false otherwise.

Returns:

  • (Boolean)

    true if the library should attach code hunks to each frame in a backtrace, false otherwise

Since:

  • v2.5.0



91
92
93
# File 'lib/airbrake-ruby/config.rb', line 91

def code_hunks
  @code_hunks
end

#environmentString, Symbol

Returns the environment the application is running in.

Returns:

  • (String, Symbol)

    the environment the application is running in

Since:

  • v1.0.0



62
63
64
# File 'lib/airbrake-ruby/config.rb', line 62

def environment
  @environment
end

#error_hostString

Returns the host, which provides the API endpoint to which exceptions should be sent.

Returns:

  • (String)

    the host, which provides the API endpoint to which exceptions should be sent

Since:

  • v5.0.0



48
49
50
# File 'lib/airbrake-ruby/config.rb', line 48

def error_host
  @error_host
end

#error_notificationsBoolean

Returns true if the library should send error reports to Airbrake, false otherwise.

Returns:

  • (Boolean)

    true if the library should send error reports to Airbrake, false otherwise

Since:

  • v5.0.0



121
122
123
# File 'lib/airbrake-ruby/config.rb', line 121

def error_notifications
  @error_notifications
end

#ignore_environmentsArray<String,Symbol,Regexp>

Returns 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.

Returns:

  • (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.

Since:

  • v1.0.0



69
70
71
# File 'lib/airbrake-ruby/config.rb', line 69

def ignore_environments
  @ignore_environments
end

#job_statsBoolean

Returns true if the library should send job/queue/worker stats to Airbrake, false otherwise.

Returns:

  • (Boolean)

    true if the library should send job/queue/worker stats to Airbrake, false otherwise

Since:

  • v4.12.0



115
116
117
# File 'lib/airbrake-ruby/config.rb', line 115

def job_stats
  @job_stats
end

#loggerLogger

Returns the default logger used for debug output.

Returns:

  • (Logger)

    the default logger used for debug output

Since:

  • v1.0.0



23
24
25
# File 'lib/airbrake-ruby/config.rb', line 23

def logger
  @logger
end

#performance_statsBoolean

Returns true if the library should send route performance stats to Airbrake, false otherwise.

Returns:

  • (Boolean)

    true if the library should send route performance stats to Airbrake, false otherwise

Since:

  • v3.2.0



97
98
99
# File 'lib/airbrake-ruby/config.rb', line 97

def performance_stats
  @performance_stats
end

#performance_stats_flush_periodInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns how many seconds to wait before sending collected route stats.

Returns:

  • (Integer)

    how many seconds to wait before sending collected route stats

Since:

  • v3.2.0



103
104
105
# File 'lib/airbrake-ruby/config.rb', line 103

def performance_stats_flush_period
  @performance_stats_flush_period
end

#project_idInteger

Returns the project identificator. This value must be set.

Returns:

  • (Integer)

    the project identificator. This value must be set.

Since:

  • v1.0.0



10
11
12
# File 'lib/airbrake-ruby/config.rb', line 10

def project_id
  @project_id
end

#project_keyString

Returns the project key. This value must be set.

Returns:

  • (String)

    the project key. This value must be set.

Since:

  • v1.0.0



14
15
16
# File 'lib/airbrake-ruby/config.rb', line 14

def project_key
  @project_key
end

#proxyHash

Returns the proxy parameters such as (:host, :port, :user and :password).

Returns:

  • (Hash)

    the proxy parameters such as (:host, :port, :user and :password)

Since:

  • v1.0.0



19
20
21
# File 'lib/airbrake-ruby/config.rb', line 19

def proxy
  @proxy
end

#query_statsBoolean

Returns true if the library should send SQL stats to Airbrake, false otherwise.

Returns:

  • (Boolean)

    true if the library should send SQL stats to Airbrake, false otherwise

Since:

  • v4.6.0



109
110
111
# File 'lib/airbrake-ruby/config.rb', line 109

def query_stats
  @query_stats
end

#queue_sizeInteger

Returns the max number of notices that can be queued up.

Returns:

  • (Integer)

    the max number of notices that can be queued up

Since:

  • v1.0.0



37
38
39
# File 'lib/airbrake-ruby/config.rb', line 37

def queue_size
  @queue_size
end

#remote_configString

Returns true if notifier should periodically fetch remote configuration, false otherwise.

Returns:

  • (String)

    true if notifier should periodically fetch remote configuration, false otherwise

Since:

  • v5.2.0



133
134
135
# File 'lib/airbrake-ruby/config.rb', line 133

def remote_config
  @remote_config
end

#remote_config_hostString

Returns the host which should be used for fetching remote configuration options.

Returns:

  • (String)

    the host which should be used for fetching remote configuration options

Since:

  • v5.0.0



127
128
129
# File 'lib/airbrake-ruby/config.rb', line 127

def remote_config_host
  @remote_config_host
end

#root_directoryString, Pathname

Returns the working directory of your project.

Returns:

  • (String, Pathname)

    the working directory of your project

Since:

  • v1.0.0



58
59
60
# File 'lib/airbrake-ruby/config.rb', line 58

def root_directory
  @root_directory
end

#timeoutInteger

Returns The HTTP timeout in seconds.

Returns:

  • (Integer)

    The HTTP timeout in seconds.

Since:

  • v1.0.0



73
74
75
# File 'lib/airbrake-ruby/config.rb', line 73

def timeout
  @timeout
end

#versionsHash{String=>String}

Returns arbitrary versions that your app wants to track.

Returns:

  • (Hash{String=>String})

    arbitrary versions that your app wants to track

Since:

  • v2.10.0



33
34
35
# File 'lib/airbrake-ruby/config.rb', line 33

def versions
  @versions
end

#workersInteger

Returns the number of worker threads that process the notice queue.

Returns:

  • (Integer)

    the number of worker threads that process the notice queue

Since:

  • v1.0.0



42
43
44
# File 'lib/airbrake-ruby/config.rb', line 42

def workers
  @workers
end

Instance Method Details

#check_configurationPromise

Returns resolved promise if config is valid & can notify, rejected otherwise.

Returns:

  • (Promise)

    resolved promise if config is valid & can notify, rejected otherwise

Since:

  • v1.0.0



244
245
246
247
248
249
# File 'lib/airbrake-ruby/config.rb', line 244

def check_configuration
  promise = validate
  return promise if promise.rejected?

  check_notify_ability
end

#check_notify_abilityPromise

Returns:

See Also:

Since:

  • v1.0.0



232
233
234
# File 'lib/airbrake-ruby/config.rb', line 232

def check_notify_ability
  Validator.check_notify_ability(self)
end

#check_performance_options(metric) ⇒ Promise

Returns resolved promise if neither of the performance options reject it, false otherwise.

Returns:

  • (Promise)

    resolved promise if neither of the performance options reject it, false otherwise

Since:

  • v1.0.0



253
254
255
256
257
258
259
260
261
262
263
264
265
# 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_endpointURI

The full URL to the Airbrake Notice API. Based on the :error_host option.

Returns:

  • (URI)

    the endpoint address

Since:

  • v1.0.0



192
193
194
195
196
197
198
199
# 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

#hostObject

Since:

  • v1.0.0



270
271
272
273
# File 'lib/airbrake-ruby/config.rb', line 270

def host
  logger.warn(HOST_DEPRECATION_MSG)
  @error_host
end

#host=(value) ⇒ Object

Since:

  • v1.0.0



275
276
277
278
# File 'lib/airbrake-ruby/config.rb', line 275

def host=(value)
  logger.warn(HOST_DEPRECATION_MSG)
  @error_host = value
end

#ignored_environment?Boolean

Returns true if the config ignores current environment, false otherwise.

Returns:

  • (Boolean)

    true if the config ignores current environment, false otherwise

Since:

  • v1.0.0



238
239
240
# File 'lib/airbrake-ruby/config.rb', line 238

def ignored_environment?
  check_notify_ability.rejected?
end

#merge(config_hash) ⇒ self

Merges the given config_hash with itself.

Examples:

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

Returns:

  • (self)

    the merged config

Since:

  • v1.0.0



213
214
215
216
# 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?Boolean

Returns true if the config meets the requirements, false otherwise.

Returns:

  • (Boolean)

    true if the config meets the requirements, false otherwise

Since:

  • v1.0.0



220
221
222
# File 'lib/airbrake-ruby/config.rb', line 220

def valid?
  validate.resolved?
end

#validatePromise

Returns:

See Also:

Since:

  • v1.0.0



226
227
228
# File 'lib/airbrake-ruby/config.rb', line 226

def validate
  Validator.validate(self)
end