diff --git a/internal/telemetry/throttler.go b/internal/telemetry/throttler.go index 2409e2ab3..37e050e64 100644 --- a/internal/telemetry/throttler.go +++ b/internal/telemetry/throttler.go @@ -92,15 +92,18 @@ func (t *throttler) startWorkers() { return } res, err := t.sendTelemetryRecord(record) - if debugMode { - if err != nil { - getLogger().Printf("send telemetry record error: %v\n", err) + if err == nil && res != nil && res.Body != nil { + if debugMode { + bts, err := io.ReadAll(res.Body) + if err != nil { + getLogger().Printf("read response body error: %v\n", err) + } else { + getLogger().Printf("[Event %s.%s] %s\n", record.ResourceType, record.EventType, string(bts)) + } + } else { + _, _ = io.Copy(io.Discard, res.Body) } - bts, err := io.ReadAll(res.Body) - if err != nil { - getLogger().Printf("read response body error: %v\n", err) - } - getLogger().Printf("[Event %s.%s] %s\n", record.ResourceType, record.EventType, string(bts)) + _ = res.Body.Close() } case <-ctx.Done(): getLogger().Println(ctx.Err())