Module: Airbrake

Defined in:
lib/airbrake.rb,
lib/airbrake/rack.rb,
lib/airbrake/rails.rb,
lib/airbrake/notice.rb,
lib/airbrake/sender.rb,
lib/airbrake/railtie.rb,
lib/airbrake/sinatra.rb,
lib/airbrake/version.rb,
lib/airbrake/response.rb,
lib/airbrake/backtrace.rb,
lib/airbrake/capistrano.rb,
lib/airbrake/configuration.rb,
lib/airbrake/user_informer.rb,
lib/airbrake/rails/middleware.rb,
lib/airbrake/rails/error_lookup.rb,
lib/airbrake/utils/rack_filters.rb,
lib/airbrake/utils/params_cleaner.rb,
lib/airbrake/rails/controller_methods.rb,
lib/airbrake/rails/action_controller_catcher.rb

Defined Under Namespace

Modules: Capistrano, Rails, RakeHandler, Utils Classes: Backtrace, CollectingSender, Configuration, Notice, Rack, Railtie, Response, Sender, Sinatra, UserInformer

Constant Summary collapse

API_VERSION =
"2.4"
LOG_PREFIX =
"** [Airbrake] "
VERSION =
"4.3.0".freeze
SENSITIVE_RACK_VARS =
%w(
    HTTP_X_CSRF_TOKEN
    HTTP_COOKIE
    HTTP_AUTHORIZATION

    action_dispatch.request.unsigned_session_cookie
    action_dispatch.cookies
    action_dispatch.unsigned_session_cookie
    action_dispatch.secret_key_base
    action_dispatch.signed_cookie_salt
    action_dispatch.encrypted_cookie_salt
    action_dispatch.encrypted_signed_cookie_salt
    action_dispatch.http_auth_salt
    action_dispatch.secret_token

    rack.request.cookie_hash
    rack.request.cookie_string
    rack.request.form_vars

    rack.session
    rack.session.options
)
RACK_VARS_CONTAINING_INSTANCES =
%w(
    action_controller.instance

    action_dispatch.backtrace_cleaner
    action_dispatch.routes
    action_dispatch.logger
    action_dispatch.key_generator

    rack-cache.storage

    rack.errors
    rack.input
)
SENSITIVE_ENV_VARS =
[
    /secret/i,
    /password/i
]
FILTERED_RACK_VARS =
SENSITIVE_RACK_VARS + SENSITIVE_ENV_VARS + RACK_VARS_CONTAINING_INSTANCES

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

The configuration object.

See Also:



115
116
117
# File 'lib/airbrake.rb', line 115

def configuration
  @configuration ||= Configuration.new
end

.senderObject

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



43
44
45
# File 'lib/airbrake.rb', line 43

def sender
  @sender
end

Class Method Details

.build_lookup_hash_for(exception, options = {}) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 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

.configure(silent = false) {|configuration| ... } ⇒ Object

Call this method to modify defaults in your initializers.

Examples:

Airbrake.configure do |config|
  config.api_key = '1234567890abcdef'
  config.secure  = false
end

Yields:



101
102
103
104
105
106
107
108
109
110
111
# 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_infoObject

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



76
77
78
79
80
81
# 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

.loggerObject

Look for the Rails logger currently defined



89
90
91
92
# File 'lib/airbrake.rb', line 89

def logger
  self.configuration.logger ||
    Logger.new(nil)
end

.notify(exception, opts = {}) ⇒ Object

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

Parameters:

  • exception (Exception)

    The exception you want to notify Airbrake about.

  • opts (Hash) (defaults to: {})

    Data that will be sent to Airbrake.

Options Hash (opts):

  • :api_key (String)

    The API key for this project. The API key is a unique identifier that Airbrake uses for identification.

  • :error_message (String)

    The error returned by the exception (or the message you want to log).

  • :backtrace (String)

    A backtrace, usually obtained with caller.

  • :rack_env (String)

    The Rack environment.

  • :session (String)

    The contents of the user’s session.

  • :environment_name (String)

    The application environment name.

  • :parameters (String)

    Additional parameters.



131
132
133
# File 'lib/airbrake.rb', line 131

def notify(exception, opts = {})
  send_notice(build_notice_for(exception, opts))
end

.notify_or_ignore(exception, opts = {}) ⇒ Object

Sends the notice unless it is one of the default ignored exceptions

See Also:



137
138
139
140
# 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_infoObject

Prints out the environment info to the log for debugging help



55
56
57
# File 'lib/airbrake.rb', line 55

def report_environment_info
  write_verbose_log("Environment Info: #{environment_info}")
end

.report_notice(notice) ⇒ Object

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



65
66
67
# File 'lib/airbrake.rb', line 65

def report_notice(notice)
  write_verbose_log("Notice details: \n#{notice}")
end

.report_notice_not_sent_for_configurationObject



69
70
71
72
73
# 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_readyObject

Tell the log that the Notifier is good to go



50
51
52
# File 'lib/airbrake.rb', line 50

def report_ready
  write_verbose_log("Notifier #{VERSION} ready to catch errors")
end

.report_response_body(response) ⇒ Object

Prints out the response body from Airbrake for debugging help



60
61
62
# 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) ⇒ Object

Writes out the given message to the #logger



84
85
86
# File 'lib/airbrake.rb', line 84

def write_verbose_log(message)
  logger.debug LOG_PREFIX + message if logger
end