MCPcopy Create free account
hub / github.com/astercloud/aster / ExampleWithError

Function ExampleWithError

pkg/telemetry/integration_example.go:97–117  ·  view source on GitHub ↗

ExampleWithError 演示错误处理和追踪

()

Source from the content-addressed store, hash-verified

95
96// ExampleWithError 演示错误处理和追踪
97func 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 并发场景
120func ExampleConcurrentAgents() {

Callers

nothing calls this directly

Calls 10

StartSpanMethod · 0.95
RecordErrorMethod · 0.95
NewSimpleTracerFunction · 0.85
NewSimpleMetricsFunction · 0.85
NewAgentMetricsFunction · 0.85
PrintfMethod · 0.80
EndMethod · 0.65
RecordErrorMethod · 0.65
SetStatusMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected