Class: ExceptionNotifier::SnsNotifier
- Inherits:
-
BaseNotifier
- Object
- BaseNotifier
- ExceptionNotifier::SnsNotifier
- Includes:
- BacktraceCleaner
- Defined in:
- lib/exception_notifier/sns_notifier.rb
Instance Method Summary collapse
- #active? ⇒ Boolean
- #call(exception, options = {}) ⇒ Object
- #compose_info ⇒ Object
- #compose_message ⇒ Object
-
#initialize(options) ⇒ SnsNotifier
constructor
A new instance of SnsNotifier.
- #request_data ⇒ Object
Constructor Details
#initialize(options) ⇒ SnsNotifier
Returns a new instance of SnsNotifier.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/exception_notifier/sns_notifier.rb', line 7 def initialize() super client_params = {} %i[access_key_id secret_access_key region].each do |key| next unless [key].present? client_params[key] = .delete(key) end @sns_client = Aws::SNS::Client.new(client_params) @topic_arn = .delete(:topic_arn) @subject = .delete(:subject) end |
Instance Method Details
#active? ⇒ Boolean
35 36 37 |
# File 'lib/exception_notifier/sns_notifier.rb', line 35 def active? !@sns_client.nil? && @topic_arn.present? end |
#call(exception, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/exception_notifier/sns_notifier.rb', line 22 def call(exception, = {}) return unless active? env = [:env] || {} @options = @exception = exception @backtrace = exception.backtrace ? clean_backtrace(exception) : [] @kontroller = env['action_controller.instance'] @request = ::ActionDispatch::Request.new(env) if @kontroller @sns_client.publish(topic_arn: @topic_arn, message: .to_json, subject: @subject) end |
#compose_info ⇒ Object
39 40 41 42 43 |
# File 'lib/exception_notifier/sns_notifier.rb', line 39 def compose_info info = @kontroller ? "#{@kontroller.controller_name}##{@kontroller.action_name}" : '' info << " (#{@exception.class})" info << " #{@exception..inspect}" end |
#compose_message ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/exception_notifier/sns_notifier.rb', line 45 def = { info: compose_info, backtrace: @backtrace.to_s, default: compose_info } [:request] = request_data if @request end |
#request_data ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/exception_notifier/sns_notifier.rb', line 56 def request_data { url: @request.url, method: @request.request_method, remote_ip: @request.remote_ip, parameters: @request.filtered_parameters.inspect } end |