Repository navigation
Trace agent runs and LLM calls in Langfuse - #10
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Until now each request sent one flat Langfuse trace, so we couldn't see which agent node was slow, what prompt the model actually got, or how many tokens each LLM call used. This PR turns every request into a trace tree.
What changed
integrations/langfuse_client.pyand switched to the SDK's sharedget_client().answer_with_agentis the root span.user_id, plussession_idset from the thread id, so a conversation is grouped under one session in Langfuse.record_langfuse_tracewas renamedupdate_langfuse_traceand now usesupdate_current_span.complete_chatis recorded as a generation namedllm:<task>. It records:level=ERROR, with the error message.capture_input=Falseandcapture_output=False, so only the fields we pass explicitly are sent.Testing
LANGFUSE_TRACING_ENABLED=falseintests/conftest.py).langfuse_spansfixture captures spans in memory withInMemorySpanExporter. It turns tracing on only for the tests that ask for it.test_agent_tracing.pychecks two things:test_llm_tracing.pychecks two things:answer_with_agent, then the node spans, thenllm:chat(qwen-plus);Deployment
No config change is needed. The Container App already has
LANGFUSE_PUBLIC_KEY,LANGFUSE_SECRET_KEY(both from secrets),LANGFUSE_BASE_URLandLANGFUSE_TRACING_ENVIRONMENT.After the deploy, ask one question in production and check that a trace shows up in Langfuse under the
azure-devenvironment.Follow-ups (not in this PR)
The first real trace surfaced these:
detect_response_languagecounts marker words, and a tie defaults tode. "Does my car insurance cover glass damage?" contains no English marker, so it is detected asde.core/answer.pydoesn't tell the model which language to answer in, and the prompt scaffolding is German.retrievearen't traced.🤖 Generated with Claude Code