mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-10-19 16:14:39 +00:00
feature (sdk): update sdk to support traces
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user