Class: Bugsnag::Configuration
- Inherits:
-
Object
- Object
- Bugsnag::Configuration
- Defined in:
- lib/bugsnag/configuration.rb
Constant Summary collapse
- API_KEY_REGEX =
/[0-9a-f]{32}/i
- THREAD_LOCAL_NAME =
"bugsnag_req_data"
- DEFAULT_NOTIFY_ENDPOINT =
"https://notify.bugsnag.com"
- DEFAULT_SESSION_ENDPOINT =
"https://sessions.bugsnag.com"
- DEFAULT_ENDPOINT =
DEFAULT_NOTIFY_ENDPOINT
- DEFAULT_META_DATA_FILTERS =
[ /authorization/i, /cookie/i, /password/i, /secret/i, /warden\.user\.([^.]+)\.key/, "rack.request.form_vars" ].freeze
- DEFAULT_MAX_BREADCRUMBS =
25
- DEFAULT_VENDOR_PATH =
Path to vendored code. Used to mark file paths as out of project.
%r{^(vendor/|\.bundle/)}
Instance Attribute Summary collapse
-
#api_key ⇒ String?
Your Integration API Key.
-
#app_version ⇒ String?
The current version of your application.
-
#auto_capture_sessions ⇒ Boolean
(also: #track_sessions)
Whether Bugsnag should automatically record sessions.
-
#auto_notify ⇒ Boolean
Whether notifications should automatically be sent.
-
#before_breadcrumb_callbacks ⇒ Array<#call>
Callables to be run before a breadcrumb is logged.
- #ca_file ⇒ String?
-
#discard_classes ⇒ Set<String, Regexp>
Exception classes that will be discarded and not sent to Bugsnag.
-
#enable_sessions ⇒ Boolean
readonly
Whether sessions will be delivered.
-
#enabled_automatic_breadcrumb_types ⇒ Array<String>
A list of strings indicating allowable automatic breadcrumb types.
-
#hostname ⇒ String
The name or descriptor of the Ruby server host.
-
#ignore_classes ⇒ Set<Class, Proc>
deprecated
Deprecated.
Use #discard_classes instead
-
#logger ⇒ Logger
The logger to use for Bugsnag log messages.
-
#max_breadcrumbs ⇒ Integer
The maximum allowable amount of breadcrumbs per thread.
-
#meta_data_filters ⇒ Set<String, Regexp>
A list of keys that should be filtered out from the report and breadcrumb metadata before sending them to Bugsnag.
-
#middleware ⇒ MiddlewareStack
The middleware stack that will run on every notification.
-
#notify_endpoint ⇒ String
(also: #endpoint)
readonly
The URL error notifications will be delivered to.
-
#notify_release_stages ⇒ Array<String>?
A list of which release stages should cause notifications to be sent.
-
#project_root ⇒ String?
Any stacktrace lines that match this path will be marked as ‘in project’.
-
#proxy_host ⇒ String?
The host address of the HTTP proxy that should be used when making requests.
-
#proxy_password ⇒ String?
The password for the user that should be used when making requests via a HTTP proxy.
-
#proxy_port ⇒ Integer?
The port number of the HTTP proxy that should be used when making requests.
-
#proxy_user ⇒ String?
The user that should be used when making requests via a HTTP proxy.
-
#release_stage ⇒ String?
The current stage of the release process, e.g.
-
#send_code ⇒ Boolean
Whether code snippets from the exception stacktrace should be sent with notifications.
-
#send_environment ⇒ Boolean
Whether to automatically attach the Rack environment to notifications.
-
#session_endpoint ⇒ String
The URL session notifications will be delivered to.
-
#timeout ⇒ Integer
The HTTP request timeout, defaults to 15 seconds.
- #vendor_path ⇒ Regexp
Instance Method Summary collapse
-
#add_on_error(callback) ⇒ void
Add the given callback to the list of on_error callbacks.
-
#app_type ⇒ String?
Get the type of application executing the current code.
-
#app_type=(app_type) ⇒ void
Set the type of application executing the current code.
-
#breadcrumbs ⇒ Bugsnag::Utility::CircularBuffer
Returns the breadcrumb circular buffer.
-
#clear_request_data ⇒ void
Clears the array of data attached to every error notification.
-
#debug(message) ⇒ Object
Logs a debug level message.
-
#delivery_method ⇒ Symbol
Gets the delivery_method that Bugsnag will use to communicate with the notification endpoint.
-
#delivery_method=(delivery_method) ⇒ void
Sets the delivery_method that Bugsnag will use to communicate with the notification endpoint.
-
#disable_sessions ⇒ void
Disables session tracking and delivery.
-
#endpoint=(new_notify_endpoint) ⇒ void
deprecated
Deprecated.
Use #set_endpoints instead
-
#info(message) ⇒ Object
Logs an info level message.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#parse_proxy(uri) ⇒ void
Parses and sets proxy from a uri.
-
#remove_on_error(callback) ⇒ void
Remove the given callback from the list of on_error callbacks.
-
#request_data ⇒ Hash
Returns the array of data that will be automatically attached to every error notification.
-
#set_endpoints(new_notify_endpoint, new_session_endpoint) ⇒ void
Sets the notification and session endpoints.
-
#set_request_data(key, value) ⇒ void
Sets an entry in the array of data attached to every error notification.
-
#should_notify_release_stage? ⇒ Boolean
Indicates whether the notifier should send a notification based on the configured release stage.
-
#unset_request_data(key, value) ⇒ void
Unsets an entry in the array of data attached to every error notification.
-
#valid_api_key? ⇒ Boolean
Tests whether the configured API key is valid.
-
#warn(message) ⇒ Object
Logs a warning level message.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/bugsnag/configuration.rb', line 175 def initialize @mutex = Mutex.new # Set up the defaults self.auto_notify = true self.send_environment = false self.send_code = true self. = Set.new(DEFAULT_META_DATA_FILTERS) self.scopes_to_filter = DEFAULT_SCOPES_TO_FILTER self.hostname = default_hostname self.runtime_versions = {} self.runtime_versions["ruby"] = RUBY_VERSION self.runtime_versions["jruby"] = JRUBY_VERSION if defined?(JRUBY_VERSION) self.timeout = 15 self.release_stage = ENV['BUGSNAG_RELEASE_STAGE'] self.notify_release_stages = nil self.auto_capture_sessions = true # All valid breadcrumb types should be allowable initially self. = Bugsnag::Breadcrumbs::VALID_BREADCRUMB_TYPES.dup self. = [] # Store max_breadcrumbs here instead of outputting breadcrumbs.max_items # to avoid infinite recursion when creating breadcrumb buffer @max_breadcrumbs = DEFAULT_MAX_BREADCRUMBS # These are set exclusively using the "set_endpoints" method @notify_endpoint = DEFAULT_NOTIFY_ENDPOINT @session_endpoint = DEFAULT_SESSION_ENDPOINT @enable_sessions = true # SystemExit and SignalException are common Exception types seen with # successful exits and are not automatically reported to Bugsnag # TODO move these defaults into `discard_classes` when `ignore_classes` # is removed self.ignore_classes = Set.new([SystemExit, SignalException]) self.discard_classes = Set.new([]) # Read the API key from the environment self.api_key = ENV["BUGSNAG_API_KEY"] # Read NET::HTTP proxy environment variables if (proxy_uri = ENV["https_proxy"] || ENV['http_proxy']) parse_proxy(proxy_uri) end # Set up vendor_path regex to mark stacktrace file paths as out of project. # Stacktrace lines that matches regex will be marked as "out of project" # will only appear in the full trace. self.vendor_path = DEFAULT_VENDOR_PATH # Set up logging self.logger = Logger.new(STDOUT) self.logger.level = Logger::INFO self.logger.formatter = proc do |severity, datetime, progname, msg| "** #{progname} #{datetime}: #{msg}\n" end # Configure the bugsnag middleware stack self.internal_middleware = Bugsnag::MiddlewareStack.new self.internal_middleware.use Bugsnag::Middleware::ExceptionMetaData self.internal_middleware.use Bugsnag::Middleware::DiscardErrorClass self.internal_middleware.use Bugsnag::Middleware::IgnoreErrorClass self.internal_middleware.use Bugsnag::Middleware::SuggestionData self.internal_middleware.use Bugsnag::Middleware::ClassifyError self.internal_middleware.use Bugsnag::Middleware::SessionData self.internal_middleware.use Bugsnag::Middleware::Breadcrumbs self.middleware = Bugsnag::MiddlewareStack.new self.middleware.use Bugsnag::Middleware::Callbacks end |
Instance Attribute Details
#api_key ⇒ String?
Your Integration API Key
20 21 22 |
# File 'lib/bugsnag/configuration.rb', line 20 def api_key @api_key end |
#app_version ⇒ String?
The current version of your application
51 52 53 |
# File 'lib/bugsnag/configuration.rb', line 51 def app_version @app_version end |
#auto_capture_sessions ⇒ Boolean Also known as: track_sessions
Whether Bugsnag should automatically record sessions
108 109 110 |
# File 'lib/bugsnag/configuration.rb', line 108 def auto_capture_sessions @auto_capture_sessions end |
#auto_notify ⇒ Boolean
Whether notifications should automatically be sent
32 33 34 |
# File 'lib/bugsnag/configuration.rb', line 32 def auto_notify @auto_notify end |
#before_breadcrumb_callbacks ⇒ Array<#call>
Callables to be run before a breadcrumb is logged
134 135 136 |
# File 'lib/bugsnag/configuration.rb', line 134 def @before_breadcrumb_callbacks end |
#ca_file ⇒ String?
35 36 37 |
# File 'lib/bugsnag/configuration.rb', line 35 def ca_file @ca_file end |
#discard_classes ⇒ Set<String, Regexp>
Exception classes that will be discarded and not sent to Bugsnag
104 105 106 |
# File 'lib/bugsnag/configuration.rb', line 104 def discard_classes @discard_classes end |
#enable_sessions ⇒ Boolean (readonly)
Whether sessions will be delivered
125 126 127 |
# File 'lib/bugsnag/configuration.rb', line 125 def enable_sessions @enable_sessions end |
#enabled_automatic_breadcrumb_types ⇒ Array<String>
A list of strings indicating allowable automatic breadcrumb types
130 131 132 |
# File 'lib/bugsnag/configuration.rb', line 130 def @enabled_automatic_breadcrumb_types end |
#hostname ⇒ String
The name or descriptor of the Ruby server host
96 97 98 |
# File 'lib/bugsnag/configuration.rb', line 96 def hostname @hostname end |
#ignore_classes ⇒ Set<Class, Proc>
Use #discard_classes instead
112 113 114 |
# File 'lib/bugsnag/configuration.rb', line 112 def ignore_classes @ignore_classes end |
#logger ⇒ Logger
The logger to use for Bugsnag log messages
60 61 62 |
# File 'lib/bugsnag/configuration.rb', line 60 def logger @logger end |
#max_breadcrumbs ⇒ Integer
The maximum allowable amount of breadcrumbs per thread
138 139 140 |
# File 'lib/bugsnag/configuration.rb', line 138 def @max_breadcrumbs end |
#meta_data_filters ⇒ Set<String, Regexp>
A list of keys that should be filtered out from the report and breadcrumb metadata before sending them to Bugsnag
56 57 58 |
# File 'lib/bugsnag/configuration.rb', line 56 def @meta_data_filters end |
#middleware ⇒ MiddlewareStack
The middleware stack that will run on every notification
64 65 66 |
# File 'lib/bugsnag/configuration.rb', line 64 def middleware @middleware end |
#notify_endpoint ⇒ String (readonly) Also known as: endpoint
The URL error notifications will be delivered to
116 117 118 |
# File 'lib/bugsnag/configuration.rb', line 116 def notify_endpoint @notify_endpoint end |
#notify_release_stages ⇒ Array<String>?
A list of which release stages should cause notifications to be sent
28 29 30 |
# File 'lib/bugsnag/configuration.rb', line 28 def notify_release_stages @notify_release_stages end |
#project_root ⇒ String?
Any stacktrace lines that match this path will be marked as ‘in project’
47 48 49 |
# File 'lib/bugsnag/configuration.rb', line 47 def project_root @project_root end |
#proxy_host ⇒ String?
The host address of the HTTP proxy that should be used when making requests
73 74 75 |
# File 'lib/bugsnag/configuration.rb', line 73 def proxy_host @proxy_host end |
#proxy_password ⇒ String?
The password for the user that should be used when making requests via a HTTP proxy
88 89 90 |
# File 'lib/bugsnag/configuration.rb', line 88 def proxy_password @proxy_password end |
#proxy_port ⇒ Integer?
The port number of the HTTP proxy that should be used when making requests
78 79 80 |
# File 'lib/bugsnag/configuration.rb', line 78 def proxy_port @proxy_port end |
#proxy_user ⇒ String?
The user that should be used when making requests via a HTTP proxy
83 84 85 |
# File 'lib/bugsnag/configuration.rb', line 83 def proxy_user @proxy_user end |
#release_stage ⇒ String?
The current stage of the release process, e.g. ‘development’, production’
24 25 26 |
# File 'lib/bugsnag/configuration.rb', line 24 def release_stage @release_stage end |
#send_code ⇒ Boolean
Whether code snippets from the exception stacktrace should be sent with notifications
43 44 45 |
# File 'lib/bugsnag/configuration.rb', line 43 def send_code @send_code end |
#send_environment ⇒ Boolean
Whether to automatically attach the Rack environment to notifications
39 40 41 |
# File 'lib/bugsnag/configuration.rb', line 39 def send_environment @send_environment end |
#session_endpoint ⇒ String
The URL session notifications will be delivered to
121 122 123 |
# File 'lib/bugsnag/configuration.rb', line 121 def session_endpoint @session_endpoint end |
#timeout ⇒ Integer
The HTTP request timeout, defaults to 15 seconds
92 93 94 |
# File 'lib/bugsnag/configuration.rb', line 92 def timeout @timeout end |
#vendor_path ⇒ Regexp
142 143 144 |
# File 'lib/bugsnag/configuration.rb', line 142 def vendor_path @vendor_path end |
Instance Method Details
#add_on_error(callback) ⇒ void
This method returns an undefined value.
Add the given callback to the list of on_error callbacks
The on_error callbacks will be called when an error is captured or reported and are passed a Report object
Returning false from an on_error callback will cause the error to be ignored and will prevent any remaining callbacks from being called
490 491 492 |
# File 'lib/bugsnag/configuration.rb', line 490 def add_on_error(callback) middleware.use(callback) end |
#app_type ⇒ String?
Get the type of application executing the current code
This is usually used to represent if you are running in a Rails server, Sidekiq job, Rake task etc… Bugsnag will automatically detect most application types for you
288 289 290 |
# File 'lib/bugsnag/configuration.rb', line 288 def app_type @app_type || @detected_app_type end |
#app_type=(app_type) ⇒ void
This method returns an undefined value.
Set the type of application executing the current code
If an app_type is set, this will be used instead of the automatically detected app_type that Bugsnag would otherwise use
300 301 302 |
# File 'lib/bugsnag/configuration.rb', line 300 def app_type=(app_type) @app_type = app_type end |
#breadcrumbs ⇒ Bugsnag::Utility::CircularBuffer
Returns the breadcrumb circular buffer
432 433 434 |
# File 'lib/bugsnag/configuration.rb', line 432 def request_data[:breadcrumbs] ||= Bugsnag::Utility::CircularBuffer.new(@max_breadcrumbs) end |
#clear_request_data ⇒ void
This method returns an undefined value.
Clears the array of data attached to every error notification.
377 378 379 |
# File 'lib/bugsnag/configuration.rb', line 377 def clear_request_data Thread.current[THREAD_LOCAL_NAME] = nil end |
#debug(message) ⇒ Object
Logs a debug level message
401 402 403 |
# File 'lib/bugsnag/configuration.rb', line 401 def debug() logger.debug(PROG_NAME) { } end |
#delivery_method ⇒ Symbol
Gets the delivery_method that Bugsnag will use to communicate with the notification endpoint.
252 253 254 |
# File 'lib/bugsnag/configuration.rb', line 252 def delivery_method @delivery_method || @default_delivery_method || :thread_queue end |
#delivery_method=(delivery_method) ⇒ void
This method returns an undefined value.
Sets the delivery_method that Bugsnag will use to communicate with the notification endpoint.
The default delivery methods are ‘:thread_queue’ and ‘:synchronous’.
264 265 266 |
# File 'lib/bugsnag/configuration.rb', line 264 def delivery_method=(delivery_method) @delivery_method = delivery_method end |
#disable_sessions ⇒ void
This method returns an undefined value.
Disables session tracking and delivery. Cannot be undone
474 475 476 477 |
# File 'lib/bugsnag/configuration.rb', line 474 def disable_sessions self.auto_capture_sessions = false @enable_sessions = false end |
#endpoint=(new_notify_endpoint) ⇒ void
Use #set_endpoints instead
This method returns an undefined value.
Sets the notification endpoint
442 443 444 445 |
# File 'lib/bugsnag/configuration.rb', line 442 def endpoint=(new_notify_endpoint) warn("The 'endpoint' configuration option is deprecated. The 'set_endpoints' method should be used instead") set_endpoints(new_notify_endpoint, session_endpoint) # Pass the existing session_endpoint through so it doesn't get overwritten end |
#info(message) ⇒ Object
Logs an info level message
385 386 387 |
# File 'lib/bugsnag/configuration.rb', line 385 def info() logger.info(PROG_NAME) { } end |
#parse_proxy(uri) ⇒ void
This method returns an undefined value.
Parses and sets proxy from a uri
410 411 412 413 414 415 416 |
# File 'lib/bugsnag/configuration.rb', line 410 def parse_proxy(uri) proxy = URI.parse(uri) self.proxy_host = proxy.host self.proxy_port = proxy.port self.proxy_user = proxy.user self.proxy_password = proxy.password end |
#remove_on_error(callback) ⇒ void
This method returns an undefined value.
Remove the given callback from the list of on_error callbacks
Note that this must be the same Proc instance that was passed to #add_on_error, otherwise it will not be removed
502 503 504 |
# File 'lib/bugsnag/configuration.rb', line 502 def remove_on_error(callback) middleware.remove(callback) end |
#request_data ⇒ Hash
Returns the array of data that will be automatically attached to every error notification.
350 351 352 |
# File 'lib/bugsnag/configuration.rb', line 350 def request_data Thread.current[THREAD_LOCAL_NAME] ||= {} end |
#set_endpoints(new_notify_endpoint, new_session_endpoint) ⇒ void
This method returns an undefined value.
Sets the notification and session endpoints
465 466 467 468 |
# File 'lib/bugsnag/configuration.rb', line 465 def set_endpoints(new_notify_endpoint, new_session_endpoint) @notify_endpoint = new_notify_endpoint @session_endpoint = new_session_endpoint end |
#set_request_data(key, value) ⇒ void
This method returns an undefined value.
Sets an entry in the array of data attached to every error notification.
360 361 362 |
# File 'lib/bugsnag/configuration.rb', line 360 def set_request_data(key, value) self.request_data[key] = value end |
#should_notify_release_stage? ⇒ Boolean
Indicates whether the notifier should send a notification based on the configured release stage.
333 334 335 |
# File 'lib/bugsnag/configuration.rb', line 333 def should_notify_release_stage? @release_stage.nil? || @notify_release_stages.nil? || @notify_release_stages.include?(@release_stage) end |
#unset_request_data(key, value) ⇒ void
This method returns an undefined value.
Unsets an entry in the array of data attached to every error notification.
369 370 371 |
# File 'lib/bugsnag/configuration.rb', line 369 def unset_request_data(key, value) self.request_data.delete(key) end |
#valid_api_key? ⇒ Boolean
Tests whether the configured API key is valid.
341 342 343 |
# File 'lib/bugsnag/configuration.rb', line 341 def valid_api_key? !api_key.nil? && api_key =~ API_KEY_REGEX end |
#warn(message) ⇒ Object
Logs a warning level message
393 394 395 |
# File 'lib/bugsnag/configuration.rb', line 393 def warn() logger.warn(PROG_NAME) { } end |