Sha256: 1217fdef9fe4e961e6fe6371e4fb8e6a004125e615decf0f49f45e16ebf11725

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

# encoding: utf-8

require 'toadhopper'
require 'socket'
require 'adhearsion/reporter/version'

module Adhearsion
  class Reporter
    class AirbrakeNotifier
      include Singleton

      def init
        @notifier = Toadhopper.new Reporter.config.api_key, :notify_host => Reporter.config.url
        @options = {
          framework_env: Adhearsion.config.platform.environment,
          notifier_name: 'adhearsion-reporter',
          notifier_version: Adhearsion::Reporter::VERSION,
          project_root: Adhearsion.config.platform[:root],
          environment: {
            'HOSTNAME' => Socket.gethostname,
            'AHN_VERSION' => Adhearsion::VERSION
          }
        }
      end

      def notify(ex)
        return unless should_post?
        response = @notifier.post!(ex, @options)
        if !response.errors.empty? || !(200..299).include?(response.status.to_i)
          logger.error "Error posting exception to #{Reporter.config.url}! Response code #{response.status}"
          response.errors.each do |error|
            logger.error "#{error}"
          end
          logger.warn "Original exception message: #{ex.message}"
        end
      end

      def self.method_missing(m, *args, &block)
        instance.send m, *args, &block
      end

    private
      def should_post?
        Reporter.config.enable &&
          !Reporter.config.excluded_environments.include?(@options[:framework_env])
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adhearsion-reporter-2.2.0 lib/adhearsion/reporter/airbrake_notifier.rb
adhearsion-reporter-2.1.0 lib/adhearsion/reporter/airbrake_notifier.rb