@@ -231,6 +231,37 @@ def test_logging_captured_warnings(sentry_init, capture_events, recwarn):
231231 assert len (third_warnings ) == 1
232232
233233
234+ def test_sentry_logs_collection_off_by_default (sentry_init , capture_items , request ):
235+ """Automatic logs capture by Sentry logs needs explicit opt-in via capture_sentry_logs."""
236+ sentry_init ()
237+ items = capture_items ("log" )
238+
239+ python_logger = logging .Logger ("test-logger" )
240+ python_logger .warning ("this is %s a template %s" , "1" , "2" )
241+
242+ get_client ().flush ()
243+
244+ assert not items
245+
246+
247+ def test_sentry_logs_collection_opt_in (sentry_init , capture_items , request ):
248+ """Automatic logs capture by Sentry logs needs explicit opt-in via capture_sentry_logs."""
249+ sentry_init (integrations = [LoggingIntegration (capture_sentry_logs = True )])
250+ items = capture_items ("log" )
251+
252+ python_logger = logging .Logger ("test-logger" )
253+ python_logger .warning ("this is %s a template %s" , "1" , "2" )
254+
255+ get_client ().flush ()
256+
257+ assert len (items ) == 1
258+
259+ log = items [0 ].payload
260+ assert log ["attributes" ]["sentry.message.template" ] == "this is %s a template %s"
261+ assert log ["attributes" ]["sentry.severity_number" ] == 13
262+ assert log ["attributes" ]["sentry.severity_text" ] == "warn"
263+
264+
234265def test_ignore_logger (sentry_init , capture_events , request ):
235266 sentry_init (integrations = [LoggingIntegration ()], default_integrations = False )
236267 events = capture_events ()
@@ -276,7 +307,7 @@ def test_ignore_logger_wildcard(sentry_init, capture_events, request):
276307
277308def test_ignore_logger_does_not_affect_sentry_logs (sentry_init , capture_items , request ):
278309 """ignore_logger should suppress events/breadcrumbs but not Sentry Logs."""
279- sentry_init (enable_logs = True )
310+ sentry_init (integrations = [ LoggingIntegration ( capture_sentry_logs = True )] )
280311 items = capture_items ("log" )
281312
282313 ignore_logger ("testfoo" )
@@ -294,7 +325,7 @@ def test_ignore_logger_for_sentry_logs(
294325 sentry_init , capture_envelopes , capture_items , request
295326):
296327 """ignore_logger_for_sentry_logs should suppress Sentry Logs but not events."""
297- sentry_init (enable_logs = True )
328+ sentry_init (integrations = [ LoggingIntegration ( capture_sentry_logs = True )] )
298329 envelopes = capture_envelopes ()
299330 items = capture_items ("log" )
300331
@@ -355,7 +386,7 @@ def test_sentry_logs_warning(sentry_init, capture_items):
355386 """
356387 The python logger module should create 'warn' sentry logs if the flag is on.
357388 """
358- sentry_init (enable_logs = True )
389+ sentry_init (integrations = [ LoggingIntegration ( capture_sentry_logs = True )] )
359390 items = capture_items ("log" )
360391
361392 python_logger = logging .Logger ("test-logger" )
@@ -380,7 +411,7 @@ def test_sentry_logs_debug(sentry_init, capture_envelopes):
380411 """
381412 The python logger module should not create 'debug' sentry logs if the flag is on by default
382413 """
383- sentry_init (enable_logs = True )
414+ sentry_init (integrations = [ LoggingIntegration ( capture_sentry_logs = True )] )
384415 envelopes = capture_envelopes ()
385416
386417 python_logger = logging .Logger ("test-logger" )
@@ -395,8 +426,11 @@ def test_no_log_infinite_loop(sentry_init, capture_envelopes):
395426 If 'debug' mode is true, and you set a low log level in the logging integration, there should be no infinite loops.
396427 """
397428 sentry_init (
398- enable_logs = True ,
399- integrations = [LoggingIntegration (sentry_logs_level = logging .DEBUG )],
429+ integrations = [
430+ LoggingIntegration (
431+ capture_sentry_logs = True , sentry_logs_level = logging .DEBUG
432+ )
433+ ],
400434 debug = True ,
401435 )
402436 envelopes = capture_envelopes ()
@@ -412,7 +446,7 @@ def test_logging_errors(sentry_init, capture_envelopes, capture_items):
412446 """
413447 The python logger module should be able to log errors without erroring
414448 """
415- sentry_init (enable_logs = True )
449+ sentry_init (integrations = [ LoggingIntegration ( capture_sentry_logs = True )] )
416450 envelopes = capture_envelopes ()
417451 items = capture_items ("log" )
418452
@@ -448,8 +482,8 @@ def test_log_strips_project_root(sentry_init, capture_items):
448482 The python logger should strip project roots from the log record path
449483 """
450484 sentry_init (
451- enable_logs = True ,
452485 project_root = "/custom/test" ,
486+ integrations = [LoggingIntegration (capture_sentry_logs = True )],
453487 )
454488 items = capture_items ("log" )
455489
@@ -477,7 +511,7 @@ def test_logger_with_all_attributes(sentry_init, capture_items):
477511 """
478512 The python logger should be able to log all attributes, including extra data.
479513 """
480- sentry_init (enable_logs = True )
514+ sentry_init (integrations = [ LoggingIntegration ( capture_sentry_logs = True )] )
481515 items = capture_items ("log" )
482516
483517 python_logger = logging .Logger ("test-logger" )
@@ -554,7 +588,7 @@ def test_sentry_logs_named_parameters(sentry_init, capture_items):
554588 """
555589 The python logger module should capture named parameters from dictionary arguments in Sentry logs.
556590 """
557- sentry_init (enable_logs = True )
591+ sentry_init (integrations = [ LoggingIntegration ( capture_sentry_logs = True )] )
558592 items = capture_items ("log" )
559593
560594 python_logger = logging .Logger ("test-logger" )
@@ -599,7 +633,7 @@ def test_sentry_logs_named_parameters_complex_values(sentry_init, capture_items)
599633 """
600634 The python logger module should handle complex values in named parameters using safe_repr.
601635 """
602- sentry_init (enable_logs = True )
636+ sentry_init (integrations = [ LoggingIntegration ( capture_sentry_logs = True )] )
603637 items = capture_items ("log" )
604638
605639 python_logger = logging .Logger ("test-logger" )
@@ -633,7 +667,7 @@ def test_sentry_logs_no_parameters_no_template(sentry_init, capture_items):
633667 """
634668 There shouldn't be a template if there are no parameters.
635669 """
636- sentry_init (enable_logs = True )
670+ sentry_init (integrations = [ LoggingIntegration ( capture_sentry_logs = True )] )
637671 items = capture_items ("log" )
638672
639673 python_logger = logging .Logger ("test-logger" )
0 commit comments