From 4d79b293dfe141c65c4b4ea6be1ce8f0b337552f Mon Sep 17 00:00:00 2001 From: Andrew Novoselac Date: Tue, 26 Mar 2024 16:06:03 -0400 Subject: [PATCH] fix: instrumentation/active_record: add :allow_retry option to find_by_sql patch Rails 7.2 (rails/rails@eabcff2) introduces the :allow_retry option for this method, so we need to add it to this patch to maintain compatibility. --- .../active_record/patches/querying.rb | 14 +++++++++++--- ...telemetry-instrumentation-active_record.gemspec | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/querying.rb b/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/querying.rb index d359c31ffd..a43038c675 100644 --- a/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/querying.rb +++ b/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/querying.rb @@ -18,9 +18,17 @@ class << base # Contains ActiveRecord::Querying to be patched module ClassMethods - def find_by_sql(sql, binds = [], preparable: nil, &block) - tracer.in_span("#{self}.find_by_sql") do - super + if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("7.2.0.alpha") + def find_by_sql(sql, binds = [], preparable: nil, allow_retry: false, &block) + tracer.in_span("#{self}.find_by_sql") do + super + end + end + else + def find_by_sql(sql, binds = [], preparable: nil, &block) + tracer.in_span("#{self}.find_by_sql") do + super + end end end diff --git a/instrumentation/active_record/opentelemetry-instrumentation-active_record.gemspec b/instrumentation/active_record/opentelemetry-instrumentation-active_record.gemspec index bb89086e1a..af54aa0ee1 100644 --- a/instrumentation/active_record/opentelemetry-instrumentation-active_record.gemspec +++ b/instrumentation/active_record/opentelemetry-instrumentation-active_record.gemspec @@ -34,6 +34,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'minitest', '~> 5.0' spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1' spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3' + spec.add_development_dependency 'rails', '>= 6.1' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rubocop', '~> 1.60.1' spec.add_development_dependency 'rubocop-performance', '~> 1.20'