module Airbrake

Constants

API_VERSION
FILTERED_RACK_VARS
LOG_PREFIX
RACK_VARS_CONTAINING_INSTANCES
SENSITIVE_ENV_VARS
SENSITIVE_RACK_VARS
VERSION

Attributes

configuration[W]

A Airbrake configuration object. Must act like a hash and return sensible values for all Airbrake configuration options. See Airbrake::Configuration.

sender[RW]

The sender object is responsible for delivering formatted data to the Airbrake server. Must respond to send_to_airbrake. See Airbrake::Sender.

Public Class Methods

build_lookup_hash_for(exception, options = {}) click to toggle source
# File lib/airbrake.rb, line 142
def build_lookup_hash_for(exception, options = {})
  notice = build_notice_for(exception, options)

  result = {}
  result[:action]           = notice.action      rescue nil
  result[:component]        = notice.component   rescue nil
  result[:error_class]      = notice.error_class if notice.error_class
  result[:environment_name] = 'production'

  unless notice.backtrace.lines.empty?
    result[:file]        = notice.backtrace.lines.first.file
    result[:line_number] = notice.backtrace.lines.first.number
  end

  result
end
configuration() click to toggle source

The configuration object. @see Airbrake.configure

# File lib/airbrake.rb, line 115
def configuration
  @configuration ||= Configuration.new
end
configure(silent = false) { |configuration| ... } click to toggle source

Call this method to modify defaults in your initializers.

@example

Airbrake.configure do |config|
  config.api_key = '1234567890abcdef'
  config.secure  = false
end
# File lib/airbrake.rb, line 101
def configure(silent = false)
  yield(configuration)
  self.sender = if configuration.test_mode?
                  CollectingSender.new(configuration)
                else
                  Sender.new(configuration)
                end

  report_ready unless silent
  self.sender
end
environment_info() click to toggle source

Returns the Ruby version, Rails version, and current Rails environment

# File lib/airbrake.rb, line 76
def environment_info
  info = "[Ruby: #{RUBY_VERSION}]"
  info << " [#{configuration.framework}]" if configuration.framework
  info << " [Env: #{configuration.environment_name}]" if configuration.environment_name
  info
end
logger() click to toggle source

Look for the Rails logger currently defined

# File lib/airbrake.rb, line 89
def logger
  self.configuration.logger ||
    Logger.new(nil)
end
notify(exception, opts = {}) click to toggle source

Sends an exception manually using this method, even when you are not in a controller.

@param [Exception] exception The exception you want to notify Airbrake about. @param [Hash] opts Data that will be sent to Airbrake.

@option opts [String] :api_key The API key for this project. The API key is a unique identifier that Airbrake uses for identification. @option opts [String] :error_message The error returned by the exception (or the message you want to log). @option opts [String] :backtrace A backtrace, usually obtained with caller. @option opts [String] :rack_env The Rack environment. @option opts [String] :session The contents of the user’s session. @option opts [String] :environment_name The application environment name. @option opts [String] :parameters Additional parameters.

# File lib/airbrake.rb, line 131
def notify(exception, opts = {})
  send_notice(build_notice_for(exception, opts))
end
notify_or_ignore(exception, opts = {}) click to toggle source

Sends the notice unless it is one of the default ignored exceptions @see Airbrake.notify

# File lib/airbrake.rb, line 137
def notify_or_ignore(exception, opts = {})
  notice = build_notice_for(exception, opts)
  send_notice(notice) unless notice.ignore?
end
report_environment_info() click to toggle source

Prints out the environment info to the log for debugging help

# File lib/airbrake.rb, line 55
def report_environment_info
  write_verbose_log("Environment Info: #{environment_info}")
end
report_notice(notice) click to toggle source

Prints out the details about the notice that wasn’t sent to server

# File lib/airbrake.rb, line 65
def report_notice(notice)
  write_verbose_log("Notice details: \n#{notice}")
end
report_notice_not_sent_for_configuration() click to toggle source
# File lib/airbrake.rb, line 69
def report_notice_not_sent_for_configuration
  write_verbose_log("Notice was not sent due to configuration: \
    \n  Environment Monitored? #{configuration.public?} \
    \n  API key set? #{configuration.configured?}")
end
report_ready() click to toggle source

Tell the log that the Notifier is good to go

# File lib/airbrake.rb, line 50
def report_ready
  write_verbose_log("Notifier #{VERSION} ready to catch errors")
end
report_response_body(response) click to toggle source

Prints out the response body from Airbrake for debugging help

# File lib/airbrake.rb, line 60
def report_response_body(response)
  write_verbose_log("Response from Airbrake: \n#{Response.pretty_format(response)}")
end
write_verbose_log(message) click to toggle source

Writes out the given message to the logger

# File lib/airbrake.rb, line 84
def write_verbose_log(message)
  logger.debug LOG_PREFIX + message if logger
end

Private Class Methods

build_notice_for(exception, opts = {}) click to toggle source
# File lib/airbrake.rb, line 174
def build_notice_for(exception, opts = {})
  exception_classes = [exception.class.to_s]
  exception = unwrap_exception(exception)
  opts = opts.merge(:exception => exception) if exception.is_a?(Exception)
  opts = opts.merge(exception.to_hash) if exception.respond_to?(:to_hash)
  opts = opts.merge(:exception_classes => exception_classes)
  Notice.new(configuration.merge(opts))
end
send_notice(notice) click to toggle source
# File lib/airbrake.rb, line 161
def send_notice(notice)
  if configuration.configured? && configuration.public?
    if configuration.async?
      configuration.async.call(notice)
      nil # make sure we never set env["airbrake.error_id"] for async notices
    else
      sender.send_to_airbrake(notice)
    end
  else
    report_notice_not_sent_for_configuration
  end
end
unwrap_exception(exception) click to toggle source
# File lib/airbrake.rb, line 183
def unwrap_exception(exception)
  if exception.respond_to?(:original_exception)
    exception.original_exception
  elsif exception.respond_to?(:continued_exception)
    exception.continued_exception
  end || exception
end