Skip to content

Commit d3658be

Browse files
committed
Add unit test
1 parent 992c0e5 commit d3658be

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

opentelemetry-sdk/tests/test_configurator.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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

870904
class TestMetricsInit(TestCase):
871905
def setUp(self):

0 commit comments

Comments
 (0)