Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix profiler wrongly detecting that google-protobuf is installed
**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 the `ddtrace` 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` (or `protobuf-cucumber`, its fork) that is not compatible with `ddtrace` 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: > [DDTRACE] Error while loading google-protobuf gem. Cause: 'LoadError > cannot load such file -- google/protobuf' Location: > 'lib/datadog/profiling.rb:106:in `require''. This can happen when > google-protobuf is missing its native components. [...] ``` To fix this, I've tweaked the `google-protobuf` detection to also check for the `::Protobuf` module. This top-level module is never defined by `google-protobuf`, and we can use it to distinguish between the two gems. **Motivation**: Avoid misleading error message when loading `ddtrace` with `protobuf`/`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. * gems.rb: ```ruby source 'http://rubygems.org' gem 'protobuf-cucumber' gem 'ddtrace' ``` * example.rb: ```ruby require 'protobuf' require 'ddtrace' puts "Works!" ```
- Loading branch information