Sha256: 54dd7025b51a504c032b94636a3c7c2878d87a4acbe397c7aaa52a5713a5779c

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 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 patched?
            done?(:cache)
          end

          def patch
            do_once(:cache) do
              begin
                patch_cache_store_read
                patch_cache_store_fetch
                patch_cache_store_write
                patch_cache_store_delete
              rescue StandardError => e
                Datadog::Tracer.log.error("Unable to apply Active Support cache integration: #{e}")
              end
            end
          end

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

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

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

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

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

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ls-trace-0.1.2 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.29.1 lib/ddtrace/contrib/active_support/cache/patcher.rb
ls-trace-0.1.1 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.29.0 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.28.0 lib/ddtrace/contrib/active_support/cache/patcher.rb
ddtrace-0.27.0 lib/ddtrace/contrib/active_support/cache/patcher.rb