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



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/ddtrace/contrib/rails/core_extensions.rb', line 75

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

  # by default, Rails 3 doesn't instrument the cache system so we should turn it on
  # using the ActiveSupport::Cache::Store.instrument= function. Unfortunately, early
  # versions of Rails use a Thread.current store that is not compatible with some
  # application servers like Passenger.
  # More details: https://github.com/rails/rails/blob/v3.2.22.5/activesupport/lib/active_support/cache.rb#L175-L177
  return unless ::Rails::VERSION::MAJOR.to_i == 3
  ::ActiveSupport::Cache::Store.singleton_class.prepend Datadog::CacheInstrumentExtension
end

.patch_rendererObject



70
71
72
73
# File 'lib/ddtrace/contrib/rails/core_extensions.rb', line 70

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