Class: Airbrake::Config
- Inherits:
-
Object
- Object
- Airbrake::Config
- 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.
Defined Under Namespace
Constant Summary collapse
- HOST_DEPRECATION_MSG =
"**Airbrake: the 'host' option is deprecated. Use " \ "'error_host' instead".freeze
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#allowlist_keys ⇒ Array<String, Symbol, Regexp>
The keys, which should be filtered.
-
#apm_host ⇒ String
The host, which provides the API endpoint to which APM data should be sent.
-
#app_version ⇒ String
The version of the user’s application.
-
#backlog ⇒ Boolean
True if the library should keep a backlog of failed notices or APM events and retry them after an interval, false otherwise.
-
#blocklist_keys ⇒ Array<String, Symbol, Regexp>
The keys, which should be filtered.
-
#code_hunks ⇒ Boolean
True if the library should attach code hunks to each frame in a backtrace, false otherwise.
-
#environment ⇒ String, Symbol
The environment the application is running in.
-
#error_host ⇒ String
The host, which provides the API endpoint to which exceptions should be sent.
-
#error_notifications ⇒ Boolean
True if the library should send error reports to Airbrake, false otherwise.
-
#ignore_environments ⇒ Array<String,Symbol,Regexp>
The array of environments that forbids sending exceptions when the application is running in them.
-
#job_stats ⇒ Boolean
True if the library should send job/queue/worker stats to Airbrake, false otherwise.
-
#logger ⇒ Logger
The default logger used for debug output.
-
#performance_stats ⇒ Boolean
True if the library should send route performance stats to Airbrake, false otherwise.
-
#performance_stats_flush_period ⇒ Integer
private
How many seconds to wait before sending collected route stats.
-
#project_id ⇒ Integer
The project identificator.
-
#project_key ⇒ String
The project key.
-
#proxy ⇒ Hash
The proxy parameters such as (:host, :port, :user and :password).
-
#query_stats ⇒ Boolean
True if the library should send SQL stats to Airbrake, false otherwise.
-
#queue_size ⇒ Integer
The max number of notices that can be queued up.
-
#remote_config ⇒ String
True if notifier should periodically fetch remote configuration, false otherwise.
-
#remote_config_host ⇒ String
The host which should be used for fetching remote configuration options.
-
#root_directory ⇒ String, Pathname
The working directory of your project.
-
#timeout ⇒ Integer
The HTTP timeout in seconds.
-
#versions ⇒ Hash{String=>String}
Arbitrary versions that your app wants to track.
-
#workers ⇒ Integer
The number of worker threads that process the notice queue.
Instance Method Summary collapse
-
#check_configuration ⇒ Promise
Resolved promise if config is valid & can notify, rejected otherwise.
- #check_notify_ability ⇒ Promise
-
#check_performance_options(metric) ⇒ Promise
Resolved promise if neither of the performance options reject it, false otherwise.
-
#error_endpoint ⇒ URI
The full URL to the Airbrake Notice API.
- #host ⇒ Object
- #host=(value) ⇒ Object
-
#ignored_environment? ⇒ Boolean
True if the config ignores current environment, false otherwise.
-
#initialize(user_config = {}) ⇒ Config
constructor
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
#merge(config_hash) ⇒ self
Merges the given
config_hash
with itself. -
#valid? ⇒ Boolean
True if the config meets the requirements, false otherwise.
- #validate ⇒ Promise
Constructor Details
#initialize(user_config = {}) ⇒ Config
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
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
.instance ⇒ Config
146 147 148 |
# File 'lib/airbrake-ruby/config.rb', line 146 def instance @instance ||= new end |
Instance Attribute Details
#allowlist_keys ⇒ Array<String, Symbol, Regexp>
Returns the keys, which should be filtered.
79 80 81 |
# File 'lib/airbrake-ruby/config.rb', line 79 def allowlist_keys @allowlist_keys end |
#apm_host ⇒ String
Returns the host, which provides the API endpoint to which APM data should be sent.
54 55 56 |
# File 'lib/airbrake-ruby/config.rb', line 54 def apm_host @apm_host end |
#app_version ⇒ String
Returns the version of the user’s application.
27 28 29 |
# File 'lib/airbrake-ruby/config.rb', line 27 def app_version @app_version end |
#backlog ⇒ Boolean
Returns true if the library should keep a backlog of failed notices or APM events and retry them after an interval, false otherwise.
139 140 141 |
# File 'lib/airbrake-ruby/config.rb', line 139 def backlog @backlog end |
#blocklist_keys ⇒ Array<String, Symbol, Regexp>
Returns the keys, which should be filtered.
85 86 87 |
# File 'lib/airbrake-ruby/config.rb', line 85 def blocklist_keys @blocklist_keys end |
#code_hunks ⇒ Boolean
Returns true if the library should attach code hunks to each frame in a backtrace, false otherwise.
91 92 93 |
# File 'lib/airbrake-ruby/config.rb', line 91 def code_hunks @code_hunks end |
#environment ⇒ String, Symbol
Returns the environment the application is running in.
62 63 64 |
# File 'lib/airbrake-ruby/config.rb', line 62 def environment @environment end |
#error_host ⇒ String
Returns the host, which provides the API endpoint to which exceptions should be sent.
48 49 50 |
# File 'lib/airbrake-ruby/config.rb', line 48 def error_host @error_host end |
#error_notifications ⇒ Boolean
Returns true if the library should send error reports to Airbrake, false otherwise.
121 122 123 |
# File 'lib/airbrake-ruby/config.rb', line 121 def error_notifications @error_notifications end |
#ignore_environments ⇒ Array<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.
69 70 71 |
# File 'lib/airbrake-ruby/config.rb', line 69 def ignore_environments @ignore_environments end |
#job_stats ⇒ Boolean
Returns true if the library should send job/queue/worker stats to Airbrake, false otherwise.
115 116 117 |
# File 'lib/airbrake-ruby/config.rb', line 115 def job_stats @job_stats end |
#logger ⇒ Logger
Returns the default logger used for debug output.
23 24 25 |
# File 'lib/airbrake-ruby/config.rb', line 23 def logger @logger end |
#performance_stats ⇒ Boolean
Returns true if the library should send route performance stats to Airbrake, false otherwise.
97 98 99 |
# File 'lib/airbrake-ruby/config.rb', line 97 def performance_stats @performance_stats end |
#performance_stats_flush_period ⇒ Integer
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.
103 104 105 |
# File 'lib/airbrake-ruby/config.rb', line 103 def performance_stats_flush_period @performance_stats_flush_period end |
#project_id ⇒ Integer
Returns the project identificator. This value must be set.
10 11 12 |
# File 'lib/airbrake-ruby/config.rb', line 10 def project_id @project_id end |
#project_key ⇒ String
Returns the project key. This value must be set.
14 15 16 |
# File 'lib/airbrake-ruby/config.rb', line 14 def project_key @project_key end |
#proxy ⇒ Hash
Returns the proxy parameters such as (:host, :port, :user and :password).
19 20 21 |
# File 'lib/airbrake-ruby/config.rb', line 19 def proxy @proxy end |
#query_stats ⇒ Boolean
Returns true if the library should send SQL stats to Airbrake, false otherwise.
109 110 111 |
# File 'lib/airbrake-ruby/config.rb', line 109 def query_stats @query_stats end |
#queue_size ⇒ Integer
Returns the max number of notices that can be queued up.
37 38 39 |
# File 'lib/airbrake-ruby/config.rb', line 37 def queue_size @queue_size end |
#remote_config ⇒ String
Returns true if notifier should periodically fetch remote configuration, false otherwise.
133 134 135 |
# File 'lib/airbrake-ruby/config.rb', line 133 def remote_config @remote_config end |
#remote_config_host ⇒ String
Returns the host which should be used for fetching remote configuration options.
127 128 129 |
# File 'lib/airbrake-ruby/config.rb', line 127 def remote_config_host @remote_config_host end |
#root_directory ⇒ String, Pathname
Returns the working directory of your project.
58 59 60 |
# File 'lib/airbrake-ruby/config.rb', line 58 def root_directory @root_directory end |
#timeout ⇒ Integer
Returns The HTTP timeout in seconds.
73 74 75 |
# File 'lib/airbrake-ruby/config.rb', line 73 def timeout @timeout end |
#versions ⇒ Hash{String=>String}
Returns arbitrary versions that your app wants to track.
33 34 35 |
# File 'lib/airbrake-ruby/config.rb', line 33 def versions @versions end |
#workers ⇒ Integer
Returns the number of worker threads that process the notice queue.
42 43 44 |
# File 'lib/airbrake-ruby/config.rb', line 42 def workers @workers end |
Instance Method Details
#check_configuration ⇒ Promise
Returns resolved promise if config is valid & can notify, rejected otherwise.
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_ability ⇒ Promise
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.
253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/airbrake-ruby/config.rb', line 253 def (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 ⇒ URI
The full URL to the Airbrake Notice API. Based on the :error_host
option.
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 |
#host ⇒ Object
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
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.
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.
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.
220 221 222 |
# File 'lib/airbrake-ruby/config.rb', line 220 def valid? validate.resolved? end |