MCPcopy Create free account
hub / github.com/hynek/structlog / aexception

Function aexception

src/structlog/_native.py:52–80  ·  view source on GitHub ↗

.. versionchanged:: 23.3.0 Callsite parameters are now also collected under asyncio.

(
    self: FilteringBoundLogger, event: str, *args: Any, **kw: Any
)

Source from the content-addressed store, hash-verified

50
51
52async def aexception(
53 self: FilteringBoundLogger, event: str, *args: Any, **kw: Any
54) -> Any:
55 """
56 .. versionchanged:: 23.3.0
57 Callsite parameters are now also collected under asyncio.
58 """
59 # Exception info has to be extracted this early, because it is no longer
60 # available once control is passed to the executor.
61 if kw.get("exc_info", True) is True:
62 kw["exc_info"] = sys.exc_info()
63
64 # Capture thread-specific info before handing off to the executor.
65 thread_token = _ASYNC_CALLING_THREAD.set(
66 (threading.get_ident(), threading.current_thread().name)
67 )
68 scs_token = _ASYNC_CALLING_STACK.set(sys._getframe().f_back) # type: ignore[arg-type]
69 ctx = contextvars.copy_context()
70
71 try:
72 runner = await asyncio.get_running_loop().run_in_executor(
73 None,
74 lambda: ctx.run(lambda: self.error(event, *args, **kw)),
75 )
76 finally:
77 _ASYNC_CALLING_STACK.reset(scs_token)
78 _ASYNC_CALLING_THREAD.reset(thread_token)
79
80 return runner
81
82
83def make_filtering_bound_logger(

Callers

nothing calls this directly

Calls 2

runMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…