diff --git a/lib/datadog/profiling/component.rb b/lib/datadog/profiling/component.rb index 0d31084f745..961b2e7ad97 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( + "Heap profiling is not supported in current Ruby version (#{RUBY_VERSION}) due to https://bugs.ruby-lang.org/issues/21710. " \ + "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 408abf1ddd8..0d411db45ec 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 @@ -868,6 +868,7 @@ before do skip "Heap profiling is only supported on Ruby >= 2.7" if RUBY_VERSION < "2.7" + skip "Heap profiling is disabled on Ruby 4 until https://bugs.ruby-lang.org/issues/21710 is fixed" 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 15d97b7d7c5..fdee2850a33 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(/Heap profiling is not supported.*21710/) + + build_profiler_component + end + end + context "and allocation profiling disabled" do before do settings.profiling.allocation_enabled = false