Skip to content

Commit

Permalink
fix: fixed unit test to use the context-manager setup for the logging…
Browse files Browse the repository at this point in the history
… setup
  • Loading branch information
a-recknagel committed Aug 28, 2024
1 parent 484615d commit 23eb08b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions opentelemetry-sdk/tests/logs/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,20 @@ def test_log_record_exception(self):

def test_log_record_recursive_exception(self):
"""Exception information will be included in attributes even though it is recursive"""
processor, logger = set_up_test_logging(logging.ERROR)
with set_up_test_logging(logging.ERROR) as (processor, logger):

try:
raise ZeroDivisionError(
ZeroDivisionError(ZeroDivisionError("division by zero"))
)
except ZeroDivisionError:
with self.assertLogs(level=logging.ERROR):
logger.exception("Zero Division Error")
try:
raise ZeroDivisionError(
ZeroDivisionError(ZeroDivisionError("division by zero"))
)
except ZeroDivisionError:
with self.assertLogs(level=logging.ERROR):
logger.exception("Zero Division Error")

log_record = processor.get_log_record(0)

self.assertIsNotNone(log_record)
self.assertEqual(log_record.body, "Zero Division Error")
self.assertIn("Zero Division Error", log_record.body)
self.assertEqual(
log_record.attributes[SpanAttributes.EXCEPTION_TYPE],
ZeroDivisionError.__name__,
Expand Down

0 comments on commit 23eb08b

Please sign in to comment.