Sha256: 9c368dab12e32ea32ea9c3ffe7526ddfac6a7555eaac90dca11f71606bc7e50c

Contents?: true

Size: 1.82 KB

Versions: 7

Compression:

Stored size: 1.82 KB

Contents

# encoding: utf-8
require 'ting_yun/agent'
require 'ting_yun/support/exception'

module TingYun
  module Instrumentation
    module Support
      module ExternalError


        module_function

        def capture_exception(response,request,type)
          if !response.nil? && response.code =~ /^[4,5][0-9][0-9]$/ && response.code!='401'
            e = TingYun::Support::Exception::InternalServerError.new("#{response.code}: #{response.message}")
            klass = "External/#{request.uri.to_s.gsub('/','%2F')}/#{type}"
            set_attributes(e, klass)
            e.instance_variable_set(:@tingyun_code, response.code)
            TingYun::Agent.notice_error(e)
          end
        end

        def handle_error(e,klass)

          set_attributes(e, klass)
          case e
            when Errno::ECONNREFUSED
              e.instance_variable_set(:@tingyun_code, 902)
            when SocketError
              e.instance_variable_set(:@tingyun_code, 901)
            when OpenSSL::SSL::SSLError
              e.instance_variable_set(:@tingyun_code, 908)
            when Timeout::Error
              e.instance_variable_set(:@tingyun_code, 903)
            else
              e.instance_variable_set(:@tingyun_code, 1000)
          end

          TingYun::Agent.notice_error(e)
        end

        def set_attributes(exception, klass)
          begin
            exception.instance_variable_set(:@tingyun_klass, klass)
            exception.instance_variable_set(:@tingyun_external, true)
            trace = caller.reject! { |t| t.include?('tingyun_rpm') }
            trace = trace.first(40) if trace.length > 40
            exception.instance_variable_set(:@tingyun_trace, trace)
          rescue => e
            TingYun::Agent.logger.warn("Failed to set attributes for : #{exception}: ", e)
          end
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tingyun_rpm-1.1.4.2 lib/ting_yun/instrumentation/support/external_error.rb
tingyun_rpm-1.1.4.1 lib/ting_yun/instrumentation/support/external_error.rb
tingyun_rpm-1.1.4 lib/ting_yun/instrumentation/support/external_error.rb
tingyun_rpm-1.1.3 lib/ting_yun/instrumentation/support/external_error.rb
tingyun_rpm-1.1.2 lib/ting_yun/instrumentation/support/external_error.rb
tingyun_rpm-1.1.1 lib/ting_yun/instrumentation/support/external_error.rb
tingyun_rpm-1.1.0 lib/ting_yun/instrumentation/support/external_error.rb