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

Cannot use ConsoleRenderer with dict_tracebacks #681

Open
vikigenius opened this issue Dec 1, 2024 · 2 comments
Open

Cannot use ConsoleRenderer with dict_tracebacks #681

vikigenius opened this issue Dec 1, 2024 · 2 comments

Comments

@vikigenius
Copy link

I want to use dict_tracebacks so that I can get logfire access to the exception key.
Here is my list of processors

            structlog.contextvars.merge_contextvars,
            structlog.processors.add_log_level,
            structlog.processors.dict_tracebacks,
            structlog.dev.set_exc_info,
            structlog.processors.TimeStamper(fmt="iso"),
            logfire.StructlogProcessor(),
            structlog.dev.ConsoleRenderer(
                colors=True, exception_formatter=RichTracebackFormatter(max_frames=1, show_locals=False, width=80)
            ),

I thought adding the structlog.dev.set_exc_info would cause exc_info to be set to True which would make it work with the ConsoleRenderer.

But it is being called with method error instead of exception which means it is not setting exc_info to True and this causes an error

TypeError: can only concatenate str (not "list") to str

  File "/home/void/Projects/Python/chatpyre/.venv/lib/python3.12/site-packages/structlog/_native.py", line 45, in exception
    return self.error(event, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/void/Projects/Python/chatpyre/.venv/lib/python3.12/site-packages/structlog/_native.py", line 134, in meth
    return self._proxy_to_logger(name, event, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/void/Projects/Python/chatpyre/.venv/lib/python3.12/site-packages/structlog/_base.py", line 214, in _proxy_to_logger
    args, kw = self._process_event(method_name, event, event_kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/void/Projects/Python/chatpyre/.venv/lib/python3.12/site-packages/structlog/_base.py", line 165, in _process_event
    event_dict = proc(self._logger, method_name, event_dict)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/void/Projects/Python/chatpyre/.venv/lib/python3.12/site-packages/structlog/dev.py", line 749, in __call__
    sio.write("\n" + exc)
@sscherfke
Copy link
Contributor

dict-tracebacks are only meant to be used with JSON output. The Rich traceback printing has the same features but nicer looking. :-)

@hynek
Copy link
Owner

hynek commented Dec 7, 2024

yeah, this is the dev module is for… development. :) what exactly are you trying to achieve here, practically speaking?

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

3 participants