Skip to content

Commit abb966a

Browse files
committed
Merge pull request #1300 from DataDog/fix/warn_on_incompatible_rollbar
[PROF-2585] Warn on incompatible rollbar version
2 parents e2893cb + a79924a commit abb966a

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

lib/ddtrace/profiling/tasks/setup.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Tasks
99
# Sets up profiling for the application
1010
class Setup
1111
def run
12+
check_warnings!
1213
activate_main_extensions
1314
autostart_profiler
1415
end
@@ -79,6 +80,22 @@ def autostart_profiler
7980
log "[DDTRACE] Could not autostart profiling. Cause: #{e.message} Location: #{e.backtrace.first}"
8081
end
8182

83+
def check_warnings!
84+
warn_if_incompatible_rollbar_gem_detected
85+
end
86+
87+
# See https://github.com/rollbar/rollbar-gem/pull/1018 for details on the incompatibility
88+
def warn_if_incompatible_rollbar_gem_detected
89+
incompatible_rollbar_versions = Gem::Requirement.new('<= 3.1.1')
90+
91+
if Gem::Specification.find_all_by_name('rollbar', incompatible_rollbar_versions).any?
92+
log "[DDTRACE] Incompatible version of the rollbar gem is installed (#{incompatible_rollbar_versions}). " \
93+
'Loading this version of the rollbar gem will disable ddtrace\'s CPU profiling. ' \
94+
'Please upgrade to the latest rollbar version. ' \
95+
'See https://github.com/rollbar/rollbar-gem/pull/1018 for details.'
96+
end
97+
end
98+
8299
private
83100

84101
def log(message)

spec/ddtrace/profiling/tasks/setup_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
subject(:run) { task.run }
1313

1414
it do
15+
expect(task).to receive(:check_warnings!).ordered
1516
expect(task).to receive(:activate_main_extensions).ordered
1617
expect(task).to receive(:autostart_profiler).ordered
1718
run
@@ -346,4 +347,63 @@
346347
end
347348
end
348349
end
350+
351+
describe '#check_warnings!' do
352+
subject(:check_warnings!) { task.check_warnings! }
353+
354+
it do
355+
expect(task).to receive(:warn_if_incompatible_rollbar_gem_detected)
356+
357+
check_warnings!
358+
end
359+
end
360+
361+
describe '#warn_if_incompatible_rollbar_gem_detected' do
362+
subject(:warn_if_incompatible_rollbar_gem_detected) { task.warn_if_incompatible_rollbar_gem_detected }
363+
364+
let(:last_version_of_rollbar_affected) { '3.1.1' }
365+
366+
before do
367+
# Simulate the result of the gem apis, so that we can check different combinations of having or not having the
368+
# rollbar gem and affected versions
369+
expect(Gem::Specification)
370+
.to receive(:find_all_by_name)
371+
.with('rollbar', Gem::Requirement.new("<= #{last_version_of_rollbar_affected}"))
372+
.and_return(rollbar_versions_found)
373+
end
374+
375+
context 'when rollbar gem is not installed' do
376+
let(:rollbar_versions_found) { [] }
377+
378+
it 'does not display a warning to STDOUT' do
379+
expect(STDOUT).to_not receive(:puts)
380+
381+
warn_if_incompatible_rollbar_gem_detected
382+
end
383+
end
384+
385+
context 'when compatible version of rollbar gem is installed' do
386+
# same as "no gem installed" because we use a version requirement when
387+
# calling find_all_by_name, so only incompatible versions get returned
388+
let(:rollbar_versions_found) { [] }
389+
390+
it 'does not display a warning to STDOUT' do
391+
expect(STDOUT).to_not receive(:puts)
392+
393+
warn_if_incompatible_rollbar_gem_detected
394+
end
395+
end
396+
397+
context 'when incompatible version of rollbar gem is installed' do
398+
let(:rollbar_versions_found) { [instance_double(Gem::Specification), instance_double(Gem::Specification)] }
399+
400+
it 'displays a warning to STDOUT' do
401+
expect(STDOUT).to receive(:puts) do |message|
402+
expect(message).to include('Incompatible version of the rollbar')
403+
end
404+
405+
warn_if_incompatible_rollbar_gem_detected
406+
end
407+
end
408+
end
349409
end

0 commit comments

Comments
 (0)