diff --git a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb index 3e1341c48..7164f4226 100644 --- a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb +++ b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb @@ -30,7 +30,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base private def gem_version - Gem.loaded_specs['actionpack']&.version || ::ActionPack.version + ::ActionPack.version end def patch diff --git a/instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/instrumentation.rb b/instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/instrumentation.rb index 0dcab4a52..9124b27d4 100644 --- a/instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/instrumentation.rb +++ b/instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/instrumentation.rb @@ -28,7 +28,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base private def gem_version - Gem.loaded_specs['actionview'].version || ::ActionView.version + ::ActionView.version end def require_dependencies diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb index 156b540e3..2ed7c381a 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb @@ -59,7 +59,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base private def gem_version - Gem.loaded_specs['activejob']&.version || ::ActiveJob.version + ::ActiveJob.version end def require_dependencies diff --git a/instrumentation/active_job/test/instrumentation/active_job/instrumentation_test.rb b/instrumentation/active_job/test/instrumentation/active_job/instrumentation_test.rb index c73e3d170..4cb9c80f4 100644 --- a/instrumentation/active_job/test/instrumentation/active_job/instrumentation_test.rb +++ b/instrumentation/active_job/test/instrumentation/active_job/instrumentation_test.rb @@ -23,15 +23,13 @@ describe '#compatible' do it 'returns false for unsupported gem versions' do - Gem.stub(:loaded_specs, 'activejob' => Gem::Specification.new { |s| s.version = '4.2.0' }) do + ::ActiveJob.stub(:version, Gem::Version.new('4.2.0')) do _(instrumentation.compatible?).must_equal false end end it 'returns true for supported gem versions' do - Gem.stub(:loaded_specs, 'activejob' => Gem::Specification.new { |s| s.version = minimum_version }) do - _(instrumentation.compatible?).must_equal true - end + _(instrumentation.compatible?).must_equal true end end diff --git a/instrumentation/active_model_serializers/lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb b/instrumentation/active_model_serializers/lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb index a024fc088..453f9e092 100644 --- a/instrumentation/active_model_serializers/lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb +++ b/instrumentation/active_model_serializers/lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb @@ -27,7 +27,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base private def gem_version - Gem.loaded_specs['active_model_serializers']&.version || Gem::Version.new(::ActiveModel::Serializer::VERSION) + Gem::Version.new(::ActiveModel::Serializer::VERSION) end def require_dependencies diff --git a/instrumentation/active_model_serializers/test/opentelemetry/instrumentation/active_model_serializers_test.rb b/instrumentation/active_model_serializers/test/opentelemetry/instrumentation/active_model_serializers_test.rb index 0ae686852..d60ef429a 100644 --- a/instrumentation/active_model_serializers/test/opentelemetry/instrumentation/active_model_serializers_test.rb +++ b/instrumentation/active_model_serializers/test/opentelemetry/instrumentation/active_model_serializers_test.rb @@ -30,12 +30,11 @@ describe 'compatible' do it 'when older gem version installed' do - allow_any_instance_of(Bundler::StubSpecification).to receive(:version).and_return(Gem::Version.new('0.9.4')) + stub_const('::ActiveModel::Serializer::VERSION', '0.9.4') _(instrumentation.compatible?).must_equal false end it 'when future gem version installed' do - allow_any_instance_of(Bundler::StubSpecification).to receive(:version).and_return(Gem::Version.new('0.11.0')) _(instrumentation.compatible?).must_equal true end end 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 0369b76a3..4561d9f06 100644 --- a/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/instrumentation.rb +++ b/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/instrumentation.rb @@ -36,7 +36,7 @@ def insert_class_methods_supported? end def gem_version - Gem.loaded_specs['activerecord']&.version || ::ActiveRecord.version + ::ActiveRecord.version end def patch 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 aa056bd48..546ac39a9 100644 --- a/instrumentation/active_record/test/instrumentation/active_record/instrumentation_test.rb +++ b/instrumentation/active_record/test/instrumentation/active_record/instrumentation_test.rb @@ -23,27 +23,25 @@ describe 'compatible' do it 'when a version below the minimum supported gem version is installed' do - Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = '4.2.0' }) do + ActiveRecord.stub(:version, Gem::Version.new('4.2.0')) do _(instrumentation.compatible?).must_equal false end 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 = '8.0.0' }) do + ActiveRecord.stub(:version, Gem::Version.new('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 = '8.0.0.alpha' }) do + ActiveRecord.stub(:version, Gem::Version.new('8.0.0.alpha')) do _(instrumentation.compatible?).must_equal false end end it 'when supported gem version installed' do - Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = minimum_version }) do - _(instrumentation.compatible?).must_equal true - end + _(instrumentation.compatible?).must_equal true end end diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb index b163d01f5..23f49775f 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb @@ -28,7 +28,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base option :suppress_internal_instrumentation, default: false, validate: :boolean def gem_version - Gem.loaded_specs['aws-sdk']&.version || Gem.loaded_specs['aws-sdk-core']&.version || Gem::Version.new(::Aws::CORE_GEM_VERSION) + Gem::Version.new(::Aws::CORE_GEM_VERSION) end private diff --git a/instrumentation/aws_sdk/test/opentelemetry/instrumentation_test.rb b/instrumentation/aws_sdk/test/opentelemetry/instrumentation_test.rb index 5e79d4eb4..5bee33557 100644 --- a/instrumentation/aws_sdk/test/opentelemetry/instrumentation_test.rb +++ b/instrumentation/aws_sdk/test/opentelemetry/instrumentation_test.rb @@ -23,15 +23,13 @@ describe '#compatible' do it 'returns false for unsupported gem versions' do - Gem.stub(:loaded_specs, 'aws-sdk' => Gem::Specification.new { |s| s.version = '1.0.0' }) do + stub_const('::Aws::CORE_GEM_VERSION', Gem::Version.new('1.0.0')) do _(instrumentation.compatible?).must_equal false end end it 'returns true for supported gem versions' do - Gem.stub(:loaded_specs, 'aws-sdk' => Gem::Specification.new { |s| s.version = minimum_version }) do - _(instrumentation.compatible?).must_equal true - end + _(instrumentation.compatible?).must_equal true end end diff --git a/instrumentation/aws_sdk/test/test_helper.rb b/instrumentation/aws_sdk/test/test_helper.rb index c5182f5b8..8a5b1b6b8 100644 --- a/instrumentation/aws_sdk/test/test_helper.rb +++ b/instrumentation/aws_sdk/test/test_helper.rb @@ -9,6 +9,7 @@ require 'opentelemetry/sdk' require 'minitest/autorun' +require 'rspec/mocks/minitest_integration' # global opentelemetry-sdk setup: EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new diff --git a/instrumentation/base/lib/opentelemetry/instrumentation/base.rb b/instrumentation/base/lib/opentelemetry/instrumentation/base.rb index af1d7f887..0fdee7356 100644 --- a/instrumentation/base/lib/opentelemetry/instrumentation/base.rb +++ b/instrumentation/base/lib/opentelemetry/instrumentation/base.rb @@ -32,7 +32,7 @@ module Instrumentation # # # if the target library is present, is it compatible? # compatible do - # (Gem.loaded_specs['sinatra']&.version || Gem::Version.new(Sinatra::VERSION)) > MIN_VERSION + # Gem::Version.new(Sinatra::VERSION)) > MIN_VERSION # end # end # end diff --git a/instrumentation/mongo/lib/opentelemetry/instrumentation/mongo/instrumentation.rb b/instrumentation/mongo/lib/opentelemetry/instrumentation/mongo/instrumentation.rb index ec3fb6348..e0627ad6c 100644 --- a/instrumentation/mongo/lib/opentelemetry/instrumentation/mongo/instrumentation.rb +++ b/instrumentation/mongo/lib/opentelemetry/instrumentation/mongo/instrumentation.rb @@ -30,7 +30,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base private def gem_version - Gem.loaded_specs['mongo']&.version || Gem::Version.new(::Mongo::VERSION) + Gem::Version.new(::Mongo::VERSION) end def require_dependencies diff --git a/instrumentation/mongo/test/opentelemetry/instrumentation/mongo_test.rb b/instrumentation/mongo/test/opentelemetry/instrumentation/mongo_test.rb index e9dfe9c95..5f7ef3cd5 100644 --- a/instrumentation/mongo/test/opentelemetry/instrumentation/mongo_test.rb +++ b/instrumentation/mongo/test/opentelemetry/instrumentation/mongo_test.rb @@ -35,12 +35,11 @@ describe 'compatible' do it 'when older gem version installed' do - allow_any_instance_of(Bundler::StubSpecification).to receive(:version).and_return(Gem::Version.new('2.4.3')) + stub_const('::Mongo::VERSION', '2.4.3') _(instrumentation.compatible?).must_equal false end it 'when future gem version installed' do - allow_any_instance_of(Bundler::StubSpecification).to receive(:version).and_return(Gem::Version.new('3.0.0')) _(instrumentation.compatible?).must_equal true end end diff --git a/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb b/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb index 0f7af067c..528a3b360 100644 --- a/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb +++ b/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb @@ -37,7 +37,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base end compatible do - Gem.loaded_specs['pg'].version > Gem::Version.new(MINIMUM_VERSION) + gem_version > Gem::Version.new(MINIMUM_VERSION) end option :peer_service, default: nil, validate: :string @@ -48,7 +48,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base private def gem_version - Gem.loaded_specs['pg']&.version || Gem::Version.new(::PG::VERSION) + Gem::Version.new(::PG::VERSION) end def require_dependencies diff --git a/instrumentation/que/lib/opentelemetry/instrumentation/que/instrumentation.rb b/instrumentation/que/lib/opentelemetry/instrumentation/que/instrumentation.rb index c32209ebd..daafa1f20 100644 --- a/instrumentation/que/lib/opentelemetry/instrumentation/que/instrumentation.rb +++ b/instrumentation/que/lib/opentelemetry/instrumentation/que/instrumentation.rb @@ -58,7 +58,7 @@ def require_dependencies end def gem_version - Gem.loaded_specs['que']&.version || Gem::Version.new(::Que::VERSION) + Gem::Version.new(::Que::VERSION) end def patch diff --git a/instrumentation/rails/lib/opentelemetry/instrumentation/rails/instrumentation.rb b/instrumentation/rails/lib/opentelemetry/instrumentation/rails/instrumentation.rb index 3ac7030c8..c738e6cb4 100644 --- a/instrumentation/rails/lib/opentelemetry/instrumentation/rails/instrumentation.rb +++ b/instrumentation/rails/lib/opentelemetry/instrumentation/rails/instrumentation.rb @@ -24,7 +24,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base private def gem_version - Gem.loaded_specs['actionpack'].version + ::ActionPack.version end end end diff --git a/instrumentation/ruby_kafka/lib/opentelemetry/instrumentation/ruby_kafka/instrumentation.rb b/instrumentation/ruby_kafka/lib/opentelemetry/instrumentation/ruby_kafka/instrumentation.rb index a975254c0..795f2d9a1 100644 --- a/instrumentation/ruby_kafka/lib/opentelemetry/instrumentation/ruby_kafka/instrumentation.rb +++ b/instrumentation/ruby_kafka/lib/opentelemetry/instrumentation/ruby_kafka/instrumentation.rb @@ -28,7 +28,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base private def gem_version - Gem.loaded_specs['ruby-kafka']&.version || Gem::Version.new(Kafka::VERSION) + Gem::Version.new(Kafka::VERSION) end def require_patches diff --git a/instrumentation/ruby_kafka/test/opentelemetry/instrumentation/ruby-kafka/instrumentation_test.rb b/instrumentation/ruby_kafka/test/opentelemetry/instrumentation/ruby-kafka/instrumentation_test.rb index 747ed4245..57ce1f98f 100644 --- a/instrumentation/ruby_kafka/test/opentelemetry/instrumentation/ruby-kafka/instrumentation_test.rb +++ b/instrumentation/ruby_kafka/test/opentelemetry/instrumentation/ruby-kafka/instrumentation_test.rb @@ -33,15 +33,12 @@ describe 'compatible' do it 'when older gem version installed' do - Gem.stub(:loaded_specs, 'ruby-kafka' => Gem::Specification.new { |s| s.version = '0.6.8' }) do - _(instrumentation.compatible?).must_equal false - end + stub_const('Kafka::VERSION', '0.6.8') + _(instrumentation.compatible?).must_equal false end it 'when future gem version installed' do - Gem.stub(:loaded_specs, 'ruby-kafka' => Gem::Specification.new { |s| s.version = '1.7.0' }) do - _(instrumentation.compatible?).must_equal true - end + _(instrumentation.compatible?).must_equal true end describe 'when the installing application bypasses RubyGems' do diff --git a/instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/instrumentation.rb b/instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/instrumentation.rb index a275f422a..0101c5fd9 100644 --- a/instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/instrumentation.rb +++ b/instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/instrumentation.rb @@ -38,7 +38,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base private def gem_version - Gem.loaded_specs['sidekiq']&.version || Gem::Version.new(::Sidekiq::VERSION) + Gem::Version.new(::Sidekiq::VERSION) end def require_dependencies diff --git a/instrumentation/sidekiq/opentelemetry-instrumentation-sidekiq.gemspec b/instrumentation/sidekiq/opentelemetry-instrumentation-sidekiq.gemspec index c64f993a7..6d463e38e 100644 --- a/instrumentation/sidekiq/opentelemetry-instrumentation-sidekiq.gemspec +++ b/instrumentation/sidekiq/opentelemetry-instrumentation-sidekiq.gemspec @@ -33,6 +33,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '>= 1.17' spec.add_development_dependency 'minitest', '~> 5.0' spec.add_development_dependency 'opentelemetry-sdk', '~> 1.0' + spec.add_development_dependency 'rspec-mocks' spec.add_development_dependency 'rubocop', '~> 0.73.0' spec.add_development_dependency 'sidekiq', '~> 5.2.0' spec.add_development_dependency 'simplecov', '~> 0.17.1' diff --git a/instrumentation/sidekiq/test/opentelemetry/instrumentation/sidekiq/instrumentation_test.rb b/instrumentation/sidekiq/test/opentelemetry/instrumentation/sidekiq/instrumentation_test.rb index fe6b2dec9..72d50e62b 100644 --- a/instrumentation/sidekiq/test/opentelemetry/instrumentation/sidekiq/instrumentation_test.rb +++ b/instrumentation/sidekiq/test/opentelemetry/instrumentation/sidekiq/instrumentation_test.rb @@ -21,9 +21,8 @@ describe 'compatible' do it 'when older gem version installed' do - Gem.stub(:loaded_specs, 'sidekiq' => Gem::Specification.new { |s| s.version = '4.2.8' }) do - _(instrumentation.compatible?).must_equal false - end + stub_const('::Sidekiq::VERSION', '4.2.8') + _(instrumentation.compatible?).must_equal false end it 'when future gem version installed' do diff --git a/instrumentation/sidekiq/test/test_helper.rb b/instrumentation/sidekiq/test/test_helper.rb index 9f58249e3..bff1b0b39 100644 --- a/instrumentation/sidekiq/test/test_helper.rb +++ b/instrumentation/sidekiq/test/test_helper.rb @@ -9,6 +9,7 @@ require 'opentelemetry/sdk' require 'minitest/autorun' +require 'rspec/mocks/minitest_integration' require 'helpers/mock_loader' require 'active_job' require 'pry'