agentTracingExample 演示 Agent 执行追踪
()
| 101 | |
| 102 | // agentTracingExample 演示 Agent 执行追踪 |
| 103 | func agentTracingExample() { |
| 104 | ctx := context.Background() |
| 105 | tracer := telemetry.GetGlobalTracer() |
| 106 | |
| 107 | // 模拟 Agent.Chat() 调用 |
| 108 | ctx, span := tracer.StartSpan( |
| 109 | ctx, |
| 110 | "agent.chat", |
| 111 | telemetry.WithSpanKind(telemetry.SpanKindInternal), |
| 112 | telemetry.WithAttributes( |
| 113 | telemetry.String(telemetry.AttrAgentID, "agt_123456"), |
| 114 | telemetry.String(telemetry.AttrAgentName, "customer-support"), |
| 115 | telemetry.String(telemetry.AttrSessionID, "sess_789"), |
| 116 | telemetry.String(telemetry.AttrUserID, "user_001"), |
| 117 | ), |
| 118 | ) |
| 119 | defer span.End() |
| 120 | |
| 121 | // 模拟消息处理 |
| 122 | span.AddEvent("message.received", |
| 123 | telemetry.String("message.content", "Hello, I need help"), |
| 124 | ) |
| 125 | |
| 126 | time.Sleep(50 * time.Millisecond) |
| 127 | |
| 128 | // 模拟中间件处理 |
| 129 | processMiddleware(ctx, span) |
| 130 | |
| 131 | // 模拟 LLM 调用 |
| 132 | processLLM(ctx, span) |
| 133 | |
| 134 | span.SetStatus(telemetry.StatusCodeOK, "Chat completed") |
| 135 | fmt.Println("✅ Agent tracing completed") |
| 136 | } |
| 137 | |
| 138 | // llmTracingExample 演示 LLM 调用追踪 |
| 139 | func llmTracingExample() { |
no test coverage detected