Skip to content

Commit

Permalink
fix: remove mock from tests and improve get qualname
Browse files Browse the repository at this point in the history
  • Loading branch information
emdneto committed Apr 6, 2024
1 parent 859e0bb commit a06a30c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 4 additions & 3 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,12 +997,13 @@ def record_exception(
)
module = (
exception.__module__
if exception.__class__.__module__ != "builtins"
if type(exception).__module__ != "builtins"
else ""
)
qualname = type(exception).__qualname__
exc_type = (
f"{module}.{exception.__class__.__qualname__}"
if module else exception.__class__.__qualname__
f"{module}.{qualname}"
if module else qualname
)
_attributes: MutableMapping[str, types.AttributeValue] = {
"exception.type": exc_type,
Expand Down
11 changes: 4 additions & 7 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,19 +1150,16 @@ def error_status_test(context):

def test_record_exception_fqn(self):
span = trace._Span("name", mock.Mock(spec=trace_api.SpanContext))
module_name = "dummy.module"
with mock.patch.object(DummyError, "__module__", module_name):
try:
raise DummyError("error")
except DummyError as err:
span.record_exception(err)
exception = DummyError("error")
exception_type = f"{exception.__module__}.{type(exception).__qualname__}"
span.record_exception(exception)
exception_event = span.events[0]
self.assertEqual("exception", exception_event.name)
self.assertEqual(
"error", exception_event.attributes["exception.message"]
)
self.assertEqual(
f"{module_name}.DummyError",
exception_type,
exception_event.attributes["exception.type"],
)
self.assertIn(
Expand Down

0 comments on commit a06a30c

Please sign in to comment.