feat(logging): enhance logging for metadata extraction and MCP tool handling
This commit is contained in:
@@ -208,6 +208,33 @@ func (c *Client) ExtractMetadata(ctx context.Context, input string) (thoughttype
|
||||
return thoughttypes.ThoughtMetadata{}, fmt.Errorf("%s extract metadata: input must not be empty", c.name)
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
if c.log != nil {
|
||||
c.log.Info("metadata client started",
|
||||
slog.String("provider", c.name),
|
||||
slog.String("model", c.metadataModel),
|
||||
)
|
||||
}
|
||||
|
||||
logCompletion := func(model string, err error) {
|
||||
if c.log == nil {
|
||||
return
|
||||
}
|
||||
|
||||
attrs := []any{
|
||||
slog.String("provider", c.name),
|
||||
slog.String("model", model),
|
||||
slog.Duration("duration", time.Since(start)),
|
||||
}
|
||||
if err != nil {
|
||||
attrs = append(attrs, slog.String("error", err.Error()))
|
||||
c.log.Error("metadata client completed", attrs...)
|
||||
return
|
||||
}
|
||||
|
||||
c.log.Info("metadata client completed", attrs...)
|
||||
}
|
||||
|
||||
result, err := c.extractMetadataWithModel(ctx, input, c.metadataModel)
|
||||
if errors.Is(err, errMetadataEmptyResponse) {
|
||||
c.noteEmptyResponse(c.metadataModel)
|
||||
@@ -217,6 +244,7 @@ func (c *Client) ExtractMetadata(ctx context.Context, input string) (thoughttype
|
||||
}
|
||||
if err == nil {
|
||||
c.noteModelSuccess(c.metadataModel)
|
||||
logCompletion(c.metadataModel, nil)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -247,13 +275,16 @@ func (c *Client) ExtractMetadata(ctx context.Context, input string) (thoughttype
|
||||
}
|
||||
if fallbackErr == nil {
|
||||
c.noteModelSuccess(fallbackModel)
|
||||
logCompletion(fallbackModel, nil)
|
||||
return fallbackResult, nil
|
||||
}
|
||||
err = fallbackErr
|
||||
}
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return thoughttypes.ThoughtMetadata{}, fmt.Errorf("%s metadata: %w", c.name, ctx.Err())
|
||||
err = fmt.Errorf("%s metadata: %w", c.name, ctx.Err())
|
||||
logCompletion(c.metadataModel, err)
|
||||
return thoughttypes.ThoughtMetadata{}, err
|
||||
}
|
||||
|
||||
heuristic := heuristicMetadataFromInput(input)
|
||||
@@ -263,6 +294,7 @@ func (c *Client) ExtractMetadata(ctx context.Context, input string) (thoughttype
|
||||
slog.String("error", err.Error()),
|
||||
)
|
||||
}
|
||||
logCompletion(c.metadataModel, nil)
|
||||
return heuristic, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user