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

Add Bundler version conditions #2823

Merged
merged 8 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion lib/new_relic/agent/instrumentation/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

depends_on do
begin
if defined?(Bundler) && Bundler.rubygems.all_specs.map(&:name).include?('newrelic-grape')
if defined?(Bundler) && ((Bundler::VERSION >= '2' && Bundler.rubygems.installed_specs.map(&:name).include?('newrelic-grape')) ||
kaylareopelle marked this conversation as resolved.
Show resolved Hide resolved
Bundler.rubygems.all_specs.map(&:name).include?('newrelic-grape'))
NewRelic::Agent.logger.info('Not installing New Relic supported Grape instrumentation because the third party newrelic-grape gem is present')
false
else
Expand Down
6 changes: 4 additions & 2 deletions lib/new_relic/control/frameworks/rails4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class Control
module Frameworks
class Rails4 < NewRelic::Control::Frameworks::Rails3
def rails_gem_list
Bundler.rubygems.all_specs.map do |gem|
"#{gem.name} (#{gem.version})"
if Bundler::VERSION >= '2'
Bundler.rubygems.installed_specs.map { |gem| "#{gem.name} (#{gem.version})" }
else
Bundler.rubygems.all_specs.map { |gem| "#{gem.name} (#{gem.version})" }
end
end

Expand Down
6 changes: 5 additions & 1 deletion lib/new_relic/environment_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def self.registered_reporters=(logic)
####################################
report_on('Gems') do
begin
Bundler.rubygems.all_specs.map { |gem| "#{gem.name}(#{gem.version})" }
if Bundler::VERSION >= '2'
Bundler.rubygems.installed_specs.map { |gem| "#{gem.name}(#{gem.version})" }
else
Bundler.rubygems.all_specs.map { |gem| "#{gem.name}(#{gem.version})" }
end
hannahramadan marked this conversation as resolved.
Show resolved Hide resolved
rescue
# There are certain rubygem, bundler, rails combinations (e.g. gem
# 1.6.2, rails 2.3, bundler 1.2.3) where the code above throws an error
Expand Down
7 changes: 6 additions & 1 deletion lib/new_relic/language_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ def snakeize(string)
end

def bundled_gem?(gem_name)
defined?(Bundler) && Bundler.rubygems.all_specs.map(&:name).include?(gem_name)
defined?(Bundler) &&
kaylareopelle marked this conversation as resolved.
Show resolved Hide resolved
if Bundler::VERSION >= '2'
Bundler.rubygems.installed_specs.map(&:name).include?(gem_name)
else
Bundler.rubygems.all_specs.map(&:name).include?(gem_name)
end
rescue => e
::NewRelic::Agent.logger.info("Could not determine if third party #{gem_name} gem is installed", e)
false
Expand Down
Loading