@@ -246,3 +246,52 @@ def test_no_thread_on_shutdown_no_errors_deprecated(
246246 sentry_sdk .flush ()
247247
248248 # If we reach this point without error, the test is successful.
249+
250+
251+ def test_top_level_start_session_basic (sentry_init , capture_envelopes ):
252+ """Test that top-level start_session starts a session on the isolation scope."""
253+ sentry_init (release = "test-release" , environment = "test-env" )
254+ envelopes = capture_envelopes ()
255+
256+ # Start a session using the top-level API
257+ sentry_sdk .start_session ()
258+
259+ # End the session
260+ sentry_sdk .end_session ()
261+ sentry_sdk .flush ()
262+
263+ # Check that we got a session envelope
264+ assert len (envelopes ) == 1
265+ sess = envelopes [0 ]
266+ assert len (sess .items ) == 1
267+ sess_event = sess .items [0 ].payload .json
268+
269+ assert sess_event ["attrs" ] == {
270+ "release" : "test-release" ,
271+ "environment" : "test-env" ,
272+ }
273+ assert sess_event ["status" ] == "exited"
274+
275+
276+ def test_top_level_start_session_with_mode (sentry_init , capture_envelopes ):
277+ """Test that top-level start_session accepts session_mode parameter."""
278+ sentry_init (release = "test-release" , environment = "test-env" )
279+ envelopes = capture_envelopes ()
280+
281+ # Start a session with request mode
282+ sentry_sdk .start_session (session_mode = "request" )
283+ sentry_sdk .end_session ()
284+ sentry_sdk .flush ()
285+
286+ # Request mode sessions are aggregated
287+ assert len (envelopes ) == 1
288+ sess = envelopes [0 ]
289+ assert len (sess .items ) == 1
290+ sess_event = sess .items [0 ].payload .json
291+
292+ assert sess_event ["attrs" ] == {
293+ "release" : "test-release" ,
294+ "environment" : "test-env" ,
295+ }
296+ # Request sessions show up as aggregates
297+ assert "aggregates" in sess_event
0 commit comments