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_ENDPOINT =
"https://notify.bugsnag.com"
DEFAULT_SESSION_ENDPOINT =
"https://sessions.bugsnag.com"
DEFAULT_META_DATA_FILTERS =
[
  /authorization/i,
  /cookie/i,
  /password/i,
  /secret/i,
  /warden\.user\.([^.]+)\.key/,
  "rack.request.form_vars"
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bugsnag/configuration.rb', line 57

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.endpoint = DEFAULT_ENDPOINT
  self.hostname = default_hostname
  self.timeout = 15
  self.notify_release_stages = nil
  self.auto_capture_sessions = false
  self.session_endpoint = DEFAULT_SESSION_ENDPOINT

  # SystemExit and Interrupt are common Exception types seen with successful
  # exits and are not automatically reported to Bugsnag
  self.ignore_classes = Set.new([SystemExit, Interrupt])

  # 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 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.middleware = Bugsnag::MiddlewareStack.new
  self.middleware.use Bugsnag::Middleware::Callbacks
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



14
15
16
# File 'lib/bugsnag/configuration.rb', line 14

def api_key
  @api_key
end

#app_typeObject

Returns the value of attribute app_type.



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

def app_type
  @app_type
end

#app_versionObject

Returns the value of attribute app_version.



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

def app_version
  @app_version
end

#auto_capture_sessionsObject Also known as: track_sessions

Returns the value of attribute auto_capture_sessions.



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

def auto_capture_sessions
  @auto_capture_sessions
end

#auto_notifyObject

Returns the value of attribute auto_notify.



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

def auto_notify
  @auto_notify
end

#ca_fileObject

Returns the value of attribute ca_file.



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

def ca_file
  @ca_file
end

#endpointObject

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

#hostnameObject

Returns the value of attribute hostname.



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

def hostname
  @hostname
end

#ignore_classesObject

Returns the value of attribute ignore_classes.



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

def ignore_classes
  @ignore_classes
end

#internal_middlewareObject

Returns the value of attribute internal_middleware.



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

def internal_middleware
  @internal_middleware
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#meta_data_filtersObject

Returns the value of attribute meta_data_filters.



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

def 
  @meta_data_filters
end

#middlewareObject

Returns the value of attribute middleware.



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

def middleware
  @middleware
end

#notify_release_stagesObject

Returns the value of attribute notify_release_stages.



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

def notify_release_stages
  @notify_release_stages
end

#project_rootObject

Returns the value of attribute project_root.



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

def project_root
  @project_root
end

#proxy_hostObject

Returns the value of attribute proxy_host.



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

def proxy_host
  @proxy_host
end

#proxy_passwordObject

Returns the value of attribute proxy_password.



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

def proxy_password
  @proxy_password
end

#proxy_portObject

Returns the value of attribute proxy_port.



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

def proxy_port
  @proxy_port
end

#proxy_userObject

Returns the value of attribute proxy_user.



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

def proxy_user
  @proxy_user
end

#release_stageObject

Returns the value of attribute release_stage.



15
16
17
# File 'lib/bugsnag/configuration.rb', line 15

def release_stage
  @release_stage
end

#send_codeObject

Returns the value of attribute send_code.



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

def send_code
  @send_code
end

#send_environmentObject

Returns the value of attribute send_environment.



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

def send_environment
  @send_environment
end

#session_endpointObject

Returns the value of attribute session_endpoint.



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

def session_endpoint
  @session_endpoint
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

Instance Method Details

#clear_request_dataObject

Clears the array of data attached to every error notification.



161
162
163
# File 'lib/bugsnag/configuration.rb', line 161

def clear_request_data
  Thread.current[THREAD_LOCAL_NAME] = nil
end

#debug(message) ⇒ Object

Logs a debug level message



179
180
181
# File 'lib/bugsnag/configuration.rb', line 179

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.



123
124
125
# File 'lib/bugsnag/configuration.rb', line 123

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.



107
108
109
# File 'lib/bugsnag/configuration.rb', line 107

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.



115
116
117
# File 'lib/bugsnag/configuration.rb', line 115

def delivery_method=(delivery_method)
  @delivery_method = delivery_method
end

#info(message) ⇒ Object

Logs an info level message



167
168
169
# File 'lib/bugsnag/configuration.rb', line 167

def info(message)
  logger.info(PROG_NAME) { message }
end

#parse_proxy(uri) ⇒ Object

Parses and sets proxy from a uri



185
186
187
188
189
190
191
# File 'lib/bugsnag/configuration.rb', line 185

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.



143
144
145
# File 'lib/bugsnag/configuration.rb', line 143

def request_data
  Thread.current[THREAD_LOCAL_NAME] ||= {}
end

#set_request_data(key, value) ⇒ Object

Sets an entry in the array of data attached to every error notification.



149
150
151
# File 'lib/bugsnag/configuration.rb', line 149

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)


130
131
132
# File 'lib/bugsnag/configuration.rb', line 130

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.



155
156
157
# File 'lib/bugsnag/configuration.rb', line 155

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)


136
137
138
# File 'lib/bugsnag/configuration.rb', line 136

def valid_api_key?
  !api_key.nil? && api_key =~ API_KEY_REGEX
end

#warn(message) ⇒ Object

Logs a warning level message



173
174
175
# File 'lib/bugsnag/configuration.rb', line 173

def warn(message)
  logger.warn(PROG_NAME) { message }
end