Fix profiler wrongly detecting that google-protobuf is installed #2595
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?:
The
google-protobuf
gem is a dependency needed by the profiler (that we plan on removing when we fully move to libdatadog), but that is not a dependency of theddtrace
gem.Because it's not a dependency of
ddtrace
, we need to gracefully handle the case where this gem is missing. Thus, before requiring any files from this gem, the profiler uses rubygems to check if the gem is available.But, in #1506, a customer asked us to allow skipping this API call to rubygems, since it didn't work on their setup. Instead, we added an extra check -- if the
::Google::Protobuf
module is available, then we assume protobuf is installed.Very very unfortunately, there's actually another gem, called
protobuf
(orprotobuf-cucumber
, its fork) that is not compatible withddtrace
BUT STILL defines::Google::Protobuf
.This is horrifying -- having two different gems that define different versions of a module with the same name.
But in this very bizarre situation, the
google-protobuf
detection code got confused, and one internal customer reported that he saw the following error on their logs:To fix this, I've tweaked the
google-protobuf
detection to also check for the::Protobuf
module. This top-level module is never defined bygoogle-protobuf
, and we can use it to distinguish between the two gems.Motivation:
Avoid misleading error message when loading
ddtrace
withprotobuf
/protobuf-cucumber
installed.Additional Notes:
I'm looking forward to dropping this whole
google-protobuf
code once the new profiler becomes the default for all customers.How to test the change?:
The following trivial Ruby app is able to trigger the issue.