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

Asyncio : trace_to_thread raise exception when func doesn't has __name__ attribute #4207

Open
JulienStitelet opened this issue Sep 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@JulienStitelet
Copy link

Describe your environment

OS: macos
Python version: 3.11.9
SDK version: 1.27.0
API version: 0.48b0

What happened?

On a fastapi app,
During async stream call to a LLM,
Using Langgraph lib, somehow when reaching this def trace_to_thread(self, func: callable): a partial func is send, without name attribute :

image

So, the statement if func.__name__ in self._to_thread_name_to_trace is raising an exception, and killing the whole process (not the server)

Steps to Reproduce

The point is I don't own the langgraph lib so I don't know (and I could not figure out) how it's done.
But the problem is pretty easy to understand.

Expected Result

As a telemetry tool, I don't want it to break my app.
worst is it doesn't do the metrics BUT error log it.

Actual Result

Exception raised

Additional context

Can be fix easily like :

     func_name = func.__name__ if hasattr(func, "__name__") and func.__name__ in self._to_thread_name_to_trace else None

      span = (
          self._tracer.start_span(
              f"{ASYNCIO_PREFIX} to_thread-" + func_name
          )
          if func_name and func_name in self._to_thread_name_to_trace
          else None
      )
attr = {"type": "to_thread", "name": func_name}

Would you like to implement a fix?

Yes

@JulienStitelet JulienStitelet added the bug Something isn't working label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant