Class: Bugsnag::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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.enabled_automatic_breadcrumb_types = Bugsnag::Breadcrumbs::VALID_BREADCRUMB_TYPES.dup
  self.before_breadcrumb_callbacks = []

  # 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_keyObject

Returns the value of attribute api_key.



17
18
19
# File 'lib/bugsnag/configuration.rb', line 17

def api_key
  @api_key
end

#app_typeObject

Returns the value of attribute app_type.



26
27
28
# File 'lib/bugsnag/configuration.rb', line 26

def app_type
  @app_type
end

#app_versionObject

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_sessionsObject 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_notifyObject

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_callbacksArray<#call>

Returns callables to be run before a breadcrumb is logged.

Returns:

  • (Array<#call>)

    callables to be run before a breadcrumb is logged



60
61
62
# File 'lib/bugsnag/configuration.rb', line 60

def before_breadcrumb_callbacks
  @before_breadcrumb_callbacks
end

#ca_fileObject

Returns the value of attribute ca_file.



21
22
23
# File 'lib/bugsnag/configuration.rb', line 21

def ca_file
  @ca_file
end

#enable_sessionsBoolean (readonly)

Returns whether any sessions types will be delivered.

Returns:

  • (Boolean)

    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_typesArray<String>

Returns strings indicating allowable automatic breadcrumb types.

Returns:

  • (Array<String>)

    strings indicating allowable automatic breadcrumb types



56
57
58
# File 'lib/bugsnag/configuration.rb', line 56

def enabled_automatic_breadcrumb_types
  @enabled_automatic_breadcrumb_types
end

#hostnameObject

Returns the value of attribute hostname.



36
37
38
# File 'lib/bugsnag/configuration.rb', line 36

def hostname
  @hostname
end

#ignore_classesObject

Returns the value of attribute ignore_classes.



38
39
40
# File 'lib/bugsnag/configuration.rb', line 38

def ignore_classes
  @ignore_classes
end

#internal_middlewareObject

Returns the value of attribute internal_middleware.



30
31
32
# File 'lib/bugsnag/configuration.rb', line 30

def internal_middleware
  @internal_middleware
end

#loggerObject

Returns the value of attribute logger.



28
29
30
# File 'lib/bugsnag/configuration.rb', line 28

def logger
  @logger
end

#max_breadcrumbsInteger

Returns the maximum allowable amount of breadcrumbs per thread.

Returns:

  • (Integer)

    the maximum allowable amount of breadcrumbs per thread



64
65
66
# File 'lib/bugsnag/configuration.rb', line 64

def max_breadcrumbs
  @max_breadcrumbs
end

#meta_data_filtersObject

Returns the value of attribute meta_data_filters.



27
28
29
# File 'lib/bugsnag/configuration.rb', line 27

def 
  @meta_data_filters
end

#middlewareObject

Returns the value of attribute middleware.



29
30
31
# File 'lib/bugsnag/configuration.rb', line 29

def middleware
  @middleware
end

#notify_endpointString (readonly) Also known as: endpoint

Returns URL error notifications will be delivered to.

Returns:

  • (String)

    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_stagesObject

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_rootObject

Returns the value of attribute project_root.



24
25
26
# File 'lib/bugsnag/configuration.rb', line 24

def project_root
  @project_root
end

#proxy_hostObject

Returns the value of attribute proxy_host.



31
32
33
# File 'lib/bugsnag/configuration.rb', line 31

def proxy_host
  @proxy_host
end

#proxy_passwordObject

Returns the value of attribute proxy_password.



34
35
36
# File 'lib/bugsnag/configuration.rb', line 34

def proxy_password
  @proxy_password
end

#proxy_portObject

Returns the value of attribute proxy_port.



32
33
34
# File 'lib/bugsnag/configuration.rb', line 32

def proxy_port
  @proxy_port
end

#proxy_userObject

Returns the value of attribute proxy_user.



33
34
35
# File 'lib/bugsnag/configuration.rb', line 33

def proxy_user
  @proxy_user
end

#release_stageObject

Returns the value of attribute release_stage.



18
19
20
# File 'lib/bugsnag/configuration.rb', line 18

def release_stage
  @release_stage
end

#runtime_versionsObject

Returns the value of attribute runtime_versions.



37
38
39
# File 'lib/bugsnag/configuration.rb', line 37

def runtime_versions
  @runtime_versions
end

#send_codeObject

Returns the value of attribute send_code.



23
24
25
# File 'lib/bugsnag/configuration.rb', line 23

def send_code
  @send_code
end

#send_environmentObject

Returns the value of attribute send_environment.



22
23
24
# File 'lib/bugsnag/configuration.rb', line 22

def send_environment
  @send_environment
end

#session_endpointString

Returns URL session notifications will be delivered to.

Returns:

  • (String)

    URL session notifications will be delivered to



48
49
50
# File 'lib/bugsnag/configuration.rb', line 48

def session_endpoint
  @session_endpoint
end

#timeoutObject

Returns the value of attribute timeout.



35
36
37
# File 'lib/bugsnag/configuration.rb', line 35

def timeout
  @timeout
end

#vendor_pathRegexp

Returns matching file paths out of project.

Returns:

  • (Regexp)

    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

Returns the breadcrumb circular buffer

Returns:



263
264
265
# File 'lib/bugsnag/configuration.rb', line 263

def breadcrumbs
  request_data[:breadcrumbs] ||= Bugsnag::Utility::CircularBuffer.new(@max_breadcrumbs)
end

#clear_request_dataObject

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(message)
  logger.debug(PROG_NAME) { message }
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_methodObject

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_sessionsObject

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

Deprecated.

Use #set_endpoints instead

Sets the notification endpoint

Parameters:

  • new_notify_endpoint (String)

    The URL to deliver error notifications to



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(message)
  logger.info(PROG_NAME) { message }
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_dataObject

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

Parameters:

  • new_notify_endpoint (String)

    The URL to deliver error notifications to

  • new_session_endpoint (String)

    The URL to deliver session notifications to



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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(message)
  logger.warn(PROG_NAME) { message }
end