Find answers from the community

Updated 2 months ago

Add Langfuse Tracing To Retriever And Stream Response

At a glance

The community member is trying to add langfuse tracing to their retriever and stream the response, but their script never exits when they use the instrumentor.observe() wrapper. Without the wrapper, the script streams the response and exits as expected. A comment suggests that the session_id parameter is optional and the instrumentor will generate the values if they are not provided.

Hey there, I've got hopefully an easy question: I'm trying to add langfuse tracing to my retriever and also stream the response. I've got something like:

Plain Text
@observe()
async def query():
(...)
   with instrumentor.observe(
        session_id=session_id,
    ) as trace:
        retriever = RAGRetriever()
        retriever_result = await retriever.run(
            query="(my query)",
            index=retriever_index,
        )
    async for chunk in retriever_result.async_response_gen():
        print(chunk, end="", flush=True)
    instrumentor.flush()


if __name__ == "__main__":
    import asyncio
    asyncio.run(query())


The issue I'm having is my script never exits. If I remove the instrumentor.observe() wrapper it streams my response and exits as I expect. What am I missing?
s
1 comment
Thanks, but session_id is just an optional parameter, as are the others in that doc. It’ll generate those values (or omit them) if they’re not there, but that’s all
Add a reply
Sign up and join the conversation on Discord