ExampleWithError 演示错误处理和追踪
()
| 95 | |
| 96 | // ExampleWithError 演示错误处理和追踪 |
| 97 | func ExampleWithError() { |
| 98 | tracer := NewSimpleTracer() |
| 99 | metrics := NewSimpleMetrics() |
| 100 | agentMetrics := NewAgentMetrics(metrics) |
| 101 | |
| 102 | ctx := context.Background() |
| 103 | agentID := "agent-002" |
| 104 | |
| 105 | _, span := tracer.StartSpan(ctx, "agent.chat") |
| 106 | defer span.End() |
| 107 | |
| 108 | // 模拟错误 |
| 109 | err := errors.New("model API timeout") |
| 110 | span.RecordError(err) |
| 111 | span.SetStatus(StatusCodeError, err.Error()) |
| 112 | |
| 113 | // 记录错误指标 |
| 114 | agentMetrics.RecordError(agentID, "timeout") |
| 115 | |
| 116 | fmt.Printf("❌ Error recorded: %v\n", err) |
| 117 | } |
| 118 | |
| 119 | // ExampleConcurrentAgents 演示多 Agent 并发场景 |
| 120 | func ExampleConcurrentAgents() { |
nothing calls this directly
no test coverage detected