Skip to content

Commit e7d72d6

Browse files
committed
feat: add langfuse doc
1 parent 1d807c8 commit e7d72d6

File tree

5 files changed

+171
-1
lines changed

5 files changed

+171
-1
lines changed

docs/ADVANCED_FEATURES-en.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,83 @@ spring:
475475
timeout: 600000 # 10 minute timeout
476476
```
477477

478+
## Langfuse Observability
479+
480+
DataAgent integrates [Langfuse](https://langfuse.com/) as an LLM observability platform, reporting trace data via the OpenTelemetry protocol to help you monitor and analyze agent performance.
481+
482+
### Feature Overview
483+
484+
- **Request Tracing**: Records the full lifecycle of each Graph stream processing (including new queries and human feedback)
485+
- **Token Usage Tracking**: Automatically accumulates prompt tokens and completion tokens per request
486+
- **Error Tracking**: Records exception types and error messages for troubleshooting
487+
- **Rich Metadata**: Records context attributes such as agentId, threadId, nl2sqlOnly, humanFeedback
488+
489+
### Configuration
490+
491+
Configure Langfuse connection in `application.yml`:
492+
493+
```yaml
494+
spring:
495+
ai:
496+
alibaba:
497+
data-agent:
498+
langfuse:
499+
enabled: ${LANGFUSE_ENABLED:true}
500+
host: ${LANGFUSE_HOST:}
501+
public-key: ${LANGFUSE_PUBLIC_KEY:}
502+
secret-key: ${LANGFUSE_SECRET_KEY:}
503+
```
504+
505+
Or configure via environment variables:
506+
507+
```bash
508+
export LANGFUSE_ENABLED=true
509+
export LANGFUSE_HOST=https://cloud.langfuse.com
510+
export LANGFUSE_PUBLIC_KEY=pk-lf-xxx
511+
export LANGFUSE_SECRET_KEY=sk-lf-xxx
512+
```
513+
514+
> For detailed configuration parameters, refer to [Developer Guide - Langfuse Configuration](DEVELOPER_GUIDE-en.md#11-langfuse-observability-configuration).
515+
516+
### Technical Implementation
517+
518+
The system sends trace data to Langfuse via OpenTelemetry OTLP HTTP protocol:
519+
520+
```
521+
GraphServiceImpl
522+
├── startLLMSpan("graph-stream", request) // New query starts
523+
├── startLLMSpan("graph-feedback", request) // Human feedback starts
524+
├── FluxUtil.extractAndAccumulateTokens() // Accumulate tokens during streaming
525+
├── endSpanSuccess(span, threadId, output) // Success completion
526+
└── endSpanError(span, threadId, exception) // Error completion
527+
```
528+
529+
### Span Attributes
530+
531+
| Attribute | Description |
532+
|-----------|-------------|
533+
| `input.value` | Request input (JSON with query, agentId, threadId, etc.) |
534+
| `output.value` | Processing result |
535+
| `gen_ai.usage.prompt_tokens` | Accumulated prompt token count |
536+
| `gen_ai.usage.completion_tokens` | Accumulated completion token count |
537+
| `gen_ai.usage.total_tokens` | Total token count |
538+
| `data_agent.agent_id` | Agent ID |
539+
| `data_agent.thread_id` | Session thread ID |
540+
| `error.type` / `error.message` | Exception type and message (on failure only) |
541+
542+
### Disabling Langfuse
543+
544+
If observability is not needed, set `enabled` to `false`. The system will use a noop OpenTelemetry instance with zero performance overhead:
545+
546+
```yaml
547+
spring:
548+
ai:
549+
alibaba:
550+
data-agent:
551+
langfuse:
552+
enabled: false
553+
```
554+
478555
## Related Documents
479556

480557
- [Quick Start](QUICK_START-en.md) - Basic configuration and installation

docs/ADVANCED_FEATURES.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,59 @@ spring:
474474
timeout: 600000 # 10分钟超时
475475
```
476476

477+
## 📊 Langfuse 可观测性
478+
479+
DataAgent 集成了 [Langfuse](https://langfuse.com/) 作为 LLM 可观测性平台,通过 OpenTelemetry 协议上报追踪数据,帮助您监控和分析智能体的运行状况。
480+
481+
### 功能概述
482+
483+
- **请求追踪**: 记录每次 Graph 流式处理的完整生命周期
484+
- **Token 用量统计**: 累计每次请求的 prompt tokens 和 completion tokens
485+
- **错误追踪**: 记录异常类型和错误信息,便于排查问题
486+
-
487+
### 配置方式
488+
489+
在 `application.yml` 中配置 Langfuse 连接信息:
490+
491+
```yaml
492+
spring:
493+
ai:
494+
alibaba:
495+
data-agent:
496+
langfuse:
497+
enabled: ${LANGFUSE_ENABLED:true}
498+
host: ${LANGFUSE_HOST:}
499+
public-key: ${LANGFUSE_PUBLIC_KEY:}
500+
secret-key: ${LANGFUSE_SECRET_KEY:}
501+
```
502+
503+
或通过环境变量配置:
504+
505+
```bash
506+
export LANGFUSE_ENABLED=true
507+
export LANGFUSE_HOST=https://cloud.langfuse.com
508+
export LANGFUSE_PUBLIC_KEY=pk-lf-xxx
509+
export LANGFUSE_SECRET_KEY=sk-lf-xxx
510+
```
511+
512+
> 配置参数详情请参考 [开发者指南 - Langfuse 配置](DEVELOPER_GUIDE.md#11-langfuse-可观测性配置-langfuse-observability)。
513+
514+
515+
516+
517+
### 禁用 Langfuse
518+
519+
如不需要可观测性功能,设置 `enabled` 为 `false` 即可,系统将使用 noop OpenTelemetry 实例,不会产生任何性能开销:
520+
521+
```yaml
522+
spring:
523+
ai:
524+
alibaba:
525+
data-agent:
526+
langfuse:
527+
enabled: false
528+
```
529+
477530
## 📚 相关文档
478531

479532
- [快速开始](QUICK_START.md) - 基础配置和安装

docs/ARCHITECTURE.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ flowchart LR
3434
Hybrid[HybridRetrievalStrategy]
3535
CodePool[CodePoolExecutorService]
3636
McpSvc[McpServerService]
37+
LangfuseSvc[LangfuseService]
38+
end
39+
40+
subgraph Observability[Observability]
41+
Langfuse[Langfuse Platform]
3742
end
3843
3944
subgraph Data[Data Storage]
@@ -78,6 +83,8 @@ flowchart LR
7883
CodePool --> Docker
7984
CodePool --> Local
8085
CodePool --> AISim
86+
GraphSvc --> LangfuseSvc
87+
LangfuseSvc --> Langfuse
8188
AgentCtl --> MetaDB
8289
PromptCtl --> MetaDB
8390
ModelCtl --> MetaDB
@@ -90,22 +97,25 @@ flowchart LR
9097
classDef data fill:#FEF3C7,stroke:#F59E0B,stroke-width:1px,color:#1F2937;
9198
classDef llm fill:#E0F7FA,stroke:#06B6D4,stroke-width:1px,color:#1F2937;
9299
classDef exec fill:#FFE4E6,stroke:#EF4444,stroke-width:1px,color:#1F2937;
100+
classDef observability fill:#F3E8FF,stroke:#9333EA,stroke-width:1px,color:#1F2937;
93101
94102
class UserUI,AdminUI,MCPClient client
95103
class RestAPI,SSE access
96104
class GraphCtl,AgentCtl,PromptCtl,ModelCtl api
97-
class GraphSvc,Context,LlmSvc,ModelRegistry,VectorSvc,Hybrid,CodePool,McpSvc service
105+
class GraphSvc,Context,LlmSvc,ModelRegistry,VectorSvc,Hybrid,CodePool,McpSvc,LangfuseSvc service
98106
class Graph workflow
99107
class BizDB,MetaDB,VectorDB,Files data
100108
class ChatLLM,EmbeddingLLM llm
101109
class Docker,Local,AISim exec
110+
class Langfuse observability
102111
103112
style Clients fill:#FFF7ED,stroke:#D97706,stroke-width:1.5px
104113
style Access fill:#EFF6FF,stroke:#0284C7,stroke-width:1.5px
105114
style Management fill:#F0FDF4,stroke:#16A34A,stroke-width:1.5px
106115
style Data fill:#FFFBEB,stroke:#F59E0B,stroke-width:1.5px
107116
style LLMs fill:#ECFEFF,stroke:#06B6D4,stroke-width:1.5px
108117
style Exec fill:#FFF1F2,stroke:#EF4444,stroke-width:1.5px
118+
style Observability fill:#FAF5FF,stroke:#9333EA,stroke-width:1.5px
109119
```
110120

111121
## 🔄 运行时主流程

docs/DEVELOPER_GUIDE-en.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,21 @@ Configuration prefix: `spring.ai.alibaba.data-agent.report-template`
364364
| `marked-url` | Marked.js path (Markdown rendering library) | https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/marked/12.0.0/marked.min.js |
365365
| `echarts-url` | ECharts path (chart library) | https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/echarts/5.5.0/echarts.min.js |
366366

367+
### 11. Langfuse Observability Configuration
368+
369+
Configuration prefix: `spring.ai.alibaba.data-agent.langfuse`
370+
371+
| Configuration Item | Description | Default Value |
372+
|-------------------|-------------|---------------|
373+
| `enabled` | Enable Langfuse observability | true |
374+
| `host` | Langfuse service URL (e.g. `https://cloud.langfuse.com` or self-hosted) | - |
375+
| `public-key` | Langfuse project Public Key | - |
376+
| `secret-key` | Langfuse project Secret Key | - |
377+
378+
Environment variables: `LANGFUSE_ENABLED`, `LANGFUSE_HOST`, `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`
379+
380+
> For detailed usage, refer to [Advanced Features - Langfuse Observability](ADVANCED_FEATURES-en.md#langfuse-observability).
381+
367382
## Learning Resources
368383

369384
### Official Documentation

docs/DEVELOPER_GUIDE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,21 @@ public class AgentVectorStoreService {
417417
| `marked-url` | Marked.js 路径 (Markdown渲染库) | https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/marked/12.0.0/marked.min.js |
418418
| `echarts-url` | ECharts 路径 (图表库) | https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/echarts/5.5.0/echarts.min.js |
419419

420+
### 11. Langfuse 可观测性配置 (Langfuse Observability)
421+
422+
配置前缀: `spring.ai.alibaba.data-agent.langfuse`
423+
424+
| 配置项 | 说明 | 默认值 |
425+
|--------|------|--------|
426+
| `enabled` | 是否启用 Langfuse 可观测性 | true |
427+
| `host` | Langfuse 服务地址(如 `https://cloud.langfuse.com` 或自部署地址) | - |
428+
| `public-key` | Langfuse 项目的 Public Key | - |
429+
| `secret-key` | Langfuse 项目的 Secret Key | - |
430+
431+
对应环境变量: `LANGFUSE_ENABLED``LANGFUSE_HOST``LANGFUSE_PUBLIC_KEY``LANGFUSE_SECRET_KEY`
432+
433+
> 详细使用说明请参考 [高级功能 - Langfuse 可观测性](ADVANCED_FEATURES.md#-langfuse-可观测性)
434+
420435
## 📚 学习资源
421436

422437
### 官方文档

0 commit comments

Comments
 (0)