Module: Datadog::RailsPatcher

Defined in:
lib/ddtrace/contrib/rails/core_extensions.rb

Overview

RailsPatcher contains function to patch the Rails libraries.

Class Method Summary collapse

Class Method Details

.patch_cache_storeObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ddtrace/contrib/rails/core_extensions.rb', line 66

def patch_cache_store
  # When Redis is used, we can't only patch Cache::Store as it is
  # Cache::RedisStore, a sub-class of it that is used, in practice.
  # We need to do a per-method monkey patching as some of them might
  # be redefined, and some of them not. The latest version of redis-activesupport
  # redefines write but leaves untouched read and delete:
  # https://github.com/redis-store/redis-activesupport/blob/master/lib/active_support/cache/redis_store.rb

  { read: Datadog::CacheStoreReadExtension,
    fetch: Datadog::CacheStoreFetchExtension,
    write: Datadog::CacheStoreWriteExtension,
    delete: Datadog::CacheStoreDeleteExtension }.each do |k, v|
    c = if defined?(::ActiveSupport::Cache::RedisStore) &&
           ::ActiveSupport::Cache::RedisStore.instance_methods(false).include?(k)
          ::ActiveSupport::Cache::RedisStore
        else
          ::ActiveSupport::Cache::Store
        end
    Datadog::Tracer.log.debug("monkey patching #{c}.#{k} with #{v}.#{k}")
    c.prepend v
  end
end

.patch_rendererObject



61
62
63
64
# File 'lib/ddtrace/contrib/rails/core_extensions.rb', line 61

def patch_renderer
  ::ActionView::Renderer.prepend Datadog::RendererExtension
  ::ActionView::PartialRenderer.prepend Datadog::PartialRendererExtension
end