Module: Datadog::AppSec::Contrib::ActiveRecord::Patcher

Includes:
Patcher
Defined in:
lib/datadog/appsec/contrib/active_record/patcher.rb

Overview

AppSec patcher module for ActiveRecord

Class Method Summary collapse

Class Method Details

.patchObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/datadog/appsec/contrib/active_record/patcher.rb', line 24

def patch
  ActiveSupport.on_load :active_record do
    instrumentation_module = if ::ActiveRecord.gem_version >= Gem::Version.new('7.1')
                               Instrumentation::InternalExecQueryAdapterPatch
                             else
                               Instrumentation::ExecQueryAdapterPatch
                             end

    if defined?(::ActiveRecord::ConnectionAdapters::SQLite3Adapter)
      ::ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend(instrumentation_module)
    end

    if defined?(::ActiveRecord::ConnectionAdapters::Mysql2Adapter)
      ::ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(instrumentation_module)
    end

    if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
      unless defined?(::ActiveRecord::ConnectionAdapters::JdbcAdapter)
        instrumentation_module = Instrumentation::ExecuteAndClearAdapterPatch
      end

      ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(instrumentation_module)
    end
  end
end

.patched?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/datadog/appsec/contrib/active_record/patcher.rb', line 16

def patched?
  Patcher.instance_variable_get(:@patched)
end

.target_versionObject



20
21
22
# File 'lib/datadog/appsec/contrib/active_record/patcher.rb', line 20

def target_version
  Integration.version
end