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

Method setErrorTypeAttribute

pkg/middleware/telemetry.go:350–377  ·  view source on GitHub ↗

setErrorTypeAttribute 设置错误类型属性

(span telemetry.Span, err error)

Source from the content-addressed store, hash-verified

348
349// setErrorTypeAttribute 设置错误类型属性
350func (m *TelemetryMiddleware) setErrorTypeAttribute(span telemetry.Span, err error) {
351 errStr := err.Error()
352 var errType string
353
354 // 简单的错误类型推断
355 switch {
356 case contains(errStr, "timeout"):
357 errType = genai.ErrorTypeTimeout
358 case contains(errStr, "rate limit") || contains(errStr, "429"):
359 errType = genai.ErrorTypeRateLimit
360 case contains(errStr, "authentication") || contains(errStr, "401"):
361 errType = genai.ErrorTypeAuthentication
362 case contains(errStr, "permission") || contains(errStr, "403"):
363 errType = genai.ErrorTypePermission
364 case contains(errStr, "not found") || contains(errStr, "404"):
365 errType = genai.ErrorTypeNotFound
366 case contains(errStr, "context length") || contains(errStr, "too long"):
367 errType = genai.ErrorTypeContextLengthExceeded
368 case contains(errStr, "content filter") || contains(errStr, "blocked"):
369 errType = genai.ErrorTypeContentFilter
370 case contains(errStr, "500") || contains(errStr, "server error"):
371 errType = genai.ErrorTypeServerError
372 default:
373 errType = "unknown"
374 }
375
376 span.SetAttributes(telemetry.String(genai.AttrErrorType, errType))
377}
378
379// contains 检查字符串是否包含子串 (case-insensitive)
380func contains(s, substr string) bool {

Callers 1

WrapModelCallMethod · 0.95

Calls 4

StringFunction · 0.92
containsFunction · 0.70
ErrorMethod · 0.65
SetAttributesMethod · 0.65

Tested by

no test coverage detected