Skip to content

Commit

Permalink
Fix issues with stopping Vernier
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Oct 11, 2024
1 parent fc0eb9e commit 760804d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sentry-ruby/lib/sentry/vernier/profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def start
return unless @sampled
return if @started

::Vernier.start_profile
@started = true
@started = ::Vernier.start_profile

Check warning on line 58 in sentry-ruby/lib/sentry/vernier/profiler.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/vernier/profiler.rb#L58

Added line #L58 was not covered by tests

log("Started")

Expand All @@ -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")

Check warning on line 81 in sentry-ruby/lib/sentry/vernier/profiler.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/vernier/profiler.rb#L80-L81

Added lines #L80 - L81 were not covered by tests
else
log("Failed to stop Vernier: #{e.message}")

Check warning on line 83 in sentry-ruby/lib/sentry/vernier/profiler.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/vernier/profiler.rb#L83

Added line #L83 was not covered by tests
end
end

def active_thread_id
Expand Down
14 changes: 14 additions & 0 deletions sentry-ruby/spec/sentry/vernier/profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 760804d

Please sign in to comment.