Skip to content

fix: support async function tracing in trace_call and trace_function (#595)#600

Open
suhaniiz wants to merge 1 commit into
param20h:devfrom
suhaniiz:bugfix/support-async-tracing-595
Open

fix: support async function tracing in trace_call and trace_function (#595)#600
suhaniiz wants to merge 1 commit into
param20h:devfrom
suhaniiz:bugfix/support-async-tracing-595

Conversation

@suhaniiz

Copy link
Copy Markdown
Contributor

📋 PR Checklist

Thank you for contributing to PDF-Assistant-RAG! 🎉
Please fill out this template before submitting. PRs without it filled in will be closed.


🔗 Related Issue

Closes #595


📝 What does this PR do?

This PR resolves an issue where asynchronous functions (async def) were not being traced properly by LangSmith. Previously, running an async function inside the synchronous wrapper returned an unawaited coroutine object immediately, resulting in inaccurate tracing spans that timed the coroutine creation rather than its actual async lifecyle and execution.

Changes introduced:

  • Utilized inspect.iscoroutinefunction(fn) to check the execution type of target functions.
  • Introduced a dedicated async_trace_call function path that accurately uses await on both the target function and the LangSmith traced function wrapper.
  • Updated the trace_function decorator to dynamically provide an async def async_wrapped execution branch when decorating asynchronous codeblocks.

🗂️ Type of Change

  • 🐛 Bug fix

🧪 How was this tested?

  • Ran backend operations locally (uvicorn app.main:app --reload).
  • Verified that asynchronous functions (such as concurrent LLM API calls and embedding lookups) correctly await their results and produce accurate execution traces inside LangSmith without hanging or throwing unawaited coroutine warnings.

📸 Screenshots (if UI change)

N/A


⚠️ Anything to flag for reviewers?

None. Synchronous paths remain identical and un-impacted by this change.


✅ Self-Review Checklist

  • My branch is based on dev, not main
  • I have not added any secrets / API keys
  • I have not modified main branch or any HuggingFace deployment config
  • My code follows the existing style (no unnecessary formatting changes)
  • I have updated relevant docs / comments if needed

@suhaniiz suhaniiz requested a review from param20h as a code owner June 13, 2026 13:38
@suhaniiz

Copy link
Copy Markdown
Contributor Author

hey @param20h , this pr is under gssoc 2026, lemme know if any changes are needed.

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

Successfully merging this pull request may close these issues.

[BUG] support async function tracing in trace_call and trace_function

1 participant