feat: Eino nodes 迁移到 trace 包(Phase 6.2)

- nodes_stt.go 使用 trace.FromContext 替换 logger.Log
- nodes_history.go 使用 trace.FromContext
- nodes_tts.go 使用 trace.FromContext
- nodes_done.go 使用 trace.FromContext
- 移除所有 nodes 中的 request_id 手动字段(自动附加)
- 所有日志消息改为英文
This commit is contained in:
hhs
2026-06-21 22:36:15 +08:00
parent ad700743ef
commit 76d331c885
4 changed files with 24 additions and 30 deletions

View File

@@ -8,8 +8,8 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/hhs/camtalk/internal/ai/stt"
"github.com/hhs/camtalk/internal/logger"
"github.com/hhs/camtalk/internal/models"
"github.com/hhs/camtalk/internal/trace"
"github.com/hhs/camtalk/internal/util"
)
@@ -21,7 +21,7 @@ import (
// 识别结果通过 Sender 发送 stt_result 到客户端。
func NewSTTLambda(sttService stt.Service) *compose.Lambda {
return compose.InvokableLambda(func(ctx context.Context, input PipelineInput) (STTOutput, error) {
log := logger.Log
log := trace.FromContext(ctx)
sender := senderFromCtx(ctx)
requestID := requestIDFromCtx(ctx)
@@ -41,7 +41,6 @@ func NewSTTLambda(sttService stt.Service) *compose.Lambda {
// 文本输入模式:跳过 STT
if input.Text != "" {
log.Debugw("text input mode, skipping stt",
"request_id", requestID,
"text_len", len(input.Text),
"text_preview", util.Truncate(input.Text, 50))
@@ -53,7 +52,7 @@ func NewSTTLambda(sttService stt.Service) *compose.Lambda {
Text: input.Text,
IsFinal: true,
}); err != nil {
log.Errorw("发送 stt_result 失败", "error", err)
log.Errorw("send stt_result failed", "error", err)
}
}
@@ -76,8 +75,7 @@ func NewSTTLambda(sttService stt.Service) *compose.Lambda {
return STTOutput{}, fmt.Errorf("stt: no audio data provided")
}
log.Infow("开始语音识别",
"request_id", requestID, "audio_bytes", len(input.AudioData))
log.Infow("stt recognition started", "audio_bytes", len(input.AudioData))
// 调用 STT 服务
text, err := sttService.Recognize(ctx, input.AudioData, stt.Options{
@@ -86,7 +84,7 @@ func NewSTTLambda(sttService stt.Service) *compose.Lambda {
Language: input.Language,
})
if err != nil {
log.Errorw("语音识别失败", "error", err, "request_id", requestID)
log.Errorw("stt recognition failed", "error", err)
if sender != nil {
sender.SendError(models.WsError{
Type: "error",
@@ -100,12 +98,11 @@ func NewSTTLambda(sttService stt.Service) *compose.Lambda {
// STT 返回空文本
if strings.TrimSpace(text) == "" {
log.Infow("语音识别结果为空", "request_id", requestID)
log.Infow("stt returned empty text")
text = "(未识别到语音)"
}
log.Debugw("stt recognition completed",
"request_id", requestID,
"text_len", len(text),
"text_preview", util.Truncate(text, 50))
@@ -117,7 +114,7 @@ func NewSTTLambda(sttService stt.Service) *compose.Lambda {
Text: text,
IsFinal: true,
}); err != nil {
log.Errorw("发送 stt_result 失败", "error", err)
log.Errorw("send stt_result failed", "error", err)
}
}