Skip to content

Commit 46cc35c

Browse files
authored
fix: add max supported version for active record (#1036)
* fix: add max supported version for active record * fix: handle pre-release versions
1 parent bf12dcc commit 46cc35c

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

instrumentation/active_record/gemfiles/activerecord_5.2.gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
source "https://rubygems.org"
44

55
gem "opentelemetry-api", path: "../../../api"
6+
gem "opentelemetry-instrumentation-base", path: "../../base"
67
gem "activerecord", "~> 5.2.0"
78

89
group :test do
910
gem "byebug"
10-
gem "mysql2"
1111
gem "opentelemetry-common", path: "../../../common"
12-
gem "opentelemetry-instrumentation-mysql2", path: "../../mysql2"
1312
gem "opentelemetry-sdk", path: "../../../sdk"
13+
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
1414
gem "pry-byebug"
15+
gem "sqlite3-ruby"
1516
end
1617

1718
gemspec path: "../"

instrumentation/active_record/gemfiles/activerecord_6.0.gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ gem "activerecord", "~> 6.0.0"
88

99
group :test do
1010
gem "byebug"
11-
gem "sqlite3-ruby"
1211
gem "opentelemetry-common", path: "../../../common"
1312
gem "opentelemetry-sdk", path: "../../../sdk"
13+
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
1414
gem "pry-byebug"
15+
gem "sqlite3-ruby"
1516
end
1617

1718
gemspec path: "../"

instrumentation/active_record/gemfiles/activerecord_6.1.gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ gem "activerecord", "~> 6.1.0"
88

99
group :test do
1010
gem "byebug"
11-
gem "sqlite3-ruby"
1211
gem "opentelemetry-common", path: "../../../common"
1312
gem "opentelemetry-sdk", path: "../../../sdk"
13+
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
1414
gem "pry-byebug"
15+
gem "sqlite3-ruby"
1516
end
1617

1718
gemspec path: "../"

instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/instrumentation.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module ActiveRecord
1010
# The Instrumentation class contains logic to detect and install the ActiveRecord instrumentation
1111
class Instrumentation < OpenTelemetry::Instrumentation::Base
1212
MINIMUM_VERSION = Gem::Version.new('5.2.0')
13+
MAX_MAJOR_VERSION = 6
1314

1415
install do |_config|
1516
require_dependencies
@@ -21,7 +22,11 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2122
end
2223

2324
compatible do
24-
gem_version >= MINIMUM_VERSION
25+
# We know that releases after MAX_MAJOR_VERSION are unstable so we
26+
# check the major version number of the gem installed to make sure we
27+
# do not install on a pre-release or full release of the latest
28+
# if it exceeds the MAX_MAJOR_VERSION version.
29+
gem_version >= MINIMUM_VERSION && gem_version.segments[0] <= MAX_MAJOR_VERSION
2530
end
2631

2732
private

instrumentation/active_record/test/instrumentation/active_record/instrumentation_test.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,24 @@
2222
end
2323

2424
describe 'compatible' do
25-
it 'when unsupported gem version is installed' do
25+
it 'when a version below the minimum supported gem version is installed' do
2626
Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = '4.2.0' }) do
2727
_(instrumentation.compatible?).must_equal false
2828
end
2929
end
3030

31+
it 'when a version above the maximum supported gem version is installed' do
32+
Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = '7.0.0' }) do
33+
_(instrumentation.compatible?).must_equal false
34+
end
35+
end
36+
37+
it 'it treats pre releases as being equivalent to a full release' do
38+
Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = '7.0.0.alpha' }) do
39+
_(instrumentation.compatible?).must_equal false
40+
end
41+
end
42+
3143
it 'when supported gem version installed' do
3244
Gem.stub(:loaded_specs, 'activerecord' => Gem::Specification.new { |s| s.version = minimum_version }) do
3345
_(instrumentation.compatible?).must_equal true

0 commit comments

Comments
 (0)