From c4c1a15b00ff8d879801a57a52151de191ff16a1 Mon Sep 17 00:00:00 2001 From: Oleh Astappiev Date: Sun, 8 Dec 2024 21:19:14 +0100 Subject: [PATCH] chore: improve logging --- umami_utils.go | 7 ++++++- umami_worker.go | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/umami_utils.go b/umami_utils.go index 8a3fb04..848bca5 100644 --- a/umami_utils.go +++ b/umami_utils.go @@ -50,7 +50,12 @@ func sendRequest(ctx context.Context, url string, body interface{}, headers http defer func() { _ = 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 diff --git a/umami_worker.go b/umami_worker.go index 757efe8..7360264 100644 --- a/umami_worker.go +++ b/umami_worker.go @@ -9,10 +9,10 @@ import ( type SendPayload struct { Website string `json:"website"` Hostname string `json:"hostname"` - Ip string `json:"ip"` Language string `json:"language,omitempty"` Referrer string `json:"referrer,omitempty"` Url string `json:"url"` + //Ip string `json:"ip,omitempty"` //Data map[string]interface{} `json:"data,omitempty"` // Additional data for the event //Name string `json:"name,omitempty"` // Event name (for custom events) //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 - 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) if err != nil { h.error("failed to send tracking: " + err.Error())