Skip to content

Commit

Permalink
[chore]: avoid unnecessary temporary variables (#3672)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Feb 8, 2024
1 parent 941e355 commit b9ee532
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,22 +462,16 @@ def _get_attributes(record: logging.LogRecord) -> Attributes:
attributes[SpanAttributes.CODE_LINENO] = record.lineno

if record.exc_info:
exc_type = ""
message = ""
stack_trace = ""
exctype, value, tb = record.exc_info
if exctype is not None:
exc_type = exctype.__name__
attributes[SpanAttributes.EXCEPTION_TYPE] = exctype.__name__
if value is not None and value.args:
message = value.args[0]
attributes[SpanAttributes.EXCEPTION_MESSAGE] = value.args[0]
if tb is not None:
# https://github.com/open-telemetry/opentelemetry-specification/blob/9fa7c656b26647b27e485a6af7e38dc716eba98a/specification/trace/semantic_conventions/exceptions.md#stacktrace-representation
stack_trace = "".join(
attributes[SpanAttributes.EXCEPTION_STACKTRACE] = "".join(
traceback.format_exception(*record.exc_info)
)
attributes[SpanAttributes.EXCEPTION_TYPE] = exc_type
attributes[SpanAttributes.EXCEPTION_MESSAGE] = message
attributes[SpanAttributes.EXCEPTION_STACKTRACE] = stack_trace
return attributes

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

0 comments on commit b9ee532

Please sign in to comment.