Module: Bugsnag

Defined in:
lib/bugsnag.rb,
lib/bugsnag/rack.rb,
lib/bugsnag/rails.rb,
lib/bugsnag/deploy.rb,
lib/bugsnag/resque.rb,
lib/bugsnag/helpers.rb,
lib/bugsnag/mailman.rb,
lib/bugsnag/railtie.rb,
lib/bugsnag/sidekiq.rb,
lib/bugsnag/version.rb,
lib/bugsnag/meta_data.rb,
lib/bugsnag/capistrano2.rb,
lib/bugsnag/delay/resque.rb,
lib/bugsnag/notification.rb,
lib/bugsnag/configuration.rb,
lib/bugsnag/middleware_stack.rb

Defined Under Namespace

Modules: Capistrano, Delay, Helpers, MetaData, Middleware, Rails, Rake Classes: Configuration, Deploy, Mailman, MiddlewareStack, Notification, Rack, Railtie, Resque, Sidekiq

Constant Summary collapse

LOG_PREFIX =
"** [Bugsnag] "
VERSION =
File.read(File.join(File.dirname(__FILE__), "../../VERSION")).strip

Class Method Summary collapse

Class Method Details

.after_notify_callbacksObject

Allow access to “after notify” callbacks



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

def after_notify_callbacks
  Bugsnag.configuration.request_data[:after_callbacks] ||= []
end

.auto_notify(exception, overrides = nil, request_data = nil) ⇒ Object

Auto notify of an exception, called from rails and rack exception rescuers, unless auto notification is disabled, or we should ignore this error class



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

def auto_notify(exception, overrides=nil, request_data=nil)
  overrides ||= {}
  overrides.merge!({:severity => "error"})
  notify_or_ignore(exception, overrides, request_data) if configuration.auto_notify
end

.before_notify_callbacksObject

Allow access to “before notify” callbacks



103
104
105
# File 'lib/bugsnag.rb', line 103

def before_notify_callbacks
  Bugsnag.configuration.request_data[:before_callbacks] ||= []
end

.clear_request_dataObject

Clear all “per-request” data, temporal data for use in bugsnag middleware This method should be called after each distinct request or session ends Eg. After completing a page request in a web app



98
99
100
# File 'lib/bugsnag.rb', line 98

def clear_request_data
  Bugsnag.configuration.clear_request_data
end

.configurationObject

Configuration getters



86
87
88
# File 'lib/bugsnag.rb', line 86

def configuration
  @configuration ||= Bugsnag::Configuration.new
end

.configure(config_hash = nil) {|configuration| ... } ⇒ Object

Configure the Bugsnag notifier application-wide settings.

Yields:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bugsnag.rb', line 25

def configure(config_hash=nil)
  if config_hash
    config_hash.each do |k,v|
      configuration.send("#{k}=", v) rescue nil if configuration.respond_to?("#{k}=")
    end
  end

  yield(configuration) if block_given?

  # Use resque for asynchronous notification if required
  require "bugsnag/delay/resque" if configuration.delay_with_resque && defined?(Resque)

  # Log that we are ready to rock
  if configuration.api_key && !@logged_ready
    log "Bugsnag exception handler #{VERSION} ready, api_key=#{configuration.api_key}"
    @logged_ready = true
  end
end

.debug(message) ⇒ Object

Debug logger



81
82
83
# File 'lib/bugsnag.rb', line 81

def debug(message)
  configuration.logger.info("#{LOG_PREFIX}#{message}") if configuration.debug
end

.log(message) ⇒ Object

Log wrapper



71
72
73
# File 'lib/bugsnag.rb', line 71

def log(message)
  configuration.logger.info("#{LOG_PREFIX}#{message}")
end

.notify(exception, overrides = nil, request_data = nil) ⇒ Object

Explicitly notify of an exception



45
46
47
# File 'lib/bugsnag.rb', line 45

def notify(exception, overrides=nil, request_data=nil)
  Notification.new(exception, configuration, overrides, request_data).deliver
end

.notify_or_ignore(exception, overrides = nil, request_data = nil) ⇒ Object

Notify of an exception unless it should be ignored



50
51
52
53
54
55
56
57
58
59
# File 'lib/bugsnag.rb', line 50

def notify_or_ignore(exception, overrides=nil, request_data=nil)
  notification = Notification.new(exception, configuration, overrides, request_data)

  unless notification.ignore?
    notification.deliver
    notification
  else
    false
  end
end

.set_request_data(key, value) ⇒ Object

Set “per-request” data, temporal data for use in bugsnag middleware



91
92
93
# File 'lib/bugsnag.rb', line 91

def set_request_data(key, value)
  Bugsnag.configuration.set_request_data(key, value)
end

.warn(message) ⇒ Object

Warning logger



76
77
78
# File 'lib/bugsnag.rb', line 76

def warn(message)
  configuration.logger.warn("#{LOG_PREFIX}#{message}")
end