Module: Bugsnag
- Extended by:
- Utility::FeatureDataStore
- Defined in:
- lib/bugsnag.rb,
lib/bugsnag/error.rb,
lib/bugsnag/event.rb,
lib/bugsnag/report.rb,
lib/bugsnag/cleaner.rb,
lib/bugsnag/helpers.rb,
lib/bugsnag/version.rb,
lib/bugsnag/delivery.rb,
lib/bugsnag/meta_data.rb,
lib/bugsnag/stacktrace.rb,
lib/bugsnag/feature_flag.rb,
lib/bugsnag/configuration.rb,
lib/bugsnag/code_extractor.rb,
lib/bugsnag/breadcrumb_type.rb,
lib/bugsnag/session_tracker.rb,
lib/bugsnag/middleware_stack.rb,
lib/bugsnag/integrations/rack.rb,
lib/bugsnag/integrations/rake.rb,
lib/bugsnag/endpoint_validator.rb,
lib/bugsnag/integrations/mongo.rb,
lib/bugsnag/on_error_callbacks.rb,
lib/bugsnag/integrations/resque.rb,
lib/bugsnag/delivery/synchronous.rb,
lib/bugsnag/integrations/mailman.rb,
lib/bugsnag/integrations/railtie.rb,
lib/bugsnag/integrations/sidekiq.rb,
lib/bugsnag/delivery/thread_queue.rb,
lib/bugsnag/endpoint_configuration.rb,
lib/bugsnag/integrations/shoryuken.rb
Overview
rubocop:todo Metrics/ModuleLength
Defined Under Namespace
Modules: BreadcrumbType, Breadcrumbs, Delivery, Helpers, MetaData, Middleware, Rails, RakeTask, Stacktrace, Utility Classes: Configuration, EndpointConfiguration, Error, FeatureFlag, Mailman, MiddlewareStack, Rack, Railtie, Report, Resque, SessionTracker, Shoryuken, Sidekiq
Constant Summary collapse
- LOCK =
Mutex.new
- INTEGRATIONS =
[:resque, :sidekiq, :mailman, :delayed_job, :shoryuken, :que, :mongo]
- NIL_EXCEPTION_DESCRIPTION =
"'nil' was notified as an exception"
- Event =
For now Event is just an alias of Report. This points to the same object so any changes to Report will also affect Event
Report
- VERSION =
File.read(File.join(File.dirname(__FILE__), "../../VERSION")).strip
Class Method Summary collapse
-
.add_feature_flag(name, variant = nil) ⇒ void
extended
from Utility::FeatureDataStore
Add a feature flag with the given name & variant.
-
.add_feature_flags(feature_flags) ⇒ void
extended
from Utility::FeatureDataStore
Merge the given array of FeatureFlag instances into the stored feature flags.
-
.add_metadata(section, key_or_data, *args) ⇒ void
Add values to metadata.
-
.add_on_breadcrumb(callback) ⇒ void
Add the given callback to the list of on_breadcrumb callbacks.
-
.add_on_error(callback) ⇒ void
Add the given callback to the list of on_error callbacks.
-
.at_exit_handler_installed? ⇒ Boolean
Checks if an at_exit handler has been added.
-
.before_notify_callbacks ⇒ Object
deprecated
Deprecated.
Use Bugsnag.add_on_error instead
-
.breadcrumbs ⇒ Bugsnag::Utility::CircularBuffer
Returns the current list of breadcrumbs.
-
.clear_feature_flag(name) ⇒ void
extended
from Utility::FeatureDataStore
Remove the stored flag with the given name.
-
.clear_feature_flags ⇒ void
extended
from Utility::FeatureDataStore
Remove all the stored flags.
-
.clear_metadata(section, *args) ⇒ void
Clear values from metadata.
-
.configuration ⇒ Configuration
Returns the client’s Configuration object, or creates one if not yet created.
-
.configure(validate_api_key = true) {|configuration| ... } ⇒ void
Configure the Bugsnag notifier application-wide settings.
-
.leave_breadcrumb(name, meta_data = {}, type = Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE, auto = :manual) ⇒ void
Leave a breadcrumb to be attached to subsequent reports.
-
.load_integration(integration) ⇒ void
Load a specific integration.
-
.load_integrations ⇒ void
Attempts to load all integrations through auto-discovery.
-
.metadata ⇒ Hash
Global metadata added to every event.
-
.notify(exception, auto_notify = false, &block) ⇒ Object
Explicitly notify of an exception.
-
.on_error(&block) ⇒ void
Add the given block to the list of on_error callbacks.
-
.pause_session ⇒ void
Stop any events being attributed to the current session until it is resumed or a new session is started.
-
.register_at_exit ⇒ void
Registers an at_exit function to automatically catch errors on exit.
-
.remove_on_breadcrumb(callback) ⇒ void
Remove the given callback from the list of on_breadcrumb callbacks.
-
.remove_on_error(callback) ⇒ void
Remove the given callback from the list of on_error callbacks.
-
.resume_session ⇒ Boolean
Resume the current session if it was previously paused.
-
.session_tracker ⇒ SessionTracker
Returns the client’s SessionTracker object, or creates one if not yet created.
-
.start_session ⇒ void
Starts a new session, which allows Bugsnag to track error rates across releases.
Class Method Details
.add_feature_flag(name, variant = nil) ⇒ void Originally defined in module Utility::FeatureDataStore
This method returns an undefined value.
Add a feature flag with the given name & variant
.add_feature_flags(feature_flags) ⇒ void Originally defined in module Utility::FeatureDataStore
This method returns an undefined value.
Merge the given array of FeatureFlag instances into the stored feature flags
New flags will be appended to the array. Flags with the same name will be overwritten, but their position in the array will not change
.add_metadata(section, data) ⇒ void .add_metadata(section, key, value) ⇒ void
This method returns an undefined value.
Add values to metadata
421 422 423 |
# File 'lib/bugsnag.rb', line 421 def (section, key_or_data, *args) configuration.(section, key_or_data, *args) end |
.add_on_breadcrumb(callback) ⇒ void
This method returns an undefined value.
Add the given callback to the list of on_breadcrumb callbacks
The on_breadcrumb callbacks will be called when a breadcrumb is left and are passed the Breadcrumb object
Returning false from an on_breadcrumb callback will cause the breadcrumb to be ignored and will prevent any remaining callbacks from being called
357 358 359 |
# File 'lib/bugsnag.rb', line 357 def (callback) configuration.(callback) end |
.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
330 331 332 |
# File 'lib/bugsnag.rb', line 330 def add_on_error(callback) configuration.add_on_error(callback) end |
.at_exit_handler_installed? ⇒ Boolean
Checks if an at_exit handler has been added.
The configure method will add this automatically, but it can be added manually using register_at_exit.
176 177 178 |
# File 'lib/bugsnag.rb', line 176 def at_exit_handler_installed? @exit_handler_added ||= false end |
.before_notify_callbacks ⇒ Object
Use add_on_error instead
Allow access to “before notify” callbacks as an array.
These callbacks will be called whenever an error notification is being made.
235 236 237 |
# File 'lib/bugsnag.rb', line 235 def before_notify_callbacks Bugsnag.configuration.request_data[:before_callbacks] ||= [] end |
.breadcrumbs ⇒ Bugsnag::Utility::CircularBuffer
Returns the current list of breadcrumbs
This is a per-thread circular buffer, containing at most ‘max_breadcrumbs’ breadcrumbs
380 381 382 |
# File 'lib/bugsnag.rb', line 380 def configuration. end |
.clear_feature_flag(name) ⇒ void Originally defined in module Utility::FeatureDataStore
This method returns an undefined value.
Remove the stored flag with the given name
.clear_feature_flags ⇒ void Originally defined in module Utility::FeatureDataStore
This method returns an undefined value.
Remove all the stored flags
.clear_metadata(section) ⇒ void .clear_metadata(section, key) ⇒ void
This method returns an undefined value.
Clear values from metadata
438 439 440 |
# File 'lib/bugsnag.rb', line 438 def (section, *args) configuration.(section, *args) end |
.configuration ⇒ Configuration
Returns the client’s Configuration object, or creates one if not yet created.
184 185 186 187 |
# File 'lib/bugsnag.rb', line 184 def configuration @configuration = nil unless defined?(@configuration) @configuration || LOCK.synchronize { @configuration ||= Bugsnag::Configuration.new } end |
.configure(validate_api_key = true) {|configuration| ... } ⇒ void
This method returns an undefined value.
Configure the Bugsnag notifier application-wide settings.
Yields a Configuration object to use to set application settings.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bugsnag.rb', line 54 def configure(validate_api_key=true) yield(configuration) if block_given? # Create the session tracker if sessions are enabled to avoid the overhead # of creating it on the first request. We skip this if we're not validating # the API key as we use this internally before the user's configure block # has run, so we don't know if sessions are enabled yet. session_tracker if validate_api_key && configuration.auto_capture_sessions check_key_valid if validate_api_key check_endpoint_setup register_at_exit end |
.leave_breadcrumb(name, meta_data = {}, type = Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE, auto = :manual) ⇒ void
This method returns an undefined value.
Leave a breadcrumb to be attached to subsequent reports
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/bugsnag.rb', line 275 def (name, ={}, type=Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE, auto=:manual) = Bugsnag::Breadcrumbs::Breadcrumb.new(name, type, , auto) validator = Bugsnag::Breadcrumbs::Validator.new(configuration) # Initial validation validator.validate() # Skip if it's already invalid return if .ignore? # Run before_breadcrumb_callbacks configuration..each do |c| c.arity > 0 ? c.call() : c.call break if .ignore? end # Return early if ignored return if .ignore? # Run on_breadcrumb callbacks configuration..call() return if .ignore? # Validate again in case of callback alteration validator.validate() # Add to breadcrumbs buffer if still valid configuration. << unless .ignore? end |
.load_integration(integration) ⇒ void
This method returns an undefined value.
Load a specific integration.
258 259 260 261 262 263 264 265 |
# File 'lib/bugsnag.rb', line 258 def load_integration(integration) integration = :railtie if integration == :rails if INTEGRATIONS.include?(integration) || integration == :railtie require "bugsnag/integrations/#{integration}" else configuration.debug("Integration #{integration} is not currently supported") end end |
.load_integrations ⇒ void
This method returns an undefined value.
Attempts to load all integrations through auto-discovery.
243 244 245 246 247 248 249 250 251 |
# File 'lib/bugsnag.rb', line 243 def load_integrations require "bugsnag/integrations/railtie" if defined?(Rails::Railtie) INTEGRATIONS.each do |integration| begin require "bugsnag/integrations/#{integration}" rescue LoadError end end end |
.metadata ⇒ Hash
Global metadata added to every event
401 402 403 |
# File 'lib/bugsnag.rb', line 401 def configuration. end |
.notify(exception, auto_notify = false, &block) ⇒ Object
Explicitly notify of an exception.
Optionally accepts a block to append metadata to the yielded report.
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 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 |
# File 'lib/bugsnag.rb', line 73 def notify(exception, auto_notify=false, &block) unless false.equal? auto_notify or true.equal? auto_notify configuration.warn("Adding metadata/severity using a hash is no longer supported, please use block syntax instead") auto_notify = false end return unless should_deliver_notification?(exception, auto_notify) exception = NIL_EXCEPTION_DESCRIPTION if exception.nil? report = Report.new(exception, configuration, auto_notify) # If this is an auto_notify we yield the block before the any middleware is run begin yield(report) if block_given? && auto_notify rescue StandardError => e configuration.warn("Error in internal notify block: #{e}") configuration.warn("Error in internal notify block stacktrace: #{e.backtrace.inspect}") end if report.ignore? configuration.debug("Not notifying #{report.exceptions.last[:errorClass]} due to ignore being signified in auto_notify block") return end # Run internal middleware configuration.internal_middleware.run(report) if report.ignore? configuration.debug("Not notifying #{report.exceptions.last[:errorClass]} due to ignore being signified in internal middlewares") return end # Store before_middleware severity reason for future reference initial_severity = report.severity initial_reason = report.severity_reason # Run users middleware configuration.middleware.run(report) do if report.ignore? configuration.debug("Not notifying #{report.exceptions.last[:errorClass]} due to ignore being signified in user provided middleware") return end # If this is not an auto_notify then the block was provided by the user. This should be the last # block that is run as it is the users "most specific" block. begin yield(report) if block_given? && !auto_notify rescue StandardError => e configuration.warn("Error in notify block: #{e}") configuration.warn("Error in notify block stacktrace: #{e.backtrace.inspect}") end if report.ignore? configuration.debug("Not notifying #{report.exceptions.last[:errorClass]} due to ignore being signified in user provided block") return end # Test whether severity has been changed and ensure severity_reason is consistant in auto_notify case if report.severity != initial_severity report.severity_reason = { :type => Report::USER_CALLBACK_SET_SEVERITY } else report.severity_reason = initial_reason end if report.unhandled_overridden? # let the dashboard know that the unhandled flag was overridden report.severity_reason[:unhandledOverridden] = true end deliver_notification(report) end end |
.on_error(&block) ⇒ void
This method returns an undefined value.
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 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
315 316 317 |
# File 'lib/bugsnag.rb', line 315 def on_error(&block) configuration.on_error(&block) end |
.pause_session ⇒ void
This method returns an undefined value.
Stop any events being attributed to the current session until it is resumed or a new session is started
214 215 216 |
# File 'lib/bugsnag.rb', line 214 def pause_session session_tracker.pause_session end |
.register_at_exit ⇒ void
This method returns an undefined value.
Registers an at_exit function to automatically catch errors on exit.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/bugsnag.rb', line 152 def register_at_exit return if at_exit_handler_installed? @exit_handler_added = true at_exit do if $! exception = unwrap_bundler_exception($!) Bugsnag.notify(exception, true) do |report| report.severity = 'error' report.severity_reason = { :type => Bugsnag::Report::UNHANDLED_EXCEPTION } end end end end |
.remove_on_breadcrumb(callback) ⇒ void
This method returns an undefined value.
Remove the given callback from the list of on_breadcrumb callbacks
Note that this must be the same instance that was passed to add_on_breadcrumb, otherwise it will not be removed
369 370 371 |
# File 'lib/bugsnag.rb', line 369 def (callback) configuration.(callback) 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
342 343 344 |
# File 'lib/bugsnag.rb', line 342 def remove_on_error(callback) configuration.remove_on_error(callback) end |
.resume_session ⇒ Boolean
Resume the current session if it was previously paused. If there is no current session, a new session will be started
225 226 227 |
# File 'lib/bugsnag.rb', line 225 def resume_session session_tracker.resume_session end |
.session_tracker ⇒ SessionTracker
Returns the client’s SessionTracker object, or creates one if not yet created.
193 194 195 196 |
# File 'lib/bugsnag.rb', line 193 def session_tracker @session_tracker = nil unless defined?(@session_tracker) @session_tracker || LOCK.synchronize { @session_tracker ||= Bugsnag::SessionTracker.new} end |
.start_session ⇒ void
This method returns an undefined value.
Starts a new session, which allows Bugsnag to track error rates across releases
203 204 205 |
# File 'lib/bugsnag.rb', line 203 def start_session session_tracker.start_session end |