diff --git a/api_logs/api-logs.go b/api_logs/api-logs.go index ce1cc05825934fbfbb60ef352feb76ea43cac137..28ddac5fd376128d673fa9bcfd8a910d5d699f52 100644 --- a/api_logs/api-logs.go +++ b/api_logs/api-logs.go @@ -3,6 +3,7 @@ package api_logs import ( "github.com/thoas/go-funk" "gitlab.com/uafrica/go-utils/string_utils" + "net/http" "net/url" "strings" "time" @@ -18,6 +19,15 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st currentRequestID = *requestID } + // Truncate response body for incoming GET requests + responseBody := res.Body + if req.HTTPMethod == http.MethodGet { + // SQS has a 256KB limit, so let's limit the response to 96KB + if len(responseBody) > 12000 { + responseBody = responseBody[:12000] + "..." + } + } + var authType string var authUsername string if req.RequestContext.Identity.CognitoAuthenticationType != "" { @@ -87,7 +97,7 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st Response: ApiLogResponse{ Headers: res.Headers, BodySize: len(res.Body), - Body: res.Body, + Body: responseBody, }, }