Sha256: 8b219aedb252d4146dbdeb7df9ecc691853fd425775a65d94b45ca50ffff56bd

Contents?: true

Size: 1.75 KB

Versions: 13

Compression:

Stored size: 1.75 KB

Contents

require 'skylight/formatters/http'

module Skylight
  module Probes
    module Excon

      # Middleware for Excon that instruments requests
      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)
            if request = @requests.delete(datum.object_id)
              Skylight.done(request)
            end
          rescue Exception => e
            error "failed to end instrumentation for Excon; msg=%s", e.message
          end

      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
skylight-1.7.2 lib/skylight/probes/excon/middleware.rb
skylight-1.7.1 lib/skylight/probes/excon/middleware.rb
skylight-1.7.0 lib/skylight/probes/excon/middleware.rb
skylight-1.6.1 lib/skylight/probes/excon/middleware.rb
skylight-1.6.0 lib/skylight/probes/excon/middleware.rb
skylight-1.5.1 lib/skylight/probes/excon/middleware.rb
skylight-1.5.0 lib/skylight/probes/excon/middleware.rb
skylight-1.4.4 lib/skylight/probes/excon/middleware.rb
skylight-1.4.3 lib/skylight/probes/excon/middleware.rb
skylight-1.4.2 lib/skylight/probes/excon/middleware.rb
skylight-1.4.1 lib/skylight/probes/excon/middleware.rb
skylight-1.4.0 lib/skylight/probes/excon/middleware.rb
skylight-1.4.0.beta.2 lib/skylight/probes/excon/middleware.rb