Skip to content

Commit

Permalink
fix: improve if statements and hardcode exception_type in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emdneto committed Apr 8, 2024
1 parent a06a30c commit 884d8ba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
13 changes: 3 additions & 10 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,18 +995,11 @@ def record_exception(
type(exception), value=exception, tb=exception.__traceback__
)
)
module = (
exception.__module__
if type(exception).__module__ != "builtins"
else ""
)
module = type(exception).__module__
qualname = type(exception).__qualname__
exc_type = (
f"{module}.{qualname}"
if module else qualname
)
exception_type = f"{module}.{qualname}" if module and module != "builtins" else qualname
_attributes: MutableMapping[str, types.AttributeValue] = {
"exception.type": exc_type,
"exception.type": exception_type,
"exception.message": str(exception),
"exception.stacktrace": stacktrace,
"exception.escaped": str(escaped),
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ def error_status_test(context):
def test_record_exception_fqn(self):
span = trace._Span("name", mock.Mock(spec=trace_api.SpanContext))
exception = DummyError("error")
exception_type = f"{exception.__module__}.{type(exception).__qualname__}"
exception_type = "tests.trace.test_trace.DummyError"
span.record_exception(exception)
exception_event = span.events[0]
self.assertEqual("exception", exception_event.name)
Expand Down

0 comments on commit 884d8ba

Please sign in to comment.