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

Function agentTracingExample

examples/telemetry/main.go:103–136  ·  view source on GitHub ↗

agentTracingExample 演示 Agent 执行追踪

()

Source from the content-addressed store, hash-verified

101
102// agentTracingExample 演示 Agent 执行追踪
103func 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 调用追踪
139func llmTracingExample() {

Callers 1

mainFunction · 0.85

Calls 10

GetGlobalTracerFunction · 0.92
WithSpanKindFunction · 0.92
WithAttributesFunction · 0.92
StringFunction · 0.92
processMiddlewareFunction · 0.85
processLLMFunction · 0.85
StartSpanMethod · 0.65
EndMethod · 0.65
AddEventMethod · 0.65
SetStatusMethod · 0.65

Tested by

no test coverage detected