Class: Airbrake::Notifier Private

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake-ruby/notifier.rb

Overview

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

This class is reponsible for sending notices to Airbrake. It supports synchronous and asynchronous delivery.

See Also:

Since:

  • v5.0.0

Instance Method Summary collapse

Constructor Details

#initialize(user_config) ⇒ Notifier

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.

Creates a new Airbrake notifier with the given config options.

Examples:

Configuring with a Hash

airbrake = Airbrake.new(project_id: 123, project_key: '321')

Configuring with an Airbrake::Config

config = Airbrake::Config.new
config.project_id = 123
config.project_key = '321'
airbake = Airbrake.new(config)

Parameters:

  • user_config (Hash, Airbrake::Config)

    The config that contains information about how the notifier should operate

Raises:

  • (Airbrake::Error)

    when either project_id or project_key is missing (or both)

Since:

  • v5.0.0



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/airbrake-ruby/notifier.rb', line 26

def initialize(user_config)
  @config = (user_config.is_a?(Config) ? user_config : Config.new(user_config))

  unless [@config.project_id, @config.project_key].all?
    raise Airbrake::Error, 'both :project_id and :project_key are required'
  end

  @filter_chain = FilterChain.new(@config)
  @async_sender = AsyncSender.new(@config)
  @sync_sender = SyncSender.new(@config)
end

Instance Method Details

#add_filter(filter = nil, &block) ⇒ 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.

See Also:

Since:

  • v5.0.0



57
58
59
# File 'lib/airbrake-ruby/notifier.rb', line 57

def add_filter(filter = nil, &block)
  @filter_chain.add_filter(block_given? ? block : filter)
end

#blacklist_keys(keys) ⇒ 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.

See Also:

Since:

  • v5.0.0



69
70
71
# File 'lib/airbrake-ruby/notifier.rb', line 69

def blacklist_keys(keys)
  add_filter(Filters::KeysBlacklist.new(*keys))
end

#build_notice(exception, params = {}) ⇒ 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.

See Also:

Since:

  • v5.0.0



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/airbrake-ruby/notifier.rb', line 75

def build_notice(exception, params = {})
  if @async_sender.closed?
    raise Airbrake::Error,
          "attempted to build #{exception} with closed Airbrake instance"
  end

  if exception.is_a?(Airbrake::Notice)
    exception
  else
    Notice.new(@config, convert_to_exception(exception), params)
  end
end

#closeObject

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.

See Also:

Since:

  • v5.0.0



90
91
92
# File 'lib/airbrake-ruby/notifier.rb', line 90

def close
  @async_sender.close
end

#create_deploy(deploy_params) ⇒ 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.

See Also:

Since:

  • v5.0.0



96
97
98
99
100
101
102
103
# File 'lib/airbrake-ruby/notifier.rb', line 96

def create_deploy(deploy_params)
  deploy_params[:environment] ||= @config.environment

  host = @config.endpoint.to_s.split(@config.endpoint.path).first
  path = "/api/v4/projects/#{@config.project_id}/deploys?key=#{@config.project_key}"

  @sync_sender.send(deploy_params, URI.join(host, path))
end

#notify(exception, params = {}) ⇒ 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.

See Also:

Since:

  • v5.0.0



44
45
46
47
# File 'lib/airbrake-ruby/notifier.rb', line 44

def notify(exception, params = {})
  send_notice(exception, params)
  nil
end

#notify_sync(exception, params = {}) ⇒ 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.

See Also:

Since:

  • v5.0.0



51
52
53
# File 'lib/airbrake-ruby/notifier.rb', line 51

def notify_sync(exception, params = {})
  send_notice(exception, params, @sync_sender)
end

#whitelist_keys(keys) ⇒ 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.

See Also:

Since:

  • v5.0.0



63
64
65
# File 'lib/airbrake-ruby/notifier.rb', line 63

def whitelist_keys(keys)
  add_filter(Filters::KeysWhitelist.new(*keys))
end