File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -866,6 +866,40 @@ def test_basicConfig_works_with_otel_handler(self):
866866 "basicConfig should add a StreamHandler even when OTel handler exists" ,
867867 )
868868
869+ def test_basicConfig_preserves_otel_handler (self ):
870+ with ClearLoggingHandlers ():
871+ _init_logging (
872+ {"otlp" : DummyOTLPLogExporter },
873+ Resource .create ({}),
874+ setup_logging_handler = True ,
875+ )
876+
877+ root_logger = logging .getLogger ()
878+ self .assertEqual (
879+ len (root_logger .handlers ),
880+ 1 ,
881+ "Should be exactly one OpenTelemetry LoggingHandler" ,
882+ )
883+ handler = root_logger .handlers [0 ]
884+ self .assertIsInstance (handler , LoggingHandler )
885+
886+ logging .basicConfig ()
887+
888+ # Assert that we have a new handler
889+ self .assertGreater (len (root_logger .handlers ), 1 )
890+
891+ # And that our logging handler is still there
892+ logging_handlers = [
893+ h
894+ for h in root_logger .handlers
895+ if isinstance (h , LoggingHandler )
896+ ]
897+ self .assertEqual (
898+ len (logging_handlers ),
899+ 1 ,
900+ "Should still have exactly one OpenTelemetry LoggingHandler" ,
901+ )
902+
869903
870904class TestMetricsInit (TestCase ):
871905 def setUp (self ):
You can’t perform that action at this time.
0 commit comments