diff --git a/api_logs/api-logs.go b/api_logs/api-logs.go index 28ddac5fd376128d673fa9bcfd8a910d5d699f52..c1d525411a660862c38881a3ba39a42396d3bbe9 100644 --- a/api_logs/api-logs.go +++ b/api_logs/api-logs.go @@ -3,7 +3,6 @@ package api_logs import ( "github.com/thoas/go-funk" "gitlab.com/uafrica/go-utils/string_utils" - "net/http" "net/url" "strings" "time" @@ -19,13 +18,10 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st currentRequestID = *requestID } - // Truncate response body for incoming GET requests + // SQS has a 256KB limit, so let's limit the response to 96KB 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] + "..." - } + if len(responseBody) > 12000 { + responseBody = responseBody[:12000] + "..." } var authType string @@ -117,6 +113,12 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st currentRequestID = *requestID } + // SQS has a 256KB limit, so let's limit the response to 96KB + originalResponseBody := responseBody + if len(responseBody) > 12000 { + responseBody = responseBody[:12000] + "..." + } + userID, _ := claim["UserID"].(int64) username, _ := claim["Username"].(string) accountID, _ := claim["AccountID"].(int64) @@ -157,7 +159,7 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st }, Response: ApiLogResponse{ Headers: requestHeaders, - BodySize: len(responseBody), + BodySize: len(originalResponseBody), Body: responseBody, }, }