Skip to content

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

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

Closed
michaelkl opened this issue Sep 15, 2022 · 1 comment · Fixed by #1897
Closed

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

michaelkl opened this issue Sep 15, 2022 · 1 comment · Fixed by #1897
Assignees
Milestone

Comments

@michaelkl
Copy link

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

@st0012
Copy link
Collaborator

st0012 commented Sep 15, 2022

Thanks for reporting. I'll open a PR shortly

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

Successfully merging a pull request may close this issue.

3 participants