Sha256: 7ca0b02c8ec014d725b66d5c5d5a6756fa9390abf65bef69d79fb53aa65341f9

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Datadog
  module Contrib
    module Faraday
      COMPATIBLE_UNTIL = Gem::Version.new('1.0.0')
      SERVICE = 'faraday-request'.freeze

      # Responsible for hooking the instrumentation into faraday
      module Patcher
        include Base
        register_as :faraday, auto_patch: true

        @patched = false

        class << self
          def patch
            return @patched if patched? || !compatible?

            require 'ddtrace/ext/app_types'
            require 'ddtrace/contrib/faraday/middleware'

            add_pin
            add_middleware

            @patched = true
          rescue => e
            Tracer.log.error("Unable to apply Faraday integration: #{e}")
            @patched
          end

          def patched?
            @patched
          end

          private

          def compatible?
            return unless defined?(::Faraday::VERSION)

            Gem::Version.new(::Faraday::VERSION) < COMPATIBLE_UNTIL
          end

          def add_pin
            Pin.new(SERVICE, app_type: Ext::AppTypes::WEB).tap do |pin|
              pin.onto(::Faraday)
            end
          end

          def add_middleware
            ::Faraday::Middleware.register_middleware(ddtrace: Middleware)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ddtrace-0.10.0 lib/ddtrace/contrib/faraday/patcher.rb