Skip to content

Commit aa39abc

Browse files
committed
Fix ActiveRecord adapter patching for Postgres with JDBC
1 parent 320f1f1 commit aa39abc

File tree

1 file changed

+11
-5
lines changed
  • lib/datadog/appsec/contrib/active_record

1 file changed

+11
-5
lines changed

lib/datadog/appsec/contrib/active_record/patcher.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,22 @@ def patch_mysql2_adapter
7676
end
7777

7878
def patch_postgresql_adapter
79-
jdbc_defined = defined?(::ActiveRecord::ConnectionAdapters::JdbcAdapter)
80-
81-
instrumentation_module = if jdbc_defined && ::ActiveRecord.gem_version >= Gem::Version.new('7.1')
82-
Instrumentation::InternalExecQueryAdapterPatch
83-
elsif jdbc_defined && ::ActiveRecord.gem_version.segments.first == 4
79+
instrumentation_module = if ::ActiveRecord.gem_version.segments.first == 4
8480
Instrumentation::Rails4ExecuteAndClearAdapterPatch
8581
else
8682
Instrumentation::ExecuteAndClearAdapterPatch
8783
end
8884

85+
if defined?(::ActiveRecord::ConnectionAdapters::JdbcAdapter)
86+
instrumentation_module = if ::ActiveRecord.gem_version >= Gem::Version.new('7.1')
87+
Instrumentation::InternalExecQueryAdapterPatch
88+
elsif ::ActiveRecord.gem_version.segments.first == 4
89+
Instrumentation::Rails4ExecQueryAdapterPatch
90+
else
91+
Instrumentation::ExecQueryAdapterPatch
92+
end
93+
end
94+
8995
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(instrumentation_module)
9096
end
9197
end

0 commit comments

Comments
 (0)