Issue Description
In the Rails project I'm working on, Sentry is disabled during testing. When I upgraded the sentry-ruby gem from 5.10.0 to 5.21.0, I had some tests give the following exception
Minitest::UnexpectedError: NoMethodError: undefined method `add_session' for nil:NilClass
Sentry.session_flusher.add_session(session)
^^^^^^^^^^^^
I'm pretty sure this is what's happening.
- auto_session_tracking isn't in my Sentry config, but it's set to true because that's the new default in 5.21.0
- However, this project has Sentry disabled for the test environment. That makes
config.session_tracking? return false because enabled_in_current_env? is false
- so, when
lib/sentry/rack/capture_exceptions calls Sentry.with_session_tracking as defined in lib/sentry-ruby.rb
lib/sentry-ruby.rb calls get_current_hub.with_session_tracking(&block) as defined in lib/sentry/hub.rb
with_session_tracking in lib/sentry/hub.rb bypasses the guard statement and calls Sentry.session_flusher.add_session(session)
- which causes an exception because
session_flusher is nil
The exception doesn't happen if auto_session_tracking is false, because the guard on Hub#with_session_tracking explicitly returns.
Reproduction Steps
- Disable Sentry in the environment you're using to reproduce
- Enable session tracking, implicitly or explicitly
- Do something that causes
CaptureExceptions.call to be executed
Expected Behavior
No exceptions about session tracking is Sentry is supposed to be disabled.
Actual Behavior
The undefined method add_session' for nil:NilClass` exception from above.
Ruby Version
ruby 3.1.6p260
SDK Version
5.21.0
Integration and Its Version
Rails
Sentry Config
No response
Issue Description
In the Rails project I'm working on, Sentry is disabled during testing. When I upgraded the sentry-ruby gem from 5.10.0 to 5.21.0, I had some tests give the following exception
I'm pretty sure this is what's happening.
config.session_tracking?return false becauseenabled_in_current_env?is falselib/sentry/rack/capture_exceptionscallsSentry.with_session_trackingas defined inlib/sentry-ruby.rblib/sentry-ruby.rbcallsget_current_hub.with_session_tracking(&block)as defined inlib/sentry/hub.rbwith_session_trackinginlib/sentry/hub.rbbypasses the guard statement and callsSentry.session_flusher.add_session(session)session_flusheris nilThe exception doesn't happen if
auto_session_trackingis false, because the guard on Hub#with_session_tracking explicitly returns.Reproduction Steps
CaptureExceptions.callto be executedExpected Behavior
No exceptions about session tracking is Sentry is supposed to be disabled.
Actual Behavior
The
undefined methodadd_session' for nil:NilClass` exception from above.Ruby Version
ruby 3.1.6p260
SDK Version
5.21.0
Integration and Its Version
Rails
Sentry Config
No response