Add context to log statements.

This commit is contained in:
Maximilian Paß
2023-04-11 19:24:06 +01:00
parent 43221c717e
commit 0c8fa9ccfa
16 changed files with 97 additions and 88 deletions

View File

@ -130,12 +130,12 @@ func addEnvironmentID(r *http.Request, id dto.EnvironmentID) {
func AddRequestSize(r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
log.WithError(err).Warn("Failed to read request body")
log.WithContext(r.Context()).WithError(err).Warn("Failed to read request body")
}
err = r.Body.Close()
if err != nil {
log.WithError(err).Warn("Failed to close request body")
log.WithContext(r.Context()).WithError(err).Warn("Failed to close request body")
}
r.Body = io.NopCloser(bytes.NewBuffer(body))
@ -185,7 +185,7 @@ func addInfluxDBField(r *http.Request, key string, value interface{}) {
func dataPointFromRequest(r *http.Request) *write.Point {
p, ok := r.Context().Value(influxdbContextKey).(*write.Point)
if !ok {
log.Error("All http request must contain an influxdb data point!")
log.WithContext(r.Context()).Error("All http request must contain an influxdb data point!")
}
return p
}