diff --git a/lib/datadog/profiling/component.rb b/lib/datadog/profiling/component.rb index 0d31084f74..686824c9ed 100644 --- a/lib/datadog/profiling/component.rb +++ b/lib/datadog/profiling/component.rb @@ -220,6 +220,12 @@ def self.build_profiler_component(settings:, agent_settings:, optional_tracer:, "Please upgrade to Ruby >= 3.1 in order to use this feature. Heap profiling has been disabled." ) return false + elsif RUBY_VERSION.start_with?("4.") + logger.warn( + "Datadog Ruby heap profiler is currently incompatible with Ruby 4. " \ + "Heap profiling has been disabled." + ) + return false end unless allocation_profiling_enabled diff --git a/spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb b/spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb index 1d5d96578c..4f9983cb8d 100644 --- a/spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb +++ b/spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb @@ -865,7 +865,8 @@ before do skip "Heap profiling is only supported on Ruby >= 2.7" if RUBY_VERSION < "2.7" - skip "Heap profiling is buggy on 4.0.0preview2 (https://bugs.ruby-lang.org/issues/21710) but fixed in master" if RUBY_DESCRIPTION.include?("4.0.0preview2") + skip "Datadog Heap profiling is incompatible with Ruby 4, see https://bugs.ruby-lang.org/issues/21710 for discussion" if RUBY_VERSION.start_with?("4.") + allow(Datadog.logger).to receive(:warn) expect(Datadog.logger).to receive(:warn).with(/dynamic sampling rate disabled/) end diff --git a/spec/datadog/profiling/component_spec.rb b/spec/datadog/profiling/component_spec.rb index 15d97b7d7c..37a8201d62 100644 --- a/spec/datadog/profiling/component_spec.rb +++ b/spec/datadog/profiling/component_spec.rb @@ -334,6 +334,20 @@ end end + context "on Ruby 4.0 or newer" do + let(:testing_version) { "4.0.0" } + + it "initializes StackRecorder without heap sampling support and warns" do + expect(Datadog::Profiling::StackRecorder).to receive(:new) + .with(hash_including(heap_samples_enabled: false, heap_size_enabled: false)) + .and_call_original + + expect(logger).to receive(:warn).with(/Datadog Ruby heap profiler is currently incompatible with Ruby 4/) + + build_profiler_component + end + end + context "and allocation profiling disabled" do before do settings.profiling.allocation_enabled = false