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

Prevent Hub from having nil scope and client #2402

Merged
merged 2 commits into from
Sep 27, 2024
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 5.20.0
## 5.20.0

- Add support for `$SENTRY_DEBUG` and `$SENTRY_SPOTLIGHT` ([#2374](https://github.com/getsentry/sentry-ruby/pull/2374))
- Support human readable intervals in `sidekiq-cron` ([#2387](https://github.com/getsentry/sentry-ruby/pull/2387))
Expand All @@ -10,6 +10,7 @@
- Fix error events missing a DSC when there's an active span ([#2408](https://github.com/getsentry/sentry-ruby/pull/2408))
- Verifies presence of client before adding a breadcrumb ([#2394](https://github.com/getsentry/sentry-ruby/pull/2394))
- Fix `Net:HTTP` integration for non-ASCII URI's ([#2417](https://github.com/getsentry/sentry-ruby/pull/2417))
- Prevent Hub from having nil scope and client ([#2402](https://github.com/getsentry/sentry-ruby/pull/2402))

## 5.19.0

Expand Down
8 changes: 7 additions & 1 deletion sentry-ruby/lib/sentry/hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ def push_scope
end

def pop_scope
@stack.pop
if @stack.size > 1
@stack.pop
else
# We never want to enter a situation where we have no scope and no client
client = current_client
@stack = [Layer.new(client, Scope.new)]
end
end

def start_transaction(transaction: nil, custom_sampling_context: {}, instrumenter: :sentry, **options)
Expand Down
33 changes: 17 additions & 16 deletions sentry-ruby/spec/sentry/hub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,25 @@

describe "#pop_scope" do
it "pops the current scope" do
prev_scope = subject.current_scope
subject.push_scope
scope = subject.current_scope
expect(subject.current_scope).to eq(scope)
subject.pop_scope
expect(subject.current_scope).to eq(nil)
expect(subject.current_scope).to eq(prev_scope)
end

it "doesn't pop the last layer" do
expect(subject.instance_variable_get(:@stack).count).to eq(1)

subject.pop_scope

expect(subject.instance_variable_get(:@stack).count).to eq(1)

# It should be a completely new scope
expect(subject.current_scope).not_to eq(scope)
# But it should be the same client
expect(subject.current_client).to eq(client)
end
end

Expand All @@ -543,21 +559,6 @@
expect(subject.current_scope).not_to eq(scope)
expect(subject.current_scope.tags).to eq({ foo: "bar" })
end

context "when the current_scope is nil" do
before do
subject.pop_scope
expect(subject.current_scope).to eq(nil)
end
it "creates a new scope" do
scope.set_tags({ foo: "bar" })

subject.push_scope

expect(subject.current_scope).not_to eq(scope)
expect(subject.current_scope.tags).to eq({})
end
end
end

describe '#configure_scope' do
Expand Down
Loading