Skip to content

bug: No Pretty traces in Langfuse sessions #6330

@mathg

Description

@mathg

Describe the bug

Hello!

I am using Langfuse @observe decorator integration with Langchain + OpenAI LLM to create my traces on Langfuse. I have access to my traces on Langfuse, but it only offers the json view and there is no button for the Pretty view available.

Thanks for the help!

To reproduce

Could it be because this was built using the old Langchain AgentExecutor instead of LangGraph? Here is how I am doing my integration :

...

from langfuse import Langfuse
from langfuse.decorators import langfuse_context, observe
from langfuse.openai import openai

langfuse = Langfuse()
...

@observe()
def run(self, message: str, uid: str, lang: str = "fr", returnOnlyAgent: str = False) -> str:
    
    # make sure uid is a string
    uid = str(uid)
    
    # Set the session ID using the uid
    langfuse_context.update_current_trace(
        session_id=uid,
    )
    
    # Get the Langchain handler from the context
    langfuse_handler = langfuse_context.get_current_langchain_handler()

    llm = ChatOpenAI(openai_api_key=OPENAI_API_KEY, model=OPENAI_CHAT_MODEL_4, temperature=0, callbacks=[langfuse_handler])
    
    langfuse_prompt = langfuse.get_prompt("guidelines")        
    prompt = langfuse_prompt.get_langchain_prompt(today_full_date=self.today_full_date)
    
    ...

    promptMessages = ChatPromptTemplate.from_messages([
        ("system", prompt),
        MessagesPlaceholder(variable_name='chat_history', optional=True),
        HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['input'], template='{input}')),
        MessagesPlaceholder(variable_name='agent_scratchpad')]
    )
    agent = create_openai_tools_agent(llm, tools, promptMessages)
    agent_chain_convo_exec = AgentExecutor(agent=agent, tools=tools, session_id=uid, memory=memory, verbose=self.use_verbose)
    
    agent_chain_convo_exec = agent_chain_convo_exec.with_config(
        run_name="ChatBot Production"
    )
    
    response = agent_chain_convo_exec.invoke(input_dict, config={"callbacks":[langfuse_handler]})

SDK and container versions

langchain==0.3.22
langchain-core==0.3.50
langchain-openai==0.3.12
langfuse==2.60.2

Additional information

No response

Are you interested to contribute a fix for this bug?

No

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions