feature (sdk): update sdk to support traces

This commit is contained in:
MickaelK
2026-04-24 03:32:05 +10:00
parent 112c1e5a15
commit 38d212202a
4 changed files with 22 additions and 6 deletions
+3
View File
@@ -16,6 +16,9 @@ func ApiHeaders(fn HandlerFunc) HandlerFunc {
header := res.Header()
header.Set("Content-Type", "application/json")
header.Set("Cache-Control", "no-cache")
if id := req.Header.Get("X-Request-ID"); id != "" {
header.Set("X-Request-ID", id)
}
fn(ctx, res, req)
})
}
+5 -1
View File
@@ -83,7 +83,11 @@ func logger(ctx *App, res http.ResponseWriter, req *http.Request) {
telemetry.Record(point)
}
if Config.Get("log.enable").Bool() {
Log.Stdout("HTTP %3d %3s %6.1fms %s", point.Status, point.Method, point.Duration, limit(point.RequestURI, 200))
tid := ""
if point.RequestID != "" && Config.Get("log.level").String() == "DEBUG" {
tid = "trace=" + point.RequestID
}
Log.Stdout("HTTP %3d %3s %6.1fms %s %s", point.Status, point.Method, point.Duration, limit(point.RequestURI, 200), tid)
}
}
}
+11 -5
View File
@@ -8,11 +8,17 @@ import (
)
type Filestash struct {
Token string
URL string
Insecure bool
Storage string
Client *http.Client
Token string
URL string
Insecure bool
Storage string
Client *http.Client
RequestID string
}
func (this Filestash) WithRequestID(id string) Filestash {
this.RequestID = id
return this
}
func NewClient() Filestash {
+3
View File
@@ -18,6 +18,9 @@ func (this Filestash) request(method string, url string, body io.Reader) (io.Rea
req.Host = Config.Get("general.host").String()
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", this.Token))
req.Header.Set("X-Requested-With", "XmlHttpRequest")
if this.RequestID != "" {
req.Header.Set("X-Request-ID", this.RequestID)
}
resp, err := this.Client.Do(req)
if err != nil {