Module: Bugsnag

Defined in:
lib/bugsnag.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/configuration.rb,
lib/bugsnag/middleware_stack.rb,
lib/bugsnag/integrations/rack.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/integrations/shoryuken.rb

Defined Under Namespace

Modules: Delivery, Helpers, MetaData, Middleware, Rails Classes: Cleaner, Configuration, Mailman, MiddlewareStack, Rack, Railtie, Report, Resque, Shoryuken, Sidekiq, Stacktrace

Constant Summary collapse

LOCK =
Mutex.new
VERSION =
File.read(File.join(File.dirname(__FILE__), "../../VERSION")).strip

Class Method Summary collapse

Class Method Details

.before_notify_callbacksObject

Allow access to “before notify” callbacks



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

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

.configurationObject

Configuration getters



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

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

.configure {|configuration| ... } ⇒ Object

Configure the Bugsnag notifier application-wide settings.

Yields:



34
35
36
37
38
39
40
41
42
# File 'lib/bugsnag.rb', line 34

def configure
  yield(configuration) if block_given?

  @key_warning = false unless defined?(@key_warning)
  if !configuration.valid_api_key? && !@key_warning
    configuration.warn("No valid API key has been set, notifications will not be sent")
    @key_warning = true
  end
end

.notify(exception, auto_notify = false) {|report| ... } ⇒ Object

Explicitly notify of an exception

Yields:

  • (report)


45
46
47
48
49
50
51
52
53
54
55
56
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/bugsnag.rb', line 45

def notify(exception, auto_notify=false, &block)
  unless auto_notify.is_a? TrueClass or auto_notify.is_a? FalseClass
    configuration.warn("Adding metadata/severity using a hash is no longer supported, please use block syntax instead")
    auto_notify = false
  end

  if !configuration.auto_notify && auto_notify
    configuration.debug("Not notifying because auto_notify is disabled")
    return
  end

  if !configuration.valid_api_key?
    configuration.debug("Not notifying due to an invalid api_key")
    return
  end

  if !configuration.should_notify_release_stage?
    configuration.debug("Not notifying due to notify_release_stages :#{configuration.notify_release_stages.inspect}")
    return
  end

  report = Report.new(exception, configuration, auto_notify)

  # If this is an auto_notify we yield the block before the any middleware is run
  yield(report) if block_given? && auto_notify
  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.
    yield(report) if block_given? && !auto_notify
    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

    # Deliver
    configuration.info("Notifying #{configuration.endpoint} of #{report.exceptions.last[:errorClass]}")
    payload_string = ::JSON.dump(Bugsnag::Helpers.trim_if_needed(report.as_json))
    Bugsnag::Delivery[configuration.delivery_method].deliver(configuration.endpoint, payload_string, configuration)
  end
end