@@ -842,30 +842,61 @@ def test_initialize_components_kwargs(
842842
843843 def test_basicConfig_works_with_otel_handler (self ):
844844 with ClearLoggingHandlers ():
845- # Initialize auto-instrumentation with logging enabled
846845 _init_logging (
847846 {"otlp" : DummyOTLPLogExporter },
848847 Resource .create ({}),
849848 setup_logging_handler = True ,
850849 )
851850
852- # Call basicConfig - this should work despite OTel handler being present
851+ # Call the patched basicConfig
853852 logging .basicConfig (level = logging .INFO )
854853
855- # Verify a StreamHandler was added
856854 root_logger = logging .getLogger ()
857855 stream_handlers = [
858856 h
859857 for h in root_logger .handlers
860858 if isinstance (h , logging .StreamHandler )
861- and not isinstance (h , LoggingHandler )
862859 ]
863860 self .assertEqual (
864861 len (stream_handlers ),
865862 1 ,
866863 "basicConfig should add a StreamHandler even when OTel handler exists" ,
867864 )
868865
866+ def test_basicConfig_preserves_otel_handler (self ):
867+ with ClearLoggingHandlers ():
868+ _init_logging (
869+ {"otlp" : DummyOTLPLogExporter },
870+ Resource .create ({}),
871+ setup_logging_handler = True ,
872+ )
873+
874+ root_logger = logging .getLogger ()
875+ self .assertEqual (
876+ len (root_logger .handlers ),
877+ 1 ,
878+ "Should be exactly one OpenTelemetry LoggingHandler" ,
879+ )
880+ handler = root_logger .handlers [0 ]
881+ self .assertIsInstance (handler , LoggingHandler )
882+
883+ logging .basicConfig ()
884+
885+ # Assert that we have a new handler
886+ self .assertGreater (len (root_logger .handlers ), 1 )
887+
888+ # And that our logging handler is still there
889+ logging_handlers = [
890+ h
891+ for h in root_logger .handlers
892+ if isinstance (h , LoggingHandler )
893+ ]
894+ self .assertEqual (
895+ len (logging_handlers ),
896+ 1 ,
897+ "Should still have exactly one OpenTelemetry LoggingHandler" ,
898+ )
899+
869900
870901class TestMetricsInit (TestCase ):
871902 def setUp (self ):
0 commit comments