Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExceptionDictTransformer issues AttributeError when exc_info = (None, None, None) #656

Closed
yaelmi3 opened this issue Sep 25, 2024 · 0 comments

Comments

@yaelmi3
Copy link
Contributor

yaelmi3 commented Sep 25, 2024

We have been using structlog for a while, along with the ExceptionDictTransformer processor, which integrates wonderfully with DataDog. Recently, we encountered a minor but frustrating issue in our production environment. This issue arose from logging exceptions without the exc_info parameter, for example.

The issue occurs because ExceptionDictTransformer calls extract before exc_info verification opposed to _format_exception which returns MISSING

full trace:

--- Logging error ---
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/logging/__init__.py", line 1110, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/logging/__init__.py", line 953, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/kernel-panic/cronenberg/venv/lib/python3.11/site-packages/structlog/stdlib.py", line 1059, in format
    ed = proc(logger, meth_name, ed)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kernel-panic/cronenberg/venv/lib/python3.11/site-packages/dd_json_logger/custom_processors.py", line 85, in format_exception_as_json
    return ExceptionRenderer(ExceptionDictTransformer(show_locals=False))(logger, name, event_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kernel-panic/cronenberg/venv/lib/python3.11/site-packages/structlog/processors.py", line 412, in __call__
    event_dict["exception"] = self.format_exception(
                              ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kernel-panic/cronenberg/venv/lib/python3.11/site-packages/structlog/tracebacks.py", line 262, in __call__
    trace = extract(
            ^^^^^^^^
  File "/Users/kernel-panic/cronenberg/venv/lib/python3.11/site-packages/structlog/tracebacks.py", line 156, in extract
    exc_type=safe_str(exc_type.__name__),
                      ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__name__'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants