Sha256: 7dae1ebcd99d04cde50739f664880048106319a2b257fbed2801af0bee3e76d2

Contents?: true

Size: 1.99 KB

Versions: 7

Compression:

Stored size: 1.99 KB

Contents

require 'ddtrace/contrib/patcher'
require 'ddtrace/contrib/active_support/cache/instrumentation'

module Datadog
  module Contrib
    module ActiveSupport
      module Cache
        # Patcher enables patching of 'active_support' module.
        module Patcher
          include Contrib::Patcher

          module_function

          def target_version
            Integration.version
          end

          def patch
            patch_cache_store_read
            patch_cache_store_read_multi
            patch_cache_store_fetch
            patch_cache_store_fetch_multi
            patch_cache_store_write
            patch_cache_store_write_multi
            patch_cache_store_delete
          end

          def cache_store_class(meth)
            ::ActiveSupport::Cache::Store
          end

          def patch_cache_store_read
            cache_store_class(:read).send(:prepend, Cache::Instrumentation::Read)
          end

          def patch_cache_store_read_multi
            cache_store_class(:read_multi).send(:prepend, Cache::Instrumentation::ReadMulti)
          end

          def patch_cache_store_fetch
            cache_store_class(:fetch).send(:prepend, Cache::Instrumentation::Fetch)
          end

          def patch_cache_store_fetch_multi
            klass = cache_store_class(:fetch_multi)
            return unless klass.public_method_defined?(:fetch_multi)

            klass.send(:prepend, Cache::Instrumentation::FetchMulti)
          end

          def patch_cache_store_write
            cache_store_class(:write).send(:prepend, Cache::Instrumentation::Write)
          end

          def patch_cache_store_write_multi
            klass = cache_store_class(:write_multi)
            return unless klass.public_method_defined?(:write_multi)

            klass.send(:prepend, Cache::Instrumentation::WriteMulti)
          end

          def patch_cache_store_delete
            cache_store_class(:delete).send(:prepend, Cache::Instrumentation::Delete)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ddtrace-0.49.0 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.48.0 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.47.0 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.46.0 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.45.0 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.44.0 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.43.0 lib/ddtrace/contrib/active_support/cache/patcher.rb