Skip to content

Commit b9ee532

Browse files
authored
[chore]: avoid unnecessary temporary variables (#3672)
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 941e355 commit b9ee532

File tree

1 file changed

+3
-9
lines changed
  • opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal

1 file changed

+3
-9
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,22 +462,16 @@ def _get_attributes(record: logging.LogRecord) -> Attributes:
462462
attributes[SpanAttributes.CODE_LINENO] = record.lineno
463463

464464
if record.exc_info:
465-
exc_type = ""
466-
message = ""
467-
stack_trace = ""
468465
exctype, value, tb = record.exc_info
469466
if exctype is not None:
470-
exc_type = exctype.__name__
467+
attributes[SpanAttributes.EXCEPTION_TYPE] = exctype.__name__
471468
if value is not None and value.args:
472-
message = value.args[0]
469+
attributes[SpanAttributes.EXCEPTION_MESSAGE] = value.args[0]
473470
if tb is not None:
474471
# https://github.com/open-telemetry/opentelemetry-specification/blob/9fa7c656b26647b27e485a6af7e38dc716eba98a/specification/trace/semantic_conventions/exceptions.md#stacktrace-representation
475-
stack_trace = "".join(
472+
attributes[SpanAttributes.EXCEPTION_STACKTRACE] = "".join(
476473
traceback.format_exception(*record.exc_info)
477474
)
478-
attributes[SpanAttributes.EXCEPTION_TYPE] = exc_type
479-
attributes[SpanAttributes.EXCEPTION_MESSAGE] = message
480-
attributes[SpanAttributes.EXCEPTION_STACKTRACE] = stack_trace
481475
return attributes
482476

483477
def _translate(self, record: logging.LogRecord) -> LogRecord:

0 commit comments

Comments
 (0)