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
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.
-
#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_notifications ⇒ Boolean
True if the library should send error reports to Airbrake, false otherwise.
-
#host ⇒ String
(also: #error_host)
The host, which provides the API endpoint to which exceptions should be sent.
-
#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.
-
#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_hashwith 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
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
.instance ⇒ Config
144 145 146 |
# File 'lib/airbrake-ruby/config.rb', line 144 def instance @instance ||= new end |
Instance Attribute Details
#allowlist_keys ⇒ Array<String, Symbol, Regexp>
Returns the keys, which should be filtered.
83 84 85 |
# File 'lib/airbrake-ruby/config.rb', line 83 def allowlist_keys @allowlist_keys end |
#apm_host ⇒ String
Returns the host, which provides the API endpoint to which APM data should be sent.
58 59 60 |
# File 'lib/airbrake-ruby/config.rb', line 58 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 |
#blocklist_keys ⇒ Array<String, Symbol, Regexp>
Returns the keys, which should be filtered.
89 90 91 |
# File 'lib/airbrake-ruby/config.rb', line 89 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.
95 96 97 |
# File 'lib/airbrake-ruby/config.rb', line 95 def code_hunks @code_hunks end |
#environment ⇒ String, Symbol
Returns the environment the application is running in.
66 67 68 |
# File 'lib/airbrake-ruby/config.rb', line 66 def environment @environment end |
#error_notifications ⇒ Boolean
Returns true if the library should send error reports to Airbrake, false otherwise.
125 126 127 |
# File 'lib/airbrake-ruby/config.rb', line 125 def error_notifications @error_notifications end |
#host ⇒ String Also known as: error_host
Returns the host, which provides the API endpoint to which exceptions should be sent.
47 48 49 |
# File 'lib/airbrake-ruby/config.rb', line 47 def host @host 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.
73 74 75 |
# File 'lib/airbrake-ruby/config.rb', line 73 def ignore_environments @ignore_environments end |
#job_stats ⇒ Boolean
Returns true if the library should send job/queue/worker stats to Airbrake, false otherwise.
119 120 121 |
# File 'lib/airbrake-ruby/config.rb', line 119 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.
101 102 103 |
# File 'lib/airbrake-ruby/config.rb', line 101 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.
107 108 109 |
# File 'lib/airbrake-ruby/config.rb', line 107 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.
113 114 115 |
# File 'lib/airbrake-ruby/config.rb', line 113 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.
137 138 139 |
# File 'lib/airbrake-ruby/config.rb', line 137 def remote_config @remote_config end |
#remote_config_host ⇒ String
Returns the host which should be used for fetching remote configuration options.
131 132 133 |
# File 'lib/airbrake-ruby/config.rb', line 131 def remote_config_host @remote_config_host end |
#root_directory ⇒ String, Pathname
Returns the working directory of your project.
62 63 64 |
# File 'lib/airbrake-ruby/config.rb', line 62 def root_directory @root_directory end |
#timeout ⇒ Integer
Returns The HTTP timeout in seconds.
77 78 79 |
# File 'lib/airbrake-ruby/config.rb', line 77 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.
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_ability ⇒ Promise
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.
251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/airbrake-ruby/config.rb', line 251 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.
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.
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.
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.
218 219 220 |
# File 'lib/airbrake-ruby/config.rb', line 218 def valid? validate.resolved? end |
#validate ⇒ Promise
224 225 226 |
# File 'lib/airbrake-ruby/config.rb', line 224 def validate Validator.validate(self) end |