add langfuse tracing#39
Conversation
Dokploy Preview Deployment
|
📝 WalkthroughWalkthroughThe pull request adds optional Langfuse observability for LLM tracing by introducing a cached credential-driven factory function, exporting it at the tracing module level, integrating it into the chat server to conditionally attach callbacks and user/session metadata to graph invocations, and documenting configuration requirements. ChangesLangfuse Observability Integration
Sequence DiagramsequenceDiagram
participant User
participant ChatEndpoint as Chat Endpoint
participant GetHandler as get_langfuse_handler()
participant GraphInvoke as LangGraph Invoke
participant LLMCall as LLM Call
User->>ChatEndpoint: Send chat message
ChatEndpoint->>GetHandler: Obtain handler (cached)
GetHandler-->>ChatEndpoint: CallbackHandler or None
ChatEndpoint->>ChatEndpoint: Build invocation config<br/>with optional callbacks/metadata
ChatEndpoint->>GraphInvoke: Invoke with config
GraphInvoke->>LLMCall: Call LLM
LLMCall-->>GraphInvoke: Response
GraphInvoke-->>ChatEndpoint: Result
ChatEndpoint-->>User: Chat response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
README.md (1)
94-102: ⚡ Quick winConsider adding an example for
LANGFUSE_BASE_URL.The documentation provides clear examples for the Public and Secret keys, but the
LANGFUSE_BASE_URLrow has an empty example column. Consider adding an example likehttps://cloud.langfuse.comorhttps://us.cloud.langfuse.com(as mentioned in.env.exampleline 109) to help users configure this variable correctly.📝 Suggested addition
| Variable | Descripción | Ejemplo | | --- | --- | --- | | `LANGFUSE_PUBLIC_KEY` | Clave pública del proyecto (Langfuse UI → Settings → API Keys) | `pk-lf-...` | | `LANGFUSE_SECRET_KEY` | Clave secreta del proyecto | `sk-lf-...` | -| `LANGFUSE_BASE_URL` | Host de Langfuse. | | +| `LANGFUSE_BASE_URL` | Host de Langfuse. | `https://cloud.langfuse.com` |🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@README.md` around lines 94 - 102, Update the README table row for LANGFUSE_BASE_URL to include a concrete example URL (e.g., "https://cloud.langfuse.com" or "https://us.cloud.langfuse.com") in the Example column so users have a clear reference for valid values; locate the LANGFUSE (Trazabilidad) section and the table containing `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, and `LANGFUSE_BASE_URL` and add the example text to the `LANGFUSE_BASE_URL` example cell.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/pyproject.toml`:
- Line 66: The Langfuse client is being constructed using the deprecated host
parameter; update the Langfuse(...) instantiation (look for the call to Langfuse
in the codebase) to replace host=base_url with base_url=base_url so it matches
langfuse>=4.0.0's API; ensure any variable name (base_url) is unchanged and run
tests/imports to confirm the new parameter is accepted.
---
Nitpick comments:
In `@README.md`:
- Around line 94-102: Update the README table row for LANGFUSE_BASE_URL to
include a concrete example URL (e.g., "https://cloud.langfuse.com" or
"https://us.cloud.langfuse.com") in the Example column so users have a clear
reference for valid values; locate the LANGFUSE (Trazabilidad) section and the
table containing `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, and
`LANGFUSE_BASE_URL` and add the example text to the `LANGFUSE_BASE_URL` example
cell.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1c7dc1ae-cd16-4616-aa2a-0903d08f30d4
⛔ Files ignored due to path filters (1)
backend/uv.lockis excluded by!**/*.lock
📒 Files selected for processing (6)
.env.exampleREADME.mdbackend/pyproject.tomlbackend/server.pybackend/src/tracing/__init__.pybackend/src/tracing/langfuse_setup.py
| "langchain-core==1.2.18", | ||
| "langchain-openai==1.1.11", | ||
| "langchain-text-splitters==1.1.1", | ||
| "langfuse>=4.0.0,<5.0.0", |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify langfuse package version availability on PyPI
echo "Checking langfuse versions on PyPI..."
curl -s https://pypi.org/pypi/langfuse/json | jq -r '.releases | keys[]' | grep '^4\.' | head -20Repository: in2ai/ASM2-client
Length of output: 218
🌐 Web query:
Does langfuse 4.0.0 or higher exist? What is the correct parameter name for the Langfuse constructor to set the base URL/host in version 4.x?
💡 Result:
Yes, Langfuse Python SDK version 4.0.0 and higher exist. The latest version is 4.6.1 as of May 2026.[1][2] In version 4.x, the correct parameter name for the Langfuse constructor to set the base URL/host is base_url. The host parameter is deprecated; use base_url instead.[3][2][4][5][6]
Citations:
- 1: https://pypi.org/project/langfuse/
- 2: https://python.reference.langfuse.com/langfuse
- 3: https://python.reference.langfuse.com/langfuse.html
- 4: https://langfuse.com/docs/sdk/python/example
- 5: https://langfuse.com/guides/cookbook/example_data_migration
- 6: chore(client): move to LANGFUSE_BASE_URL langfuse/langfuse-python#1418
🏁 Script executed:
cat -n backend/src/tracing/langfuse_setup.pyRepository: in2ai/ASM2-client
Length of output: 1191
Replace host parameter with base_url in Langfuse constructor call.
Langfuse version 4.0.0 exists and is available on PyPI. However, the code at line 24 uses the deprecated host parameter when instantiating Langfuse(). In version 4.x, the correct parameter is base_url. Change host=base_url to base_url=base_url to ensure compatibility with the pinned version constraint.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@backend/pyproject.toml` at line 66, The Langfuse client is being constructed
using the deprecated host parameter; update the Langfuse(...) instantiation
(look for the call to Langfuse in the codebase) to replace host=base_url with
base_url=base_url so it matches langfuse>=4.0.0's API; ensure any variable name
(base_url) is unchanged and run tests/imports to confirm the new parameter is
accepted.
Summary by CodeRabbit
Release Notes
New Features
Documentation
Chores