Skip to content

Sentry.with_scope block is not called when Sentry is not initialized #1896

Closed

Description

Issue Description

I'm using Sentry.with_scope to add custom context information for the piece of code.

Also, I don't want to have Sentry initialized during my tests run. I achieved it by bailing out of sentry initializer before Sentry.init is called.

It works fine except one thing. Now, code inside with_scope block is not executed at all. This behavior obviously breaks the application.

Reproduction Steps

config/initializers/sentry.rb:

return if Rails.env.test? # Don't initialize in test environment

Sentry.init do |config|
  config.dsn = 'MY_DSN'
end

Expected Behavior

Code flow should not be affected regardless of the Sentry SDK state.

$ bundle exec rails r "Sentry.with_scope { puts 'Inside the scope' }"
Inside the scope
$

$ RAILS_ENV=test bundle exec rails r "Sentry.with_scope { puts 'Inside the scope' }"
Inside the scope
$

Actual Behavior

$ bundle exec rails r "Sentry.with_scope { puts 'Inside the scope' }"
Inside the scope
$

$ RAILS_ENV=test bundle exec rails r "Sentry.with_scope { puts 'Inside the scope' }"
$

In a nutshell, when I'm in a test environment (Sentry.init was not called), my code is not working.

Ruby Version

3.0.4

SDK Version

5.4.2

Integration and Its Version

sentry-ruby (5.4.2)

Sentry Config

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions