-
-
Notifications
You must be signed in to change notification settings - Fork 523
Closed
Labels
Description
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 becauseenabled_in_current_env?is false - so, when
lib/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)- which causes an exception because
session_flusheris 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.callto 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
Metadata
Metadata
Assignees
Labels
Projects
Status
Waiting for: Product Owner