Module: Airbrake

Defined in:
lib/airbrake-ruby.rb,
lib/airbrake-ruby/config.rb,
lib/airbrake-ruby/notice.rb,
lib/airbrake-ruby/filters.rb,
lib/airbrake-ruby/version.rb,
lib/airbrake-ruby/notifier.rb,
lib/airbrake-ruby/response.rb,
lib/airbrake-ruby/backtrace.rb,
lib/airbrake-ruby/sync_sender.rb,
lib/airbrake-ruby/async_sender.rb,
lib/airbrake-ruby/filter_chain.rb,
lib/airbrake-ruby/payload_truncator.rb,
lib/airbrake-ruby/filters/keys_filter.rb,
lib/airbrake-ruby/filters/keys_blacklist.rb,
lib/airbrake-ruby/filters/keys_whitelist.rb

Overview

Defines version.

Defined Under Namespace

Modules: Backtrace, Filters, Response Classes: AsyncSender, Config, FilterChain, Notice, Notifier, PayloadTruncator, SyncSender

Constant Summary collapse

Error =

The general error that this library uses when it wants to raise.

Class.new(StandardError)
LOG_LABEL =
'**Airbrake:'.freeze
AIRBRAKE_RUBY_VERSION =
'1.0.1'.freeze

Class Method Summary collapse

Class Method Details

.add_filter(filter = nil, notifier = :default) {|notice| ... } ⇒ void

Note:

Once a filter was added, there’s no way to delete it

This method returns an undefined value.

Runs a callback before notify or notify_sync kicks in. This is useful if you want to ignore specific notices or filter the data the notice contains.

Examples:

Ignore all notices

Airbrake.add_filter(&:ignore!)

Ignore based on some condition

Airbrake.add_filter do |notice|
  notice.ignore! if notice[:error_class] == 'StandardError'
end

Ignore with help of a class

class MyFilter
  def call(notice)
    # ...
  end
end

Airbrake.add_filter(MyFilter.new)

Yields:

  • (notice)

    The notice to filter

Yield Parameters:

Yield Returns:

  • (void)

Raises:

See Also:

Since:

  • v5.0.0



180
181
182
# File 'lib/airbrake-ruby.rb', line 180

def add_filter(filter = nil, notifier = :default, &block)
  call_notifier(notifier, __method__, filter, &block)
end

.blacklist_keys(keys, notifier = :default) ⇒ void

This method returns an undefined value.

Specifies which keys should be filtered. Such keys will be replaced with the [Filtered] label.

Examples:

Airbrake.blacklist_keys([:email, /credit/i, 'password'])

Raises:

See Also:

Since:

  • v5.0.0



214
215
216
# File 'lib/airbrake-ruby.rb', line 214

def blacklist_keys(keys, notifier = :default)
  call_notifier(notifier, __method__, keys)
end

.build_notice(exception, params = {}, notifier = :default) ⇒ Airbrake::Notice

Builds an Airbrake notice. This is useful, if you want to add or modify a value only for a specific notice. When you’re done modifying the notice, send it with notify or notify_sync.

Examples:

notice = airbrake.build_notice('App crashed!')
notice[:params][:username] = user.name
airbrake.notify_sync(notice)

Raises:

See Also:

Since:

  • v5.0.0



235
236
237
# File 'lib/airbrake-ruby.rb', line 235

def build_notice(exception, params = {}, notifier = :default)
  call_notifier(notifier, __method__, exception, params)
end

.close(notifier = :default) ⇒ void

This method returns an undefined value.

Makes the notifier a no-op, which means you cannot use the notify and notify_sync methods anymore. It also stops the notifier’s worker threads.

Examples:

Airbrake.close
Airbrake.notify('App crashed!') #=> raises Airbrake::Error

Raises:

See Also:

Since:

  • v5.0.0



251
252
253
# File 'lib/airbrake-ruby.rb', line 251

def close(notifier = :default)
  call_notifier(notifier, __method__)
end

.configure(notifier = :default) {|config| ... } ⇒ void

Note:

There’s no way to reconfigure a notifier

Note:

There’s no way to read config values outside of this library

This method returns an undefined value.

Configures a new notifier with the given name. If the name is not given, configures the default notifier.

Examples:

Configuring the default notifier

Airbrake.configure do |c|
  c.project_id = 113743
  c.project_key = 'fd04e13d806a90f96614ad8e529b2822'
end

Configuring a named notifier

# Configure a new Airbrake instance and
# assign +:my_other_project+ as its name.
Airbrake.configure(:my_other_project) do |c|
  c.project_id = 224854
  c.project_key = '91ac5e4a37496026c6837f63276ed2b6'
end

Yields:

  • (config)

    The configuration object

Yield Parameters:

Raises:

  • (Airbrake::Error)

    when trying to reconfigure already existing notifier



97
98
99
100
101
102
103
104
105
106
# File 'lib/airbrake-ruby.rb', line 97

def configure(notifier = :default)
  yield config = Airbrake::Config.new

  if @notifiers.key?(notifier)
    raise Airbrake::Error,
          "the '#{notifier}' notifier was already configured"
  else
    @notifiers[notifier] = Notifier.new(config)
  end
end

.create_deploy(deploy_params, notifier = :default) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Pings the Airbrake Deploy API endpoint about the occurred deploy. This method is used by the airbrake gem for various integrations.

Options Hash (deploy_params):

  • :environment (Symbol)
  • :username (Symbol)
  • :repository (Symbol)
  • :revision (Symbol)
  • :version (Symbol)

Raises:

See Also:

Since:

  • v5.0.0



268
269
270
# File 'lib/airbrake-ruby.rb', line 268

def create_deploy(deploy_params, notifier = :default)
  call_notifier(notifier, __method__, deploy_params)
end

.notify(exception, params = {}, notifier = :default) ⇒ nil

Sends an exception to Airbrake asynchronously.

Examples:

Sending an exception

Airbrake.notify(RuntimeError.new('Oops!'))

Sending a string

# Converted to RuntimeError.new('Oops!') internally
Airbrake.notify('Oops!')

Sending a Notice

notice = airbrake.build_notice(RuntimeError.new('Oops!'))
airbrake.notify(notice)

Raises:

See Also:



133
134
135
# File 'lib/airbrake-ruby.rb', line 133

def notify(exception, params = {}, notifier = :default)
  call_notifier(notifier, __method__, exception, params)
end

.notify_sync(exception, params = {}, notifier = :default) ⇒ Hash{String=>String}

Sends an exception to Airbrake synchronously.

Examples:

Airbrake.notify_sync('App crashed!')
#=> {"id"=>"123", "url"=>"https://airbrake.io/locate/321"}

Raises:

See Also:

Since:

  • v5.0.0



148
149
150
# File 'lib/airbrake-ruby.rb', line 148

def notify_sync(exception, params = {}, notifier = :default)
  call_notifier(notifier, __method__, exception, params)
end

.whitelist_keys(keys, notifier = :default) ⇒ void

This method returns an undefined value.

Specifies which keys should not be filtered. All other keys will be substituted with the [Filtered] label.

Examples:

Airbrake.whitelist([:email, /user/i, 'account_id'])

Raises:

See Also:

Since:

  • v5.0.0



197
198
199
# File 'lib/airbrake-ruby.rb', line 197

def whitelist_keys(keys, notifier = :default)
  call_notifier(notifier, __method__, keys)
end