From 884d8babbac2fe53c336834b30cf4f306e719b7a Mon Sep 17 00:00:00 2001 From: emdneto <9735060+emdneto@users.noreply.github.com> Date: Mon, 8 Apr 2024 07:43:16 -0300 Subject: [PATCH] fix: improve if statements and hardcode exception_type in tests --- .../src/opentelemetry/sdk/trace/__init__.py | 13 +++---------- opentelemetry-sdk/tests/trace/test_trace.py | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 7abf2f2c0ef..a82aa1c1d3b 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -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), diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 0220ae726cc..72c7095da70 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -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)