Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with stopping Vernier #2429

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 @@
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 @@
@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
Loading