From fc0eb9e862567d7d8ef7f94861639d1cc07e52d8 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 11 Oct 2024 09:19:51 +0000 Subject: [PATCH 1/2] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c7c3e2c7..4adbcb093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - Add `include_sentry_event` matcher for RSpec [#2424](https://github.com/getsentry/sentry-ruby/pull/2424) +### Bug Fixes + +- Fix Vernier profiler not stopping when already stopped [#2429](https://github.com/getsentry/sentry-ruby/pull/2429) + ## 5.21.0 ### Features From 760804d481372e0f9777043651b59449fb554e78 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 11 Oct 2024 09:16:37 +0000 Subject: [PATCH 2/2] Fix issues with stopping Vernier --- sentry-ruby/lib/sentry/vernier/profiler.rb | 9 +++++++-- sentry-ruby/spec/sentry/vernier/profiler_spec.rb | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sentry-ruby/lib/sentry/vernier/profiler.rb b/sentry-ruby/lib/sentry/vernier/profiler.rb index 0ca8c0f39..6ee6b6ced 100644 --- a/sentry-ruby/lib/sentry/vernier/profiler.rb +++ b/sentry-ruby/lib/sentry/vernier/profiler.rb @@ -55,8 +55,7 @@ def start return unless @sampled return if @started - ::Vernier.start_profile - @started = true + @started = ::Vernier.start_profile log("Started") @@ -77,6 +76,12 @@ def stop @result = ::Vernier.stop_profile log("Stopped") + rescue RuntimeError => e + if e.message.include?("Profile not started") + log("Not stopped since not started") + else + log("Failed to stop Vernier: #{e.message}") + end end def active_thread_id diff --git a/sentry-ruby/spec/sentry/vernier/profiler_spec.rb b/sentry-ruby/spec/sentry/vernier/profiler_spec.rb index 03fe7ebde..46a696fee 100644 --- a/sentry-ruby/spec/sentry/vernier/profiler_spec.rb +++ b/sentry-ruby/spec/sentry/vernier/profiler_spec.rb @@ -133,6 +133,20 @@ expect(Vernier).to receive(:stop_profile) profiler.stop end + + it 'does not crash when Vernier was already stopped' do + profiler.set_initial_sample_decision(true) + profiler.start + Vernier.stop_profile + profiler.stop + end + + it 'does not crash when stopping Vernier crashed' do + profiler.set_initial_sample_decision(true) + profiler.start + expect(Vernier).to receive(:stop_profile).and_raise(RuntimeError.new("Profile not started")) + profiler.stop + end end describe "#to_hash" do