feat(debug): логировать все API-вызовы к opencode serve с содержимым
В единой точке Client.do добавлены отладочные логи (всегда включены): - строка вызова: opencode api <op> -> <METHOD> <url><path> - тело запроса (усечено до 5000 байт) - тело ответа 2xx (усечено до 5000 байт) - тело ответа при ошибке/не-2xx (усечено до 1000 байт) Нужно для диагностики проблемы аналитика (serve отвечал на модель opencode/nemotron, ratatoskr не видел вердикт).
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -61,6 +62,11 @@ func (c *Client) do(ctx context.Context, method, path, op string, body []byte) (
|
|||||||
if body != nil {
|
if body != nil {
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
|
log.Printf("opencode api %s -> %s %s%s",
|
||||||
|
op, method, c.BaseURL, path)
|
||||||
|
if len(body) > 0 {
|
||||||
|
log.Printf("opencode api %s request body: %s", op, truncateStr(string(body), 5000))
|
||||||
|
}
|
||||||
resp, err := c.http.Do(req)
|
resp, err := c.http.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &ClientErr{Op: "connect", Err: err}
|
return nil, &ClientErr{Op: "connect", Err: err}
|
||||||
@@ -71,8 +77,10 @@ func (c *Client) do(ctx context.Context, method, path, op string, body []byte) (
|
|||||||
return nil, &ClientErr{Op: "connect", Err: err}
|
return nil, &ClientErr{Op: "connect", Err: err}
|
||||||
}
|
}
|
||||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||||
|
log.Printf("opencode api %s response: status %d: %s", op, resp.StatusCode, truncateStr(string(b), 1000))
|
||||||
return nil, &ClientErr{Op: op, Err: fmt.Errorf("status %d: %s", resp.StatusCode, truncateStr(string(b), 300))}
|
return nil, &ClientErr{Op: op, Err: fmt.Errorf("status %d: %s", resp.StatusCode, truncateStr(string(b), 300))}
|
||||||
}
|
}
|
||||||
|
log.Printf("opencode api %s response (%d bytes): %s", op, len(b), truncateStr(string(b), 5000))
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user