Sha256: f3569db1bd244dea7b2e74a192a18835cd7ce5b9b47925c7f7bbbbdfa10f1cff

Contents?: true

Size: 1.67 KB

Versions: 28

Compression:

Stored size: 1.67 KB

Contents

require 'skylight/formatters/http'

module Skylight
  module Probes
    module Excon
      class Middleware < ::Excon::Middleware::Base

        # This probably won't work since config isn't defined
        include Util::Logging

        def initialize(*)
          @requests = {}
          super
        end

        # TODO:
        # - Consider whether a LIFO queue would be sufficient
        # - Check that errors can't be called without a request

        def request_call(datum)
          begin_instrumentation(datum)
          super
        end

        def response_call(datum)
          super
        ensure
          end_instrumentation(datum)
        end

        def error_call(datum)
          super
        ensure
          end_instrumentation(datum)
        end

        private

          def begin_instrumentation(datum)
            method = datum[:method].to_s
            scheme = datum[:scheme]
            host   = datum[:host]
            # TODO: Maybe don't show other default ports like 443
            port   = datum[:port] != 80 ? datum[:port] : nil
            path   = datum[:path]
            query  = datum[:query]

            opts = Formatters::HTTP.build_opts(method, scheme, host, port, path, query)

            @requests[datum.object_id] = Skylight.instrument(opts)
          rescue Exception => e
            error "failed to begin instrumentation for Excon; msg=%s", e.message
          end

          def end_instrumentation(datum)
            @requests[datum.object_id].done
            @requests.delete(datum)
          rescue Exception => e
            error "failed to end instrumentation for Excon; msg=%s", e.message
          end

      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
skylight-0.9.3 lib/skylight/probes/excon/middleware.rb
skylight-0.9.2 lib/skylight/probes/excon/middleware.rb
skylight-0.9.1 lib/skylight/probes/excon/middleware.rb
skylight-0.9.0 lib/skylight/probes/excon/middleware.rb
skylight-0.8.1 lib/skylight/probes/excon/middleware.rb
skylight-0.8.0 lib/skylight/probes/excon/middleware.rb
skylight-0.8.0.beta.3 lib/skylight/probes/excon/middleware.rb
skylight-0.8.0.beta.1 lib/skylight/probes/excon/middleware.rb
skylight-0.7.1 lib/skylight/probes/excon/middleware.rb
skylight-0.7.0.beta.3 lib/skylight/probes/excon/middleware.rb
truex-skylight-0.6.0 lib/skylight/probes/excon/middleware.rb
skylight-0.7.0.beta.2 lib/skylight/probes/excon/middleware.rb
skylight-0.7.0.beta.1 lib/skylight/probes/excon/middleware.rb
skylight-0.6.2.beta.2 lib/skylight/probes/excon/middleware.rb
skylight-0.6.1 lib/skylight/probes/excon/middleware.rb
skylight-0.6.0 lib/skylight/probes/excon/middleware.rb
skylight-0.6.0.beta.1 lib/skylight/probes/excon/middleware.rb
skylight-0.5.2 lib/skylight/probes/excon/middleware.rb
skylight-0.5.1 lib/skylight/probes/excon/middleware.rb
skylight-0.5.0 lib/skylight/probes/excon/middleware.rb