Skip to content

Commit 1f30c80

Browse files
committed
Refactor patching to use define_method
1 parent 049c179 commit 1f30c80

File tree

1 file changed

+5
-11
lines changed
  • instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches

1 file changed

+5
-11
lines changed

instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/querying.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,11 @@ class << base
1818

1919
# Contains ActiveRecord::Querying to be patched
2020
module ClassMethods
21-
if ::ActiveRecord.version >= Gem::Version.new('7.0.0')
22-
def _query_by_sql(...)
23-
tracer.in_span("#{self} query") do
24-
super
25-
end
26-
end
27-
else
28-
def find_by_sql(...)
29-
tracer.in_span("#{self} query") do
30-
super
31-
end
21+
method_name = ::ActiveRecord.version >= Gem::Version.new('7.0.0') ? :_query_by_sql : :find_by_sql
22+
23+
define_method(method_name) do |*args, **kwargs|
24+
tracer.in_span("#{self} query") do
25+
super(*args, **kwargs)
3226
end
3327
end
3428

0 commit comments

Comments
 (0)