Skip to content

Commit

Permalink
Add bundler conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahramadan committed Aug 20, 2024
1 parent b1eef51 commit bfad25e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
11 changes: 8 additions & 3 deletions lib/new_relic/agent/instrumentation/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@

depends_on do
begin
if defined?(Bundler) && 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
if defined?(Bundler) &&
if Bundler::VERSION >= '2' && Bundler.rubygems.installed_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
elsif 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
end
else
true
end
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
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) &&
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

0 comments on commit bfad25e

Please sign in to comment.