chore: improve logging

This commit is contained in:
Oleh Astappiev 2024-12-08 21:19:14 +01:00
parent f3ec9005f7
commit c4c1a15b00
No known key found for this signature in database
GPG key ID: 37D7AC22589E9632
2 changed files with 8 additions and 3 deletions

View file

@ -50,7 +50,12 @@ func sendRequest(ctx context.Context, url string, body interface{}, headers http
defer func() { defer func() {
_ = resp.Body.Close() _ = resp.Body.Close()
}() }()
return nil, fmt.Errorf("request failed with status %d", status)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("request failed with status %d (failed to read body: %v)", status, err)
}
return nil, fmt.Errorf("request failed with status %d (%v)", status, string(respBody))
} }
return resp, nil return resp, nil

View file

@ -9,10 +9,10 @@ import (
type SendPayload struct { type SendPayload struct {
Website string `json:"website"` Website string `json:"website"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
Ip string `json:"ip"`
Language string `json:"language,omitempty"` Language string `json:"language,omitempty"`
Referrer string `json:"referrer,omitempty"` Referrer string `json:"referrer,omitempty"`
Url string `json:"url"` Url string `json:"url"`
//Ip string `json:"ip,omitempty"`
//Data map[string]interface{} `json:"data,omitempty"` // Additional data for the event //Data map[string]interface{} `json:"data,omitempty"` // Additional data for the event
//Name string `json:"name,omitempty"` // Event name (for custom events) //Name string `json:"name,omitempty"` // Event name (for custom events)
//Screen string `json:"screen,omitempty"` // Screen resolution (ex. "1920x1080") //Screen string `json:"screen,omitempty"` // Screen resolution (ex. "1920x1080")
@ -119,7 +119,7 @@ func (h *UmamiFeeder) reportEventToUmami(ctx context.Context, event *UmamiPayloa
} }
event.body.Payload.Website = websiteId event.body.Payload.Website = websiteId
h.debug("sending tracking request %s with body %v %v", event.body.Payload.Url, event.body, event.headers) h.debug("sending tracking request %v %v", event.body, event.headers)
resp, err := sendRequest(ctx, h.umamiHost+"/api/send", event.body, event.headers) resp, err := sendRequest(ctx, h.umamiHost+"/api/send", event.body, event.headers)
if err != nil { if err != nil {
h.error("failed to send tracking: " + err.Error()) h.error("failed to send tracking: " + err.Error())