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 ⇒ Object
Returns the value of attribute api_key.
-
#app_type ⇒ Object
Returns the value of attribute app_type.
-
#app_version ⇒ Object
Returns the value of attribute app_version.
-
#auto_capture_sessions ⇒ Object
(also: #track_sessions)
Returns the value of attribute auto_capture_sessions.
-
#auto_notify ⇒ Object
Returns the value of attribute auto_notify.
-
#before_breadcrumb_callbacks ⇒ Array<#call>
Callables to be run before a breadcrumb is logged.
-
#ca_file ⇒ Object
Returns the value of attribute ca_file.
-
#enable_sessions ⇒ Boolean
readonly
Whether any sessions types will be delivered.
-
#enabled_automatic_breadcrumb_types ⇒ Array<String>
Strings indicating allowable automatic breadcrumb types.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#ignore_classes ⇒ Object
Returns the value of attribute ignore_classes.
-
#internal_middleware ⇒ Object
Returns the value of attribute internal_middleware.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_breadcrumbs ⇒ Integer
The maximum allowable amount of breadcrumbs per thread.
-
#meta_data_filters ⇒ Object
Returns the value of attribute meta_data_filters.
-
#middleware ⇒ Object
Returns the value of attribute middleware.
-
#notify_endpoint ⇒ String
(also: #endpoint)
readonly
URL error notifications will be delivered to.
-
#notify_release_stages ⇒ Object
Returns the value of attribute notify_release_stages.
-
#project_root ⇒ Object
Returns the value of attribute project_root.
-
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
-
#proxy_password ⇒ Object
Returns the value of attribute proxy_password.
-
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
-
#release_stage ⇒ Object
Returns the value of attribute release_stage.
-
#runtime_versions ⇒ Object
Returns the value of attribute runtime_versions.
-
#send_code ⇒ Object
Returns the value of attribute send_code.
-
#send_environment ⇒ Object
Returns the value of attribute send_environment.
-
#session_endpoint ⇒ String
URL session notifications will be delivered to.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#vendor_path ⇒ Regexp
Matching file paths out of project.
Instance Method Summary collapse
-
#breadcrumbs ⇒ Bugsnag::Utility::CircularBuffer
Returns the breadcrumb circular buffer.
-
#clear_request_data ⇒ Object
Clears the array of data attached to every error notification.
-
#debug(message) ⇒ Object
Logs a debug level message.
-
#default_delivery_method=(delivery_method) ⇒ Object
Used to set a new default delivery method that will be used if one is not set with #delivery_method.
-
#delivery_method ⇒ Object
Gets the delivery_method that Bugsnag will use to communicate with the notification endpoint.
-
#delivery_method=(delivery_method) ⇒ Object
Sets the delivery_method that Bugsnag will use to communicate with the notification endpoint.
-
#disable_sessions ⇒ Object
Disables session tracking and delivery.
-
#endpoint=(new_notify_endpoint) ⇒ Object
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) ⇒ Object
Parses and sets proxy from a uri.
-
#request_data ⇒ Object
Returns the array of data that will be automatically attached to every error notification.
-
#set_endpoints(new_notify_endpoint, new_session_endpoint) ⇒ Object
Sets the notification and session endpoints.
-
#set_request_data(key, value) ⇒ Object
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) ⇒ Object
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.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/bugsnag/configuration.rb', line 94 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.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.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 self.ignore_classes = Set.new([SystemExit, SignalException]) # 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::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 ⇒ Object
Returns the value of attribute api_key.
17 18 19 |
# File 'lib/bugsnag/configuration.rb', line 17 def api_key @api_key end |
#app_type ⇒ Object
Returns the value of attribute app_type.
26 27 28 |
# File 'lib/bugsnag/configuration.rb', line 26 def app_type @app_type end |
#app_version ⇒ Object
Returns the value of attribute app_version.
25 26 27 |
# File 'lib/bugsnag/configuration.rb', line 25 def app_version @app_version end |
#auto_capture_sessions ⇒ Object Also known as: track_sessions
Returns the value of attribute auto_capture_sessions.
39 40 41 |
# File 'lib/bugsnag/configuration.rb', line 39 def auto_capture_sessions @auto_capture_sessions end |
#auto_notify ⇒ Object
Returns the value of attribute auto_notify.
20 21 22 |
# File 'lib/bugsnag/configuration.rb', line 20 def auto_notify @auto_notify end |
#before_breadcrumb_callbacks ⇒ Array<#call>
Returns callables to be run before a breadcrumb is logged.
60 61 62 |
# File 'lib/bugsnag/configuration.rb', line 60 def @before_breadcrumb_callbacks end |
#ca_file ⇒ Object
Returns the value of attribute ca_file.
21 22 23 |
# File 'lib/bugsnag/configuration.rb', line 21 def ca_file @ca_file end |
#enable_sessions ⇒ Boolean (readonly)
Returns whether any sessions types will be delivered.
52 53 54 |
# File 'lib/bugsnag/configuration.rb', line 52 def enable_sessions @enable_sessions end |
#enabled_automatic_breadcrumb_types ⇒ Array<String>
Returns strings indicating allowable automatic breadcrumb types.
56 57 58 |
# File 'lib/bugsnag/configuration.rb', line 56 def @enabled_automatic_breadcrumb_types end |
#hostname ⇒ Object
Returns the value of attribute hostname.
36 37 38 |
# File 'lib/bugsnag/configuration.rb', line 36 def hostname @hostname end |
#ignore_classes ⇒ Object
Returns the value of attribute ignore_classes.
38 39 40 |
# File 'lib/bugsnag/configuration.rb', line 38 def ignore_classes @ignore_classes end |
#internal_middleware ⇒ Object
Returns the value of attribute internal_middleware.
30 31 32 |
# File 'lib/bugsnag/configuration.rb', line 30 def internal_middleware @internal_middleware end |
#logger ⇒ Object
Returns the value of attribute logger.
28 29 30 |
# File 'lib/bugsnag/configuration.rb', line 28 def logger @logger end |
#max_breadcrumbs ⇒ Integer
Returns the maximum allowable amount of breadcrumbs per thread.
64 65 66 |
# File 'lib/bugsnag/configuration.rb', line 64 def @max_breadcrumbs end |
#meta_data_filters ⇒ Object
Returns the value of attribute meta_data_filters.
27 28 29 |
# File 'lib/bugsnag/configuration.rb', line 27 def @meta_data_filters end |
#middleware ⇒ Object
Returns the value of attribute middleware.
29 30 31 |
# File 'lib/bugsnag/configuration.rb', line 29 def middleware @middleware end |
#notify_endpoint ⇒ String (readonly) Also known as: endpoint
Returns URL error notifications will be delivered to.
43 44 45 |
# File 'lib/bugsnag/configuration.rb', line 43 def notify_endpoint @notify_endpoint end |
#notify_release_stages ⇒ Object
Returns the value of attribute notify_release_stages.
19 20 21 |
# File 'lib/bugsnag/configuration.rb', line 19 def notify_release_stages @notify_release_stages end |
#project_root ⇒ Object
Returns the value of attribute project_root.
24 25 26 |
# File 'lib/bugsnag/configuration.rb', line 24 def project_root @project_root end |
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
31 32 33 |
# File 'lib/bugsnag/configuration.rb', line 31 def proxy_host @proxy_host end |
#proxy_password ⇒ Object
Returns the value of attribute proxy_password.
34 35 36 |
# File 'lib/bugsnag/configuration.rb', line 34 def proxy_password @proxy_password end |
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
32 33 34 |
# File 'lib/bugsnag/configuration.rb', line 32 def proxy_port @proxy_port end |
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
33 34 35 |
# File 'lib/bugsnag/configuration.rb', line 33 def proxy_user @proxy_user end |
#release_stage ⇒ Object
Returns the value of attribute release_stage.
18 19 20 |
# File 'lib/bugsnag/configuration.rb', line 18 def release_stage @release_stage end |
#runtime_versions ⇒ Object
Returns the value of attribute runtime_versions.
37 38 39 |
# File 'lib/bugsnag/configuration.rb', line 37 def runtime_versions @runtime_versions end |
#send_code ⇒ Object
Returns the value of attribute send_code.
23 24 25 |
# File 'lib/bugsnag/configuration.rb', line 23 def send_code @send_code end |
#send_environment ⇒ Object
Returns the value of attribute send_environment.
22 23 24 |
# File 'lib/bugsnag/configuration.rb', line 22 def send_environment @send_environment end |
#session_endpoint ⇒ String
Returns URL session notifications will be delivered to.
48 49 50 |
# File 'lib/bugsnag/configuration.rb', line 48 def session_endpoint @session_endpoint end |
#timeout ⇒ Object
Returns the value of attribute timeout.
35 36 37 |
# File 'lib/bugsnag/configuration.rb', line 35 def timeout @timeout end |
#vendor_path ⇒ Regexp
Returns matching file paths out of project.
68 69 70 |
# File 'lib/bugsnag/configuration.rb', line 68 def vendor_path @vendor_path end |
Instance Method Details
#breadcrumbs ⇒ Bugsnag::Utility::CircularBuffer
Returns the breadcrumb circular buffer
263 264 265 |
# File 'lib/bugsnag/configuration.rb', line 263 def request_data[:breadcrumbs] ||= Bugsnag::Utility::CircularBuffer.new(@max_breadcrumbs) end |
#clear_request_data ⇒ Object
Clears the array of data attached to every error notification.
218 219 220 |
# File 'lib/bugsnag/configuration.rb', line 218 def clear_request_data Thread.current[THREAD_LOCAL_NAME] = nil end |
#debug(message) ⇒ Object
Logs a debug level message
236 237 238 |
# File 'lib/bugsnag/configuration.rb', line 236 def debug() logger.debug(PROG_NAME) { } end |
#default_delivery_method=(delivery_method) ⇒ Object
Used to set a new default delivery method that will be used if one is not set with #delivery_method.
180 181 182 |
# File 'lib/bugsnag/configuration.rb', line 180 def default_delivery_method=(delivery_method) @default_delivery_method = delivery_method end |
#delivery_method ⇒ Object
Gets the delivery_method that Bugsnag will use to communicate with the notification endpoint.
164 165 166 |
# File 'lib/bugsnag/configuration.rb', line 164 def delivery_method @delivery_method || @default_delivery_method || :thread_queue end |
#delivery_method=(delivery_method) ⇒ Object
Sets the delivery_method that Bugsnag will use to communicate with the notification endpoint.
172 173 174 |
# File 'lib/bugsnag/configuration.rb', line 172 def delivery_method=(delivery_method) @delivery_method = delivery_method end |
#disable_sessions ⇒ Object
Disables session tracking and delivery. Cannot be undone
300 301 302 303 |
# File 'lib/bugsnag/configuration.rb', line 300 def disable_sessions self.auto_capture_sessions = false @enable_sessions = false end |
#endpoint=(new_notify_endpoint) ⇒ Object
Use #set_endpoints instead
Sets the notification endpoint
272 273 274 275 |
# File 'lib/bugsnag/configuration.rb', line 272 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
224 225 226 |
# File 'lib/bugsnag/configuration.rb', line 224 def info() logger.info(PROG_NAME) { } end |
#parse_proxy(uri) ⇒ Object
Parses and sets proxy from a uri
242 243 244 245 246 247 248 |
# File 'lib/bugsnag/configuration.rb', line 242 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 |
#request_data ⇒ Object
Returns the array of data that will be automatically attached to every error notification.
200 201 202 |
# File 'lib/bugsnag/configuration.rb', line 200 def request_data Thread.current[THREAD_LOCAL_NAME] ||= {} end |
#set_endpoints(new_notify_endpoint, new_session_endpoint) ⇒ Object
Sets the notification and session endpoints
293 294 295 296 |
# File 'lib/bugsnag/configuration.rb', line 293 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) ⇒ Object
Sets an entry in the array of data attached to every error notification.
206 207 208 |
# File 'lib/bugsnag/configuration.rb', line 206 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.
187 188 189 |
# File 'lib/bugsnag/configuration.rb', line 187 def should_notify_release_stage? @release_stage.nil? || @notify_release_stages.nil? || @notify_release_stages.include?(@release_stage) end |
#unset_request_data(key, value) ⇒ Object
Unsets an entry in the array of data attached to every error notification.
212 213 214 |
# File 'lib/bugsnag/configuration.rb', line 212 def unset_request_data(key, value) self.request_data.delete(key) end |
#valid_api_key? ⇒ Boolean
Tests whether the configured API key is valid.
193 194 195 |
# File 'lib/bugsnag/configuration.rb', line 193 def valid_api_key? !api_key.nil? && api_key =~ API_KEY_REGEX end |
#warn(message) ⇒ Object
Logs a warning level message
230 231 232 |
# File 'lib/bugsnag/configuration.rb', line 230 def warn() logger.warn(PROG_NAME) { } end |