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

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



152
153
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
# File 'lib/airbrake-ruby/config.rb', line 152

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 = 'https://api.airbrake.io'
  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

  merge(user_config)
end

Class Attribute Details

.instanceConfig

Returns:

Since:

  • v1.0.0



144
145
146
# File 'lib/airbrake-ruby/config.rb', line 144

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



83
84
85
# File 'lib/airbrake-ruby/config.rb', line 83

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



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

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

#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



89
90
91
# File 'lib/airbrake-ruby/config.rb', line 89

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



95
96
97
# File 'lib/airbrake-ruby/config.rb', line 95

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



66
67
68
# File 'lib/airbrake-ruby/config.rb', line 66

def environment
  @environment
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



125
126
127
# File 'lib/airbrake-ruby/config.rb', line 125

def error_notifications
  @error_notifications
end

#hostString Also known as: error_host

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:

  • v1.0.0



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

def host
  @host
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



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

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



119
120
121
# File 'lib/airbrake-ruby/config.rb', line 119

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



101
102
103
# File 'lib/airbrake-ruby/config.rb', line 101

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



107
108
109
# File 'lib/airbrake-ruby/config.rb', line 107

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



113
114
115
# File 'lib/airbrake-ruby/config.rb', line 113

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



137
138
139
# File 'lib/airbrake-ruby/config.rb', line 137

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



131
132
133
# File 'lib/airbrake-ruby/config.rb', line 131

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



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

def root_directory
  @root_directory
end

#timeoutInteger

Returns The HTTP timeout in seconds.

Returns:

  • (Integer)

    The HTTP timeout in seconds.

Since:

  • v1.0.0



77
78
79
# File 'lib/airbrake-ruby/config.rb', line 77

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



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

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

  check_notify_ability
end

#check_notify_abilityPromise

Returns:

See Also:

Since:

  • v1.0.0



230
231
232
# File 'lib/airbrake-ruby/config.rb', line 230

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



251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/airbrake-ruby/config.rb', line 251

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



190
191
192
193
194
195
196
197
# File 'lib/airbrake-ruby/config.rb', line 190

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

#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



236
237
238
# File 'lib/airbrake-ruby/config.rb', line 236

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



211
212
213
214
# File 'lib/airbrake-ruby/config.rb', line 211

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



218
219
220
# File 'lib/airbrake-ruby/config.rb', line 218

def valid?
  validate.resolved?
end

#validatePromise

Returns:

See Also:

Since:

  • v1.0.0



224
225
226
# File 'lib/airbrake-ruby/config.rb', line 224

def validate
  Validator.validate(self)
end