diff --git a/lib/datadog/profiling/component.rb b/lib/datadog/profiling/component.rb index fe2ba74f758..6b03ea564c1 100644 --- a/lib/datadog/profiling/component.rb +++ b/lib/datadog/profiling/component.rb @@ -171,12 +171,11 @@ def self.build_profiler_component(settings:, agent_settings:, optional_tracer:) return true end - if defined?(::PhusionPassenger) + if (defined?(::PhusionPassenger) || Gem.loaded_specs['passenger']) && incompatible_passenger_version? Datadog.logger.warn( - 'Enabling the profiling "no signals" workaround because the passenger web server is in use. ' \ - 'This is needed because passenger is currently incompatible with the normal working mode ' \ - 'of the profiler, as detailed in . ' \ - 'Profiling data will have lower quality.' + 'Enabling the profiling "no signals" workaround because an incompatible version of the passenger gem is ' \ + 'installed. Profiling data will have lower quality.' \ + 'To fix this, upgrade the passenger gem to version 6.0.19 or above.' ) return true end @@ -237,6 +236,15 @@ def self.build_profiler_component(settings:, agent_settings:, optional_tracer:) true end end + + # See https://github.com/datadog/dd-trace-rb/issues/2976 for details. + private_class_method def self.incompatible_passenger_version? + if Gem.loaded_specs['passenger'] + Gem.loaded_specs['passenger'].version < Gem::Version.new('6.0.19') + else + true + end + end end end end diff --git a/sig/datadog/profiling/component.rbs b/sig/datadog/profiling/component.rbs index c3b8bc92240..75f739c8784 100644 --- a/sig/datadog/profiling/component.rbs +++ b/sig/datadog/profiling/component.rbs @@ -23,6 +23,7 @@ module Datadog def self.no_signals_workaround_enabled?: (untyped settings) -> bool def self.incompatible_libmysqlclient_version?: (untyped settings) -> bool + def self.incompatible_passenger_version?: () -> bool end end end diff --git a/spec/datadog/profiling/component_spec.rb b/spec/datadog/profiling/component_spec.rb index 7d806e3b543..7c64aa27f21 100644 --- a/spec/datadog/profiling/component_spec.rb +++ b/spec/datadog/profiling/component_spec.rb @@ -480,7 +480,9 @@ end end - context 'when running inside the passenger web server' do + context 'when running inside the passenger web server, even when gem is not available' do + include_context('loaded gems', passenger: nil, rugged: nil, mysql2: nil) + before do stub_const('::PhusionPassenger', Module.new) allow(Datadog.logger).to receive(:warn) @@ -495,8 +497,30 @@ end end + context 'when passenger gem is available' do + context 'on passenger >= 6.0.19' do + include_context('loaded gems', passenger: Gem::Version.new('6.0.19'), rugged: nil, mysql2: nil) + + it { is_expected.to be false } + end + + context 'on passenger < 6.0.19' do + include_context('loaded gems', passenger: Gem::Version.new('6.0.18'), rugged: nil, mysql2: nil) + + before { allow(Datadog.logger).to receive(:warn) } + + it { is_expected.to be true } + + it 'logs a warning message mentioning that the no signals workaround is going to be used' do + expect(Datadog.logger).to receive(:warn).with(/Enabling the profiling "no signals" workaround/) + + no_signals_workaround_enabled? + end + end + end + context 'when mysql2 / rugged gems + passenger are not available' do - include_context('loaded gems', mysql2: nil, rugged: nil) + include_context('loaded gems', passenger: nil, mysql2: nil, rugged: nil) it { is_expected.to be false } end