Skip to content

Commit

Permalink
feat: RubyGems Fallback
Browse files Browse the repository at this point in the history
The GitHub Monolith bypasses RubyGems when loading dependencies, which results in a `nil` variable being returned by `Gem.loaded_specs`.

This change fallsback to using `Gem::Version.new(<VERSION>)` where possible.

See #947

Related https://github.com/open-telemetry/opentelemetry-ruby/issues/988#issuecomment-1018676853
  • Loading branch information
arielvalentin authored Mar 28, 2022
1 parent 8ed6435 commit fd88fd8
Show file tree
Hide file tree
Showing 53 changed files with 143 additions and 31 deletions.
2 changes: 1 addition & 1 deletion instrumentation/action_pack/gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "rails", "~> 7.0.0.alpha2"
gem "rails", "~> 7.0.0"

group :test do
gem "byebug"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
private

def gem_version
Gem.loaded_specs['actionpack'].version
Gem.loaded_specs['actionpack']&.version || ::ActionPack.version
end

def patch
Expand Down
1 change: 1 addition & 0 deletions instrumentation/action_view/gemfiles/rails_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "rails", "~> 5.2.0"
group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-active_support", path: "../../../instrumentation/active_support"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "pry-byebug"
Expand Down
1 change: 1 addition & 0 deletions instrumentation/action_view/gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "rails", "~> 6.0.0"
group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-active_support", path: "../../../instrumentation/active_support"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "pry-byebug"
Expand Down
1 change: 1 addition & 0 deletions instrumentation/action_view/gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "rails", "~> 6.1.0"
group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-active_support", path: "../../../instrumentation/active_support"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "pry-byebug"
Expand Down
3 changes: 2 additions & 1 deletion instrumentation/action_view/gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "rails", "~> 7.0.0.alpha2"
gem "rails", "~> 7.0.0"

group :test do
gem "byebug"
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-instrumentation-active_support", path: "../../../instrumentation/active_support"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "pry-byebug"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
end

compatible do
Gem.loaded_specs['actionview'].version >= MINIMUM_VERSION
gem_version >= MINIMUM_VERSION
end

option :disallowed_notification_payload_keys, default: [], validate: :array
option :notification_payload_transform, default: nil, validate: :callable

private

def gem_version
Gem.loaded_specs['actionview'].version || ::ActionView.version
end

def require_dependencies
require_relative 'railtie'
end
Expand Down
3 changes: 1 addition & 2 deletions instrumentation/active_job/gemfiles/activejob_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ gem "activejob", "~> 5.2.0"
group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "pry"
gem "pry-byebug"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
end

gemspec path: "../"
3 changes: 1 addition & 2 deletions instrumentation/active_job/gemfiles/activejob_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ gem "activejob", "~> 6.0.0"
group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "pry"
gem "pry-byebug"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
end

gemspec path: "../"
3 changes: 1 addition & 2 deletions instrumentation/active_job/gemfiles/activejob_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ gem "activejob", "~> 6.1.0"
group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "pry"
gem "pry-byebug"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
end

gemspec path: "../"
15 changes: 15 additions & 0 deletions instrumentation/active_job/gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "rails", "~> 7.0.0"

group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
end

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
end

compatible do
Gem.loaded_specs['activejob'].version >= MINIMUM_VERSION
gem_version >= MINIMUM_VERSION
end

## Supported configuration keys for the install config hash:
Expand Down Expand Up @@ -58,6 +58,10 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base

private

def gem_version
Gem.loaded_specs['activejob']&.version || ::ActiveJob.version
end

def require_dependencies
require_relative 'patches/base'
require_relative 'patches/active_job_callbacks'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "active_model_serializers", "~> 0.10.10"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "active_model_serializers", "~> 0.10.0"

group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
end

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
private

def gem_version
Gem.loaded_specs['active_model_serializers'].version
Gem.loaded_specs['active_model_serializers']&.version || Gem::Version.new(::ActiveModel::Serializer::VERSION)
end

def require_dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def insert_class_methods_supported?
end

def gem_version
Gem.loaded_specs['activerecord'].version
Gem.loaded_specs['activerecord']&.version || ::ActiveRecord.version
end

def patch
Expand Down
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.11.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.3.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.6.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.7.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.8.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_2.9.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_3.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/gemfiles/aws_sdk_3.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "webrick", "~> 1.7"
end

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
option :suppress_internal_instrumentation, default: false, validate: :boolean

def gem_version
if Gem.loaded_specs['aws-sdk']
Gem.loaded_specs['aws-sdk'].version
elsif Gem.loaded_specs['aws-sdk-core']
Gem.loaded_specs['aws-sdk-core'].version
end
Gem.loaded_specs['aws-sdk']&.version || Gem.loaded_specs['aws-sdk-core']&.version || Gem::Version.new(::Aws::CORE_GEM_VERSION)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Instrumentation
#
# # if the target library is present, is it compatible?
# compatible do
# Gem.loaded_specs['sinatra'].version > MIN_VERSION
# (Gem.loaded_specs['sinatra']&.version || Gem::Version.new(Sinatra::VERSION)) > MIN_VERSION
# end
# end
# end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
private

def gem_version
# Version is hardcoded in the gemspec
# https://github.com/collectiveidea/delayed_job/blob/master/delayed_job.gemspec#L16
Gem.loaded_specs['delayed_job'].version
end

Expand Down
2 changes: 2 additions & 0 deletions instrumentation/http/gemfiles/http_3.3.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "http", "~> 3.3.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"
end

Expand Down
2 changes: 2 additions & 0 deletions instrumentation/http/gemfiles/http_4.4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "http", "~> 4.4.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"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
end

present do
!(defined?(::HTTP) && Gem.loaded_specs['http']).nil?
!(defined?(::HTTP::Client).nil? || defined?(::HTTP::Connection).nil?)
end

def patch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
hide_const('HTTP')
_(instrumentation.present?).must_equal(false)
end

it 'when http gem not installed' do
allow(Gem).to receive(:loaded_specs).and_return({})
_(instrumentation.present?).must_equal(false)
end
end

describe '#install' do
Expand Down
5 changes: 4 additions & 1 deletion instrumentation/mongo/gemfiles/mongo_2.13.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "mongo-ruby-driver", "~> 2.13.0"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "mongo", "~> 2.13.0"

group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
end

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
private

def gem_version
Gem.loaded_specs['mongo']&.version
Gem.loaded_specs['mongo']&.version || Gem::Version.new(::Mongo::VERSION)
end

def require_dependencies
Expand Down
Loading

0 comments on commit fd88fd8

Please sign in to comment.