diff --git a/instrumentation/active_record/Appraisals b/instrumentation/active_record/Appraisals index d9618fec1..5af31f8ff 100644 --- a/instrumentation/active_record/Appraisals +++ b/instrumentation/active_record/Appraisals @@ -14,8 +14,14 @@ end # Rails 5.2 is not compatible with Ruby 3.0 # https://github.com/rails/rails/issues/40938 -if RUBY_VERSION < '3' +if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3') appraise 'activerecord-5.2' do gem 'activerecord', '~> 5.2.0' end end + +if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') + appraise 'activerecord-7.0' do + gem 'activerecord', '~> 7.0.0' + end +end diff --git a/instrumentation/active_record/gemfiles/activerecord_7.0.gemfile b/instrumentation/active_record/gemfiles/activerecord_7.0.gemfile new file mode 100644 index 000000000..8d2182128 --- /dev/null +++ b/instrumentation/active_record/gemfiles/activerecord_7.0.gemfile @@ -0,0 +1,18 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "opentelemetry-api", path: "../../../api" +gem "opentelemetry-instrumentation-base", path: "../../base" +gem "activerecord", "~> 7.0.0" + +group :test do + gem "byebug" + gem "opentelemetry-common", path: "../../../common" + gem "opentelemetry-sdk", path: "../../../sdk" + gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions" + gem "pry-byebug" + gem "sqlite3-ruby" +end + +gemspec path: "../" diff --git a/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/instrumentation.rb b/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/instrumentation.rb index b2f22f6fe..8d60c53d2 100644 --- a/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/instrumentation.rb +++ b/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/instrumentation.rb @@ -10,7 +10,7 @@ module ActiveRecord # The Instrumentation class contains logic to detect and install the ActiveRecord instrumentation class Instrumentation < OpenTelemetry::Instrumentation::Base MINIMUM_VERSION = Gem::Version.new('5.2.0') - MAX_MAJOR_VERSION = 6 + MAX_MAJOR_VERSION = 7 install do |_config| require_dependencies @@ -60,6 +60,7 @@ def patch end def require_dependencies + require 'ruby2_keywords' require_relative 'patches/querying' require_relative 'patches/persistence' require_relative 'patches/persistence_class_methods' diff --git a/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb b/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb index 8701f6773..6354ee0be 100644 --- a/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb +++ b/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb @@ -3,7 +3,6 @@ # Copyright The OpenTelemetry Authors # # SPDX-License-Identifier: Apache-2.0 - module OpenTelemetry module Instrumentation module ActiveRecord @@ -19,39 +18,39 @@ class << base # Contains ActiveRecord::Persistence::ClassMethods to be patched module ClassMethods - def insert(attributes, returning: nil, unique_by: nil) + ruby2_keywords def insert(*args) tracer.in_span("#{self}.insert") do - super + super(*args) end end - def insert_all(attributes, returning: nil, unique_by: nil) + ruby2_keywords def insert_all(*args) tracer.in_span("#{self}.insert_all") do - super + super(*args) end end - def insert!(attributes, returning: nil) + ruby2_keywords def insert!(*args) tracer.in_span("#{self}.insert!") do - super + super(*args) end end - def insert_all!(attributes, returning: nil) + ruby2_keywords def insert_all!(*args) tracer.in_span("#{self}.insert_all!") do - super + super(*args) end end - def upsert(attributes, returning: nil, unique_by: nil) + ruby2_keywords def upsert(*args) tracer.in_span("#{self}.upsert") do - super + super(*args) end end - def upsert_all(attributes, returning: nil, unique_by: nil) + ruby2_keywords def upsert_all(*args) tracer.in_span("#{self}.upsert_all") do - super + super(*args) end end diff --git a/instrumentation/active_record/opentelemetry-instrumentation-active_record.gemspec b/instrumentation/active_record/opentelemetry-instrumentation-active_record.gemspec index 5bf73c206..9333dce50 100644 --- a/instrumentation/active_record/opentelemetry-instrumentation-active_record.gemspec +++ b/instrumentation/active_record/opentelemetry-instrumentation-active_record.gemspec @@ -27,6 +27,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'opentelemetry-api', '~> 1.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.19.0' + spec.add_dependency 'ruby2_keywords' spec.add_development_dependency 'activerecord' spec.add_development_dependency 'appraisal', '~> 2.2.0' diff --git a/instrumentation/active_record/test/instrumentation/active_record/instrumentation_test.rb b/instrumentation/active_record/test/instrumentation/active_record/instrumentation_test.rb index b61b6e2a3..aa056bd48 100644 --- a/instrumentation/active_record/test/instrumentation/active_record/instrumentation_test.rb +++ b/instrumentation/active_record/test/instrumentation/active_record/instrumentation_test.rb @@ -29,13 +29,13 @@ end it 'when a version above the maximum supported gem version is installed' do - Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = '7.0.0' }) do + Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = '8.0.0' }) do _(instrumentation.compatible?).must_equal false end end it 'it treats pre releases as being equivalent to a full release' do - Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = '7.0.0.alpha' }) do + Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = '8.0.0.alpha' }) do _(instrumentation.compatible?).must_equal false end end diff --git a/instrumentation/active_record/test/instrumentation/active_record/patches/querying_test.rb b/instrumentation/active_record/test/instrumentation/active_record/patches/querying_test.rb index c429ed8f2..6da620512 100644 --- a/instrumentation/active_record/test/instrumentation/active_record/patches/querying_test.rb +++ b/instrumentation/active_record/test/instrumentation/active_record/patches/querying_test.rb @@ -17,7 +17,7 @@ describe 'find_by_sql' do it 'traces' do - User.first + User.find_by_sql('SELECT * FROM users') find_span = spans.find { |s| s.name == 'User.find_by_sql' } _(find_span).wont_be_nil