(t *testing.T)
| 197 | } |
| 198 | |
| 199 | func TestTelemetryMiddleware_WrapToolCall(t *testing.T) { |
| 200 | tracer := telemetry.NewSimpleTracer() |
| 201 | |
| 202 | m := NewTelemetryMiddleware(&TelemetryMiddlewareConfig{ |
| 203 | Tracer: tracer, |
| 204 | AgentID: "test-agent", |
| 205 | AgentName: "Test Agent", |
| 206 | ConversationID: "conv-123", |
| 207 | }) |
| 208 | |
| 209 | ctx := context.Background() |
| 210 | req := &ToolCallRequest{ |
| 211 | ToolCallID: "call-123", |
| 212 | ToolName: "read_file", |
| 213 | ToolInput: map[string]any{ |
| 214 | "path": "/tmp/test.txt", |
| 215 | }, |
| 216 | } |
| 217 | |
| 218 | // Mock handler |
| 219 | handler := func(ctx context.Context, req *ToolCallRequest) (*ToolCallResponse, error) { |
| 220 | return &ToolCallResponse{ |
| 221 | Result: map[string]any{ |
| 222 | "content": "file contents", |
| 223 | }, |
| 224 | }, nil |
| 225 | } |
| 226 | |
| 227 | resp, err := m.WrapToolCall(ctx, req, handler) |
| 228 | if err != nil { |
| 229 | t.Fatalf("unexpected error: %v", err) |
| 230 | } |
| 231 | if resp == nil { |
| 232 | t.Fatal("expected response") |
| 233 | } |
| 234 | |
| 235 | // Verify spans |
| 236 | spans := tracer.GetSpans() |
| 237 | if len(spans) != 1 { |
| 238 | t.Fatalf("expected 1 span, got %d", len(spans)) |
| 239 | } |
| 240 | |
| 241 | span := spans[0] |
| 242 | if span.Name() != "execute_tool read_file" { |
| 243 | t.Errorf("expected span name 'execute_tool read_file', got '%s'", span.Name()) |
| 244 | } |
| 245 | |
| 246 | // Verify attributes |
| 247 | attrs := span.Attributes() |
| 248 | attrMap := make(map[string]any) |
| 249 | for _, attr := range attrs { |
| 250 | attrMap[attr.Key] = attr.Value |
| 251 | } |
| 252 | |
| 253 | if attrMap[genai.AttrOperationName] != genai.OpExecuteTool { |
| 254 | t.Errorf("expected operation name '%s', got '%v'", genai.OpExecuteTool, attrMap[genai.AttrOperationName]) |
| 255 | } |
| 256 | if attrMap[genai.AttrToolName] != "read_file" { |
nothing calls this directly
no test coverage detected