Skip to content

Commit acbfe22

Browse files
fix(go): Debug logs change from fmt.Sprintf("%#v",d) to serialized JSON in []byte (#3717)
1 parent f7257e1 commit acbfe22

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

go/ai/generate.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ type ModelOptions struct {
115115
func DefineGenerateAction(ctx context.Context, r api.Registry) *generateAction {
116116
return (*generateAction)(core.DefineStreamingAction(r, "generate", api.ActionTypeUtil, nil, nil,
117117
func(ctx context.Context, actionOpts *GenerateActionOptions, cb ModelStreamCallback) (resp *ModelResponse, err error) {
118+
actionOptsBytes, _ := json.Marshal(actionOpts)
118119
logger.FromContext(ctx).Debug("GenerateAction",
119-
"input", fmt.Sprintf("%#v", actionOpts))
120+
"input", actionOptsBytes)
120121
defer func() {
122+
respBytes, _ := json.Marshal(resp)
121123
logger.FromContext(ctx).Debug("GenerateAction",
122-
"output", fmt.Sprintf("%#v", resp),
124+
"output", respBytes,
123125
"err", err)
124126
}()
125127

go/core/action.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,15 @@ func (a *ActionDef[In, Out, Stream]) Run(ctx context.Context, input In, cb Strea
183183

184184
// Run executes the Action's function in a new trace span.
185185
func (a *ActionDef[In, Out, Stream]) runWithTelemetry(ctx context.Context, input In, cb StreamCallback[Stream]) (output api.ActionRunResult[Out], err error) {
186+
inputBytes, _ := json.Marshal(input)
186187
logger.FromContext(ctx).Debug("Action.Run",
187188
"name", a.Name(),
188-
"input", fmt.Sprintf("%#v", input))
189+
"input", inputBytes)
189190
defer func() {
191+
outputBytes, _ := json.Marshal(output)
190192
logger.FromContext(ctx).Debug("Action.Run",
191193
"name", a.Name(),
192-
"output", fmt.Sprintf("%#v", output),
194+
"output", outputBytes,
193195
"err", err)
194196
}()
195197

0 commit comments

Comments
 (0)