class Bugsnag::Configuration
Constants
- API_KEY_REGEX
- DEFAULT_ENDPOINT
- DEFAULT_MAX_BREADCRUMBS
- DEFAULT_META_DATA_FILTERS
- DEFAULT_NOTIFY_ENDPOINT
- DEFAULT_SCOPES_TO_FILTER
@api private
- DEFAULT_SESSION_ENDPOINT
- DEFAULT_VENDOR_PATH
Path to vendored code. Used to mark file paths as out of project.
- PROG_NAME
- THREAD_LOCAL_NAME
Attributes
Your Integration API Key @return [String, nil]
The current version of your application @return [String, nil]
Whether Bugsnag
should automatically record sessions @deprecated Use {#auto_track_sessions} instead @return [Boolean]
Whether notifications should automatically be sent @return [Boolean]
@return [String, nil]
The default context for all future events Setting this will disable automatic context setting @return [String, nil]
Exception classes that will be discarded and not sent to Bugsnag
@return [Set<String, Regexp>]
Whether events will be delivered @api private @return [Boolean]
Whether sessions will be delivered @api private @return [Boolean]
The URLs to send events and sessions to @return [EndpointConfiguration]
The name or descriptor of the Ruby server host @return [String]
@deprecated Use {#discard_classes} instead @return [Set<Class, Proc>]
@api private @return [MiddlewareStack]
The logger to use for Bugsnag
log messages @return [Logger]
A list of keys that should be filtered out from the report and breadcrumb metadata before sending them to Bugsnag
@deprecated Use {#redacted_keys} instead @return [Set<String, Regexp>]
Global metadata added to every event @return [Hash]
The middleware stack that will run on every notification @return [MiddlewareStack]
A list of which release stages should cause notifications to be sent @deprecated Use {#enabled_release_stages} instead @return [Array<String>, nil]
Any stacktrace lines that match this path will be marked as ‘in project’ @return [String, nil]
The host address of the HTTP proxy that should be used when making requests @see parse_proxy
@return [String, nil]
The password for the user that should be used when making requests via a HTTP proxy @see parse_proxy
@return [String, nil]
The port number of the HTTP proxy that should be used when making requests @see parse_proxy
@return [Integer, nil]
The user that should be used when making requests via a HTTP proxy @see parse_proxy
@return [String, nil]
A set of keys that should be redacted from the report and breadcrumb metadata before sending them to Bugsnag
When adding strings, keys that are equal to the string (ignoring case) will be redacted. When adding regular expressions, any keys which match the regular expression will be redacted
@return [Set<String, Regexp>]
The current stage of the release process, e.g. ‘development’, production’ @return [String, nil]
@api private @return [Hash{String => String}]
@api private @return [Array<String>]
Whether code snippets from the exception stacktrace should be sent with notifications @return [Boolean]
Whether to automatically attach the Rack
environment to notifications @return [Boolean]
The HTTP request timeout, defaults to 15 seconds @return [Integer]
Whether Bugsnag
should automatically record sessions @deprecated Use {#auto_track_sessions} instead @return [Boolean]
Whether Bugsnag
should automatically record sessions @deprecated Use {#auto_track_sessions} instead @return [Boolean]
@deprecated Use {vendor_paths} instead @return [Regexp]
An array of paths within the {project_root} that should not be considered as “in project”
These paths should be relative to the {project_root} and will only match whole directory names
@return [Array<String>]
Public Class Methods
# File lib/bugsnag/configuration.rb, line 224 def initialize @mutex = Mutex.new # Set up the defaults self.auto_notify = true self.send_environment = false self.send_code = true self.meta_data_filters = Set.new(DEFAULT_META_DATA_FILTERS) @redacted_keys = Set.new 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.enabled_automatic_breadcrumb_types = Bugsnag::Breadcrumbs::VALID_BREADCRUMB_TYPES.dup self.before_breadcrumb_callbacks = [] @on_breadcrumb_callbacks = Breadcrumbs::OnBreadcrumbCallbackList.new(self) # Store max_breadcrumbs here instead of outputting breadcrumbs.max_items # to avoid infinite recursion when creating breadcrumb buffer @max_breadcrumbs = DEFAULT_MAX_BREADCRUMBS @endpoints = EndpointConfiguration.new(DEFAULT_NOTIFY_ENDPOINT, DEFAULT_SESSION_ENDPOINT) @enable_events = true @enable_sessions = true @metadata = {} @metadata_delegate = Utility::MetadataDelegate.new # 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 @vendor_paths = [] # 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
Public Instance Methods
Add values to metadata
@overload add_metadata
(section, data)
Merges data into the given section of metadata @param section [String, Symbol] @param data [Hash]
@overload add_metadata
(section, key, value)
Sets key to value in the given section of metadata. If the value is nil the key will be deleted @param section [String, Symbol] @param key [String, Symbol] @param value
@return [void]
# File lib/bugsnag/configuration.rb, line 664 def add_metadata(section, key_or_data, *args) @mutex.synchronize do @metadata_delegate.add_metadata(@metadata, section, key_or_data, *args) end end
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 {Bugsnag::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
@param callback [Proc, Method, call] @return [void]
# File lib/bugsnag/configuration.rb, line 605 def add_on_error(callback) middleware.use(callback) end
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
@return [String, nil]
# File lib/bugsnag/configuration.rb, line 343 def app_type @app_type || @detected_app_type end
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
@param app_type
[String] @return [void]
# File lib/bugsnag/configuration.rb, line 355 def app_type=(app_type) @app_type = app_type end
Whether sessions should be tracked automatically @!attribute auto_track_sessions
@return [Boolean]
# File lib/bugsnag/configuration.rb, line 736 def auto_track_sessions @auto_capture_sessions end
@param track_sessions
[Boolean] @return [void]
# File lib/bugsnag/configuration.rb, line 742 def auto_track_sessions=(track_sessions) @auto_capture_sessions = track_sessions end
Clear values from metadata
@overload clear_metadata
(section)
Clears the given section of metadata @param section [String, Symbol]
@overload clear_metadata
(section, key)
Clears the key in the given section of metadata @param section [String, Symbol] @param key [String, Symbol]
@return [void]
# File lib/bugsnag/configuration.rb, line 683 def clear_metadata(section, *args) @mutex.synchronize do @metadata_delegate.clear_metadata(@metadata, section, *args) end end
Clears the array of data attached to every error notification.
@return [void]
# File lib/bugsnag/configuration.rb, line 432 def clear_request_data Thread.current[THREAD_LOCAL_NAME] = nil end
Has the context been explicitly set?
This is necessary to differentiate between the context not being set and the context being set to ‘nil’ explicitly
@api private @return [Boolean]
# File lib/bugsnag/configuration.rb, line 697 def context_set? defined?(@context) != nil end
Logs a debug level message
@param message [String, to_s] The message to log
# File lib/bugsnag/configuration.rb, line 464 def debug(message) logger.debug(PROG_NAME) { message } end
Used to set a new default delivery method that will be used if one is not set with delivery_method
.
@api private
@param delivery_method
[Symbol] @return [void]
# File lib/bugsnag/configuration.rb, line 331 def default_delivery_method=(delivery_method) @default_delivery_method = delivery_method end
Gets the delivery_method
that Bugsnag
will use to communicate with the notification endpoint.
@return [Symbol]
# File lib/bugsnag/configuration.rb, line 307 def delivery_method @delivery_method || @default_delivery_method || :thread_queue end
Sets the delivery_method
that Bugsnag
will use to communicate with the notification endpoint.
The default delivery methods are ‘:thread_queue’ and ‘:synchronous’.
@param delivery_method
[Symbol] @return [void]
# File lib/bugsnag/configuration.rb, line 319 def delivery_method=(delivery_method) @delivery_method = delivery_method end
Get the detected app_type
, which is used when one isn’t set explicitly
@api private
@return [String, nil]
# File lib/bugsnag/configuration.rb, line 365 def detected_app_type @detected_app_type end
Set the detected app_type
, which is used when one isn’t set explicitly
This allows Bugsnag’s integrations to say ‘this is a Rails
app’ while allowing the user to overwrite this if they wish
@api private
@param app_type
[String] @return [void]
# File lib/bugsnag/configuration.rb, line 379 def detected_app_type=(app_type) @detected_app_type = app_type end
Disables session tracking and delivery. Cannot be undone
@return [void]
# File lib/bugsnag/configuration.rb, line 575 def disable_sessions self.auto_capture_sessions = false @enable_sessions = false end
A list of which release stages should cause notifications to be sent @!attribute enabled_release_stages
@return [Array<String>, nil]
# File lib/bugsnag/configuration.rb, line 709 def enabled_release_stages @notify_release_stages end
@param release_stages [Array<String>, nil] @return [void]
# File lib/bugsnag/configuration.rb, line 715 def enabled_release_stages=(release_stages) @notify_release_stages = release_stages end
Sets the notification endpoint
@deprecated Use {#endpoints} instead
@param new_notify_endpoint [String] The URL to deliver error notifications to @return [void]
# File lib/bugsnag/configuration.rb, line 518 def endpoint=(new_notify_endpoint) warn("The 'endpoint' configuration option is deprecated. Set both endpoints with the 'endpoints=' method instead") set_endpoints(new_notify_endpoint, session_endpoint) # Pass the existing session_endpoint through so it doesn't get overwritten end
# File lib/bugsnag/configuration.rb, line 554 def endpoints=(endpoint_configuration) result = EndpointValidator.validate(endpoint_configuration) if result.valid? @enable_events = true @enable_sessions = true else warn(result.reason) @enable_events = result.keep_events_enabled_for_backwards_compatibility? @enable_sessions = false end # use the given endpoints even if they are invalid @endpoints = endpoint_configuration end
Logs an error level message
@param message [String, to_s] The message to log
# File lib/bugsnag/configuration.rb, line 456 def error(message) logger.error(PROG_NAME) { message } end
Logs an info level message
@param message [String, to_s] The message to log
# File lib/bugsnag/configuration.rb, line 440 def info(message) logger.info(PROG_NAME) { message } end
The URL error notifications will be delivered to @!attribute notify_endpoint
@return [String] @deprecated Use {#endpoints} instead
# File lib/bugsnag/configuration.rb, line 506 def notify_endpoint @endpoints.notify end
Add the given block 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 {Bugsnag::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
@return [void]
# File lib/bugsnag/configuration.rb, line 590 def on_error(&block) middleware.use(block) end
Parses and sets proxy from a uri
@param uri [String, to_s] The URI to parse and extract proxy details from @return [void]
# File lib/bugsnag/configuration.rb, line 473 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 the given callback from the list of on_error
callbacks
Note that this must be the same instance that was passed to {#add_on_error}, otherwise it will not be removed
@param callback [Proc, Method, call] @return [void]
# File lib/bugsnag/configuration.rb, line 617 def remove_on_error(callback) middleware.remove(callback) end
Returns the array of data that will be automatically attached to every error notification.
@return [Hash]
# File lib/bugsnag/configuration.rb, line 405 def request_data Thread.current[THREAD_LOCAL_NAME] ||= {} end
The URL session notifications will be delivered to @!attribute session_endpoint
@return [String] @deprecated Use {#endpoints} instead
# File lib/bugsnag/configuration.rb, line 527 def session_endpoint @endpoints.sessions end
Sets the sessions endpoint
@deprecated Use {#endpoints} instead
@param new_session_endpoint [String] The URL to deliver session notifications to @return [void]
# File lib/bugsnag/configuration.rb, line 538 def session_endpoint=(new_session_endpoint) warn("The 'session_endpoint' configuration option is deprecated. Set both endpoints with the 'endpoints=' method instead") set_endpoints(notify_endpoint, new_session_endpoint) # Pass the existing notify_endpoint through so it doesn't get overwritten end
Sets the notification and session endpoints
@param new_notify_endpoint [String] The URL to deliver error notifications to @param new_session_endpoint [String] The URL to deliver session notifications to @return [void] @deprecated Use {#endpoints} instead
# File lib/bugsnag/configuration.rb, line 550 def set_endpoints(new_notify_endpoint, new_session_endpoint) self.endpoints = EndpointConfiguration.new(new_notify_endpoint, new_session_endpoint) end
Sets an entry in the array of data attached to every error notification.
@param key [String, to_s] @param value [Object] @return [void]
# File lib/bugsnag/configuration.rb, line 415 def set_request_data(key, value) self.request_data[key] = value end
Indicates whether the notifier should send a notification based on the configured release stage.
@return [Boolean]
# File lib/bugsnag/configuration.rb, line 388 def should_notify_release_stage? @release_stage.nil? || @notify_release_stages.nil? || @notify_release_stages.include?(@release_stage) end
Unsets an entry in the array of data attached to every error notification.
@param (see set_request_data
) @return [void]
# File lib/bugsnag/configuration.rb, line 424 def unset_request_data(key, value) self.request_data.delete(key) end
Tests whether the configured API key is valid.
@return [Boolean]
# File lib/bugsnag/configuration.rb, line 396 def valid_api_key? !api_key.nil? && api_key =~ API_KEY_REGEX end
Logs a warning level message
@param message [String, to_s] The message to log
# File lib/bugsnag/configuration.rb, line 448 def warn(message) logger.warn(PROG_NAME) { message } end
Private Instance Methods
# File lib/bugsnag/configuration.rb, line 752 def default_hostname # Send the heroku dyno name instead of hostname if available ENV["DYNO"] || Socket.gethostname; end