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/cleaner.rb,
lib/bugsnag/helpers.rb,
lib/bugsnag/mailman.rb,
lib/bugsnag/railtie.rb,
lib/bugsnag/sidekiq.rb,
lib/bugsnag/version.rb,
lib/bugsnag/delivery.rb,
lib/bugsnag/meta_data.rb,
lib/bugsnag/shoryuken.rb,
lib/bugsnag/capistrano2.rb,
lib/bugsnag/delay/resque.rb,
lib/bugsnag/notification.rb,
lib/bugsnag/configuration.rb,
lib/bugsnag/middleware_stack.rb,
lib/bugsnag/delivery/synchronous.rb,
lib/bugsnag/delivery/thread_queue.rb

Defined Under Namespace

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

Constant Summary collapse

LOG_PREFIX =
"** [Bugsnag] "
LOCK =
Mutex.new
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



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

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

.auto_notify(exception, overrides = nil, request_data = nil, &block) ⇒ 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



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

def auto_notify(exception, overrides=nil, request_data=nil, &block)
  overrides ||= {}
  overrides[:severity] = "error" unless overrides.has_key? :severity
  overrides[:unhandled] = true unless overrides.has_key? :unhandled
  notify_or_ignore(exception, overrides, request_data, &block) if configuration.auto_notify
end

.before_notify_callbacksObject

Allow access to “before notify” callbacks



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

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



132
133
134
# File 'lib/bugsnag.rb', line 132

def clear_request_data
  Bugsnag.configuration.clear_request_data
end

.configurationObject

Configuration getters



119
120
121
122
# File 'lib/bugsnag.rb', line 119

def configuration
  @configuration = nil unless defined?(@configuration)
  @configuration || LOCK.synchronize { @configuration ||= Bugsnag::Configuration.new }
end

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

Configure the Bugsnag notifier application-wide settings.

Yields:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/bugsnag.rb', line 35

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)

  # Add info error classifier to internal middleware
  configuration.internal_middleware.use(Bugsnag::Middleware::ClassifyError)

  # Warn if an api_key hasn't been set
  @key_warning = false unless defined?(@key_warning)

  if !configuration.api_key && !@key_warning
    warn "No API key has been set, check your configuration"
    @key_warning = true
  end

  # Log that we are ready to rock
  @logged_ready = false unless defined?(@logged_ready)

  if configuration.api_key && !@logged_ready
    log "Bugsnag exception handler #{VERSION} ready"
    @logged_ready = true
  end
end

.debug(message) ⇒ Object

Debug logger



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

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

.log(message) ⇒ Object

Log wrapper



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

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

.notify(exception, overrides = nil, request_data = nil) {|notification| ... } ⇒ Object Also known as: notify_or_ignore

Explicitly notify of an exception

Yields:

  • (notification)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/bugsnag.rb', line 68

def notify(exception, overrides=nil, request_data=nil, &block)
  notification = Notification.new(exception, configuration, overrides, request_data)

  initial_severity = notification.severity
  initial_reason = notification.severity_reason

  yield(notification) if block_given?

  if notification.severity != initial_severity
    notification.severity_reason = {
      :type => Bugsnag::Notification::USER_CALLBACK_SET_SEVERITY
    }
  else
    notification.severity_reason = initial_reason
  end

  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



125
126
127
# File 'lib/bugsnag.rb', line 125

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

.warn(message) ⇒ Object

Warning logger



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

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