DE-3247 | updated logging for failing requests
This commit is contained in:
@@ -68,6 +68,7 @@ func (wp *WorkerPool) processRequest(request RequestObject) {
|
||||
if err := json.Unmarshal(messageBytes, &result); err != nil {
|
||||
wp.logger.Error("Failed to unmarshal JSON",
|
||||
zap.Error(err),
|
||||
zap.String("client_addr", utils.GetClientIP(request.Header.Get("X-Forwarded-For"), "")),
|
||||
zap.String("messageBytes", string(messageBytes)),
|
||||
zap.Int("bytesLength", len(messageBytes)))
|
||||
return
|
||||
|
||||
@@ -72,7 +72,7 @@ func eventsHandlerJson(workerPool *lib.WorkerPool) http.HandlerFunc {
|
||||
if err != nil {
|
||||
logger.Error("Error reading request body",
|
||||
zap.Error(err),
|
||||
zap.String("remote_addr", r.RemoteAddr),
|
||||
zap.String("client_addr", utils.GetClientIP(r.Header.Get("X-Forwarded-For"), r.RemoteAddr)),
|
||||
zap.String("user_agent", r.UserAgent()),
|
||||
zap.Int64("content_length", r.ContentLength),
|
||||
)
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
package utils
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NanosToMillis(timestamp int64) int64 {
|
||||
return timestamp * (int64(time.Nanosecond) / int64(time.Millisecond))
|
||||
}
|
||||
|
||||
func GetClientIP(xForwardedFor string, remoteAddr string) string {
|
||||
if xForwardedFor != "" {
|
||||
ips := strings.Split(xForwardedFor, ",")
|
||||
return strings.TrimSpace(ips[0])
|
||||
}
|
||||
|
||||
ip, _, err := net.SplitHostPort(remoteAddr)
|
||||
if err != nil {
|
||||
return remoteAddr
|
||||
}
|
||||
return ip
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user