# encoding: utf-8 LibraryDetection.defer do named :excon # We have two ways of instrumenting Excon: # - For newer versions, use the middleware mechanism Excon exposes # - For older versions, monkey-patch Excon::Connection#request # # EXCON_MINIMUM_VERSION is the minimum version we attempt to instrument at all. # EXCON_MIDDLEWARE_MINIMUM_VERSION is the min version we use the newer # instrumentation for. # # Note that middlewares were added to Excon prior to 0.19, but we don't # use middleware-based instrumentation prior to that version because it didn't # expose a way for middlewares to know about request failures. # # Why don't we use Excon.defaults[:instrumentor]? # While this might seem a perfect fit, it unfortunately isn't suitable in # current form. Someone might reasonably set the default instrumentor to # something else after we install our instrumentation. Ideally, excon would # itself conform to the #subscribe interface of ActiveSupport::Notifications, # so we could safely subscribe and not be clobbered by future subscribers, # but alas, it does not yet. EXCON_MINIMUM_VERSION = ::OneApm::VersionNumber.new("0.10.1") EXCON_MIDDLEWARE_MINIMUM_VERSION = ::OneApm::VersionNumber.new("0.19.0") depends_on do defined?(::Excon) && defined?(::Excon::VERSION) end executes do excon_version = OneApm::VersionNumber.new(::Excon::VERSION) if excon_version >= EXCON_MINIMUM_VERSION install_excon_instrumentation(excon_version) else OneApm::Manager.logger.warn("Excon instrumentation requires at least version #{EXCON_MINIMUM_VERSION}") end end def install_excon_instrumentation(excon_version) require 'one_apm/agent/cross_app/cross_app_tracing' require 'one_apm/support/http_clients/excon_wrappers' if excon_version >= EXCON_MIDDLEWARE_MINIMUM_VERSION install_middleware_excon_instrumentation else install_legacy_excon_instrumentation end end def install_middleware_excon_instrumentation OneApm::Manager.logger.info 'Installing middleware-based Excon instrumentation' require 'one_apm/inst/http_clients/excon/middleware' defaults = Excon.defaults if defaults[:middlewares] defaults[:middlewares] << ::Excon::Middleware::OneApmCrossAppTracing else OneApm::Manager.logger.warn("Did not find :middlewares key in Excon.defaults, skipping Excon instrumentation") end end def install_legacy_excon_instrumentation OneApm::Manager.logger.info 'Installing legacy Excon instrumentation' require 'one_apm/inst/http_clients/excon/connection' ::Excon::Connection.install_oneapm_instrumentation end end