asyncio
only added full support for passing context in version 3.11.
asyncio
tasks lack proper contextvar
support, which can lead to disconnected traces.
config
to the child call:
ThreadPoolExecutor
by default breaks tracing.
ContextThreadPoolExecutor
that automatically handles context propagation:
get_current_run_tree()
to obtain the current run tree and pass it to the inner function using the langsmith_extra
parameter.
Both methods ensure that the inner function calls are correctly aggregated under the initial trace stack, even when executed in separate threads.