Class: Airbrake::NoticeNotifier

Inherits:
Object
  • Object
show all
Includes:
Inspectable, Loggable
Defined in:
lib/airbrake-ruby/notice_notifier.rb

Overview

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

See Also:

Since:

  • v1.0.0

Constant Summary collapse

DEFAULT_FILTERS =

Returns filters to be executed first.

Returns:

  • (Array<Class>)

    filters to be executed first

Since:

  • v1.0.0

[
  Airbrake::Filters::SystemExitFilter,
  Airbrake::Filters::GemRootFilter,

  # Optional filters (must be included by users):
  # Airbrake::Filters::ThreadFilter
].freeze

Constants included from Inspectable

Inspectable::INSPECT_TEMPLATE

Instance Method Summary collapse

Methods included from Loggable

#logger

Methods included from Inspectable

#inspect, #pretty_print

Constructor Details

#initializeNoticeNotifier

Returns a new instance of NoticeNotifier.

Since:

  • v1.0.0



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/airbrake-ruby/notice_notifier.rb', line 21

def initialize
  @config = Airbrake::Config.instance
  @filter_chain = FilterChain.new
  @async_sender = AsyncSender.new(:post, self.class.name)
  @sync_sender = SyncSender.new

  DEFAULT_FILTERS.each { |filter| add_filter(filter.new) }

  add_filter(Airbrake::Filters::ContextFilter.new)
  add_filter(Airbrake::Filters::ExceptionAttributesFilter.new)
end

Instance Method Details

#add_filter(filter = nil, &block) ⇒ Object

See Also:

  • Airbrake.add_filte

Since:

  • v1.0.0



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

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

#build_notice(exception, params = {}) ⇒ Object

See Also:

Since:

  • v1.0.0



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/airbrake-ruby/notice_notifier.rb', line 54

def build_notice(exception, params = {})
  if @async_sender.closed?
    raise Airbrake::Error,
          "Airbrake is closed; can't build exception: " \
          "#{exception.class}: #{exception}"
  end

  if exception.is_a?(Airbrake::Notice)
    exception[:params].merge!(params)
    exception
  else
    Notice.new(convert_to_exception(exception), params.dup)
  end
end

#closeObject

See Also:

Since:

  • v1.0.0



70
71
72
73
# File 'lib/airbrake-ruby/notice_notifier.rb', line 70

def close
  @sync_sender.close
  @async_sender.close
end

#configured?Boolean

Returns:

  • (Boolean)

See Also:

Since:

  • v1.0.0



76
77
78
# File 'lib/airbrake-ruby/notice_notifier.rb', line 76

def configured?
  @config.valid?
end

#delete_filter(filter_class) ⇒ Object

See Also:

Since:

  • v1.0.0



49
50
51
# File 'lib/airbrake-ruby/notice_notifier.rb', line 49

def delete_filter(filter_class)
  @filter_chain.delete_filter(filter_class)
end

#has_filter?(filter_class) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • v4.14.0



87
88
89
# File 'lib/airbrake-ruby/notice_notifier.rb', line 87

def has_filter?(filter_class) # rubocop:disable Naming/PredicateName
  @filter_chain.includes?(filter_class)
end

#merge_context(context) ⇒ Object

See Also:

Since:

  • v1.0.0



81
82
83
# File 'lib/airbrake-ruby/notice_notifier.rb', line 81

def merge_context(context)
  Airbrake::Context.current.merge!(context)
end

#notify(exception, params = {}, &block) ⇒ Object

See Also:

Since:

  • v1.0.0



34
35
36
# File 'lib/airbrake-ruby/notice_notifier.rb', line 34

def notify(exception, params = {}, &block)
  send_notice(exception, params, default_sender, &block)
end

#notify_sync(exception, params = {}, &block) ⇒ Object

See Also:

Since:

  • v1.0.0



39
40
41
# File 'lib/airbrake-ruby/notice_notifier.rb', line 39

def notify_sync(exception, params = {}, &block)
  send_notice(exception, params, @sync_sender, &block).value
end