Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix profiler wrongly detecting that google-protobuf is installed #2595

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/datadog/profiling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def self.start_if_enabled
# NOTE: On environments where protobuf is already loaded, we skip the check. This allows us to support environments
# where no Gem.loaded_version is NOT available but customers are able to load protobuf; see for instance
# https://github.com/teamcapybara/capybara/commit/caf3bcd7664f4f2691d0ca9ef3be9a2a954fecfb
if !defined?(::Google::Protobuf) && Gem.loaded_specs['google-protobuf'].nil?
if !protobuf_already_loaded? && Gem.loaded_specs['google-protobuf'].nil?
"Missing google-protobuf dependency; please add `gem 'google-protobuf', '~> 3.0'` to your Gemfile or gems.rb file"
end
end
Expand All @@ -74,12 +74,16 @@ def self.start_if_enabled
# See above for why we skip the check when protobuf is already loaded; note that when protobuf was already loaded
# we skip the version check to avoid the call to Gem.loaded_specs. Unfortunately, protobuf does not seem to
# expose the gem version constant elsewhere, so in that setup we are not able to check the version.
if !defined?(::Google::Protobuf) && Gem.loaded_specs['google-protobuf'].version < GOOGLE_PROTOBUF_MINIMUM_VERSION
if !protobuf_already_loaded? && Gem.loaded_specs['google-protobuf'].version < GOOGLE_PROTOBUF_MINIMUM_VERSION
'Your google-protobuf is too old; ensure that you have google-protobuf >= 3.0 by ' \
"adding `gem 'google-protobuf', '~> 3.0'` to your Gemfile or gems.rb file"
end
end

private_class_method def self.protobuf_already_loaded?
defined?(::Google::Protobuf) && !defined?(::Protobuf)
end

private_class_method def self.protobuf_failed_to_load?
unless protobuf_loaded_successfully?
'There was an error loading the google-protobuf library; see previous warning message for details'
Expand Down
10 changes: 10 additions & 0 deletions spec/datadog/profiling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@
end

it { is_expected.to be nil }

context "but it's the protobuf/cucumber-protobuf gem instead of google-protobuf" do
include_context 'loaded gems', :'google-protobuf' => nil

before do
stub_const('::Protobuf', Module.new)
end

it { is_expected.to include 'Missing google-protobuf' }
end
end
end
end
Expand Down