本页还没有译文
本页 53 段还没译成Español,下面显示的是英文原文。Trace Augment Code with Langfuse
还没翻译译自英文(langfuse.com)本页 53 段都还没译
Augment Code Tracing with Langfuse
What is Augment Code? Augment Code is an agentic AI platform specifically engineered for professional teams, featuring a specialized Context Engine that maintains a deep, semantic understanding of large-scale, multi-repository codebases. It utilizes autonomous agents to plan and execute end-to-end development tasks from complex refactors and high-precision code reviews to implementing full features directly from Jira or Linear tickets while ensuring architectural consistency and security compliance.
What is Langfuse? Langfuse is the open-source LLM engineering platform. It helps teams trace AI workflows, debug issues, evaluate quality, and monitor usage in production. Use Langfuse Cloud (hosted by Langfuse, free tier, no infrastructure to run) or self-host it.
What Can This Integration Trace?
By using Augment's hooks system, this integration captures both per-tool activity and the final conversation summary, then sends them to Langfuse. In this documentation you'll leverage 2 hooks to monitor:
- User prompts and assistant responses from the final conversation payload
- Per-tool executions through the
PostToolUsehook - Tool metadata such as tool name, MCP details, timestamps, and error state
- File-change context recorded after tool calls
- Conversation-level traces emitted by the
Stophook - Generation and tool observations nested under the final conversation trace
UX Demo
1min demo of the tracing UX Auggie CLI => Langfuse
How It Works
Augment supports globally registered hooks in ~/.augment/settings.json. This integration uses both the PostToolUse and Stop hooks.
- Global hooks are configured to run after each tool call and after each completed Augment response.
- The shell wrapper scripts receive Augment's hook payload on
stdin, write local audit entries, and forward the unchanged JSON payload to Python. - The Python scripts load Langfuse configuration, convert Augment payloads into Langfuse traces and observations, and fail open if tracing is disabled or config is missing.
- Tracing is opt-in per workspace because the Python scripts first search the active workspace roots for
.env.langfuse.local, then fall back to~/.augment/hooksand~/.augment.
Quick Start
Set up Langfuse
- Sign up for Langfuse Cloud or self-host Langfuse.
- Create a new project and copy your API keys from the project settings.
Install Dependencies
Make sure the machine running Augment has:
jq/usr/bin/python3- the Python
langfusepackage
Install the Python SDK and create the hooks directory:
python3 -m pip install langfuse
mkdir -p ~/.augment/hooksCreate the Hook Files
Create these four files under ~/.augment/hooks/:
~/.augment/hooks/
├── langfuse_hook_posttooluse.sh
├── langfuse_hook_posttooluse.py
├── langfuse_hook_stop.sh
└── langfuse_hook_stop.pyUse the shell wrappers as the executable hook entry points, and use the Python files for the Langfuse tracing logic.
Make the shell wrappers executable:
chmod +x ~/.augment/hooks/langfuse_hook_stop.sh
chmod +x ~/.augment/hooks/langfuse_hook_posttooluse.shRegister the Hook
Add both hooks to your global Augment settings at ~/.augment/settings.json:
{
"hooks": {
"PostToolUse": [
{
"hooks": [
{
"type": "command",
"command": "~/.augment/hooks/langfuse_hook_posttooluse.sh"
}
],
"metadata": {
"includeConversationData": true,
"includeUserContext": true
}
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "~/.augment/hooks/langfuse_hook_stop.sh"
}
],
"metadata": {
"includeConversationData": true,
"includeUserContext": true
}
}
]
}
}This registers the hooks globally so they run for all Augment sessions.
Enable Tracing Per-Project
For each workspace where you want tracing enabled, create a .env.langfuse.local file in the workspace root:
TRACE_TO_LANGFUSE=true
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...
LANGFUSE_BASE_URL=https://cloud.langfuse.com
AUGGIE_LANGFUSE_DEBUG=false
AUGGIE_LANGFUSE_MAX_CHARS=20000Note
Tracing is opt-in per workspace. The hooks are installed globally, but the Python scripts immediately exit unless TRACE_TO_LANGFUSE is set to "true" in a discovered .env.langfuse.local file.
The Python hooks look for .env.langfuse.local in this order:
- the current workspace roots
~/.augment/hooks~/.augment
Environment Variables:
| Variable | Description | Required |
|---|---|---|
TRACE_TO_LANGFUSE | Set to "true" to enable tracing | Yes |
LANGFUSE_PUBLIC_KEY | Your Langfuse public key | Yes |
LANGFUSE_SECRET_KEY | Your Langfuse secret key | Yes |
LANGFUSE_BASE_URL | Langfuse base URL (https://cloud.langfuse.com for EU, https://us.cloud.langfuse.com for US) | No (defaults to EU) |
AUGGIE_LANGFUSE_DEBUG | Set to "true" for verbose debug logging | No |
AUGGIE_LANGFUSE_MAX_CHARS | Max characters kept per field (default 20000) | No |
Start Using Augment Code
Now open a workspace with tracing enabled and use Augment normally. Once the hooks are registered, PostToolUse and Stop events are sent automatically whenever tracing is enabled.
View Traces in Langfuse
Open your Langfuse project to see the captured traces. You'll see:
PostToolUse – <tool>traces for individual tool executions, including file changes, error state, user/model/timestamp details, and MCP metadata.Auggie Conversationtraces from theStophook, containing the final conversation-level generation plus extracted tool observations from the full payload.
Troubleshooting
No traces appearing in Langfuse
- Confirm
.env.langfuse.localis present in the workspace root,~/.augment/hooks, or~/.augment. - Verify
TRACE_TO_LANGFUSE=trueand confirm the Langfuse keys are populated. - Check the local hook logs:
tail -f /tmp/auggie-hook-stop.log
tail -f /tmp/auggie-hook-posttooluse.log
tail -f ~/.augment/hooks/langfuse_hook_stop.log
tail -f ~/.augment/hooks/langfuse_hook_posttooluse.log- Verify the Python dependency is importable:
/usr/bin/python3 -c "import langfuse; print('langfuse ok')"Hooks are registered but still not sending traces
- Make sure both hook commands in
~/.augment/settings.jsonpoint to executable shell scripts. - Confirm the shell wrappers forward the original payload to the Python scripts instead of consuming it.
- Check
~/.augment/audit-api.jsonlto confirm the shell wrappers are receiving events even if Langfuse emission fails. - Remember that this setup is designed to fail open: Augment continues even if tracing fails, so the logs are the best source of truth.
Authentication or region issues
Verify the keys and base URL in .env.langfuse.local:
- EU Cloud:
https://cloud.langfuse.com - US Cloud:
https://us.cloud.langfuse.com - Self-hosted: your own Langfuse base URL