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

Function ameth

src/structlog/_native.py:176–199  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

174 )
175
176 async def ameth(self: Any, event: str, *args: Any, **kw: Any) -> Any:
177 """
178 .. versionchanged:: 23.3.0
179 Callsite parameters are now also collected under asyncio.
180 """
181 event = _maybe_interpolate(event, args)
182
183 # Capture thread-specific info before handing off to the executor.
184 thread_token = _ASYNC_CALLING_THREAD.set(
185 (threading.get_ident(), threading.current_thread().name)
186 )
187 scs_token = _ASYNC_CALLING_STACK.set(sys._getframe().f_back) # type: ignore[arg-type]
188 ctx = contextvars.copy_context()
189
190 try:
191 await asyncio.get_running_loop().run_in_executor(
192 None,
193 lambda: ctx.run(
194 lambda: self._proxy_to_logger(name, event, **kw)
195 ),
196 )
197 finally:
198 _ASYNC_CALLING_STACK.reset(scs_token)
199 _ASYNC_CALLING_THREAD.reset(thread_token)
200
201 meth.__name__ = name
202 ameth.__name__ = f"a{name}"

Callers

nothing calls this directly

Calls 3

_maybe_interpolateFunction · 0.85
runMethod · 0.45
_proxy_to_loggerMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…