Skip to content
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
17 changes: 17 additions & 0 deletions lib/ddtrace/profiling/tasks/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Tasks
# Sets up profiling for the application
class Setup
def run
check_warnings!
activate_main_extensions
autostart_profiler
end
Expand Down Expand Up @@ -79,6 +80,22 @@ def autostart_profiler
log "[DDTRACE] Could not autostart profiling. Cause: #{e.message} Location: #{e.backtrace.first}"
end

def check_warnings!
warn_if_incompatible_rollbar_gem_detected
end

# See https://github.com/rollbar/rollbar-gem/pull/1018 for details on the incompatibility
def warn_if_incompatible_rollbar_gem_detected
incompatible_rollbar_versions = Gem::Requirement.new('<= 3.1.1')

if Gem::Specification.find_all_by_name('rollbar', incompatible_rollbar_versions).any?
log "[DDTRACE] Incompatible version of the rollbar gem is installed (#{incompatible_rollbar_versions}). " \
'Loading this version of the rollbar gem will disable ddtrace\'s CPU profiling. ' \
'Please upgrade to the latest rollbar version. ' \
'See https://github.com/rollbar/rollbar-gem/pull/1018 for details.'
end
end

private

def log(message)
Expand Down
60 changes: 60 additions & 0 deletions spec/ddtrace/profiling/tasks/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
subject(:run) { task.run }

it do
expect(task).to receive(:check_warnings!).ordered
expect(task).to receive(:activate_main_extensions).ordered
expect(task).to receive(:autostart_profiler).ordered
run
Expand Down Expand Up @@ -346,4 +347,63 @@
end
end
end

describe '#check_warnings!' do
subject(:check_warnings!) { task.check_warnings! }

it do
expect(task).to receive(:warn_if_incompatible_rollbar_gem_detected)

check_warnings!
end
end

describe '#warn_if_incompatible_rollbar_gem_detected' do
subject(:warn_if_incompatible_rollbar_gem_detected) { task.warn_if_incompatible_rollbar_gem_detected }

let(:last_version_of_rollbar_affected) { '3.1.1' }

before do
# Simulate the result of the gem apis, so that we can check different combinations of having or not having the
# rollbar gem and affected versions
expect(Gem::Specification)
.to receive(:find_all_by_name)
.with('rollbar', Gem::Requirement.new("<= #{last_version_of_rollbar_affected}"))
.and_return(rollbar_versions_found)
end

context 'when rollbar gem is not installed' do
let(:rollbar_versions_found) { [] }

it 'does not display a warning to STDOUT' do
expect(STDOUT).to_not receive(:puts)

warn_if_incompatible_rollbar_gem_detected
end
end

context 'when compatible version of rollbar gem is installed' do
# same as "no gem installed" because we use a version requirement when
# calling find_all_by_name, so only incompatible versions get returned
let(:rollbar_versions_found) { [] }

it 'does not display a warning to STDOUT' do
expect(STDOUT).to_not receive(:puts)

warn_if_incompatible_rollbar_gem_detected
end
end

context 'when incompatible version of rollbar gem is installed' do
let(:rollbar_versions_found) { [instance_double(Gem::Specification), instance_double(Gem::Specification)] }

it 'displays a warning to STDOUT' do
expect(STDOUT).to receive(:puts) do |message|
expect(message).to include('Incompatible version of the rollbar')
end

warn_if_incompatible_rollbar_gem_detected
end
end
end
end