diff --git a/api_logs/api-logs.go b/api_logs/api-logs.go index c1d525411a660862c38881a3ba39a42396d3bbe9..457e05b5f5048c591da92b23e73728d5474a2176 100644 --- a/api_logs/api-logs.go +++ b/api_logs/api-logs.go @@ -18,25 +18,19 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st currentRequestID = *requestID } - // SQS has a 256KB limit, so let's limit the response to 96KB - responseBody := res.Body - if len(responseBody) > 12000 { - responseBody = responseBody[:12000] + "..." - } - var authType string var authUsername string if req.RequestContext.Identity.CognitoAuthenticationType != "" { authType = "cognito" split := strings.Split(req.RequestContext.Identity.CognitoAuthenticationProvider, ":") if len(split) > 0 { - authUsername = split[len(split)-1] //= part after last ':' + authUsername = split[len(split)-1] // = part after last ':' } } else { authType = "iam" split := strings.Split(req.RequestContext.Identity.UserArn, ":user/") if len(split) > 0 { - authUsername = split[len(split)-1] //= part after ':user/' + authUsername = split[len(split)-1] // = part after ':user/' } } @@ -93,11 +87,11 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st Response: ApiLogResponse{ Headers: res.Headers, BodySize: len(res.Body), - Body: responseBody, + Body: res.Body, }, } - //also copy multi-value query parameters to the log as CSV array values + // also copy multi-value query parameters to the log as CSV array values for n, as := range req.MultiValueQueryStringParameters { apiLog.Request.QueryParameters[n] = "[" + strings.Join(as, ",") + "]" } @@ -113,12 +107,6 @@ 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) @@ -159,7 +147,7 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st }, Response: ApiLogResponse{ Headers: requestHeaders, - BodySize: len(originalResponseBody), + BodySize: len(responseBody), Body: responseBody, }, } @@ -167,14 +155,14 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st return apiLog } -//ApiLog is the SQS event details struct encoded as JSON document, sent to SQS, to be logged for each API handler executed. +// ApiLog is the SQS event details struct encoded as JSON document, sent to SQS, to be logged for each API handler executed. type ApiLog struct { StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` - DurMs int64 `json:"duration_ms"` //duration in milliseconds - Type string `json:"type"` //incoming-api or outgoing-api + DurMs int64 `json:"duration_ms"` // duration in milliseconds + Type string `json:"type"` // incoming-api or outgoing-api Method string `json:"method"` - Address string `json:"address"` //server address for incoming and outgoing + Address string `json:"address"` // server address for incoming and outgoing Path string `json:"path"` ResponseCode int `json:"response_code"` RequestID string `json:"request_id"` @@ -184,8 +172,8 @@ type ApiLog struct { ProviderID int64 `json:"provider_id,omitempty"` UserID int64 `json:"user_id,omitempty"` Username string `json:"username,omitempty"` - SourceIP string `json:"source_ip,omitempty"` //only logged for incoming API - UserAgent string `json:"user_agent,omitempty"` //only for incoming, indicate type of browser when UI + SourceIP string `json:"source_ip,omitempty"` // only logged for incoming API + UserAgent string `json:"user_agent,omitempty"` // only for incoming, indicate type of browser when UI Request ApiLogRequest `json:"request"` Response ApiLogResponse `json:"response"` } @@ -193,12 +181,12 @@ type ApiLog struct { type ApiLogRequest struct { Headers map[string]string `json:"headers,omitempty"` QueryParameters map[string]string `json:"query_parameters,omitempty"` - BodySize int `json:"body_size" search:"long"` //set even when body is truncated/omitted - Body string `json:"body,omitempty"` //json body as a string + BodySize int `json:"body_size" search:"long"` // set even when body is truncated/omitted + Body string `json:"body,omitempty"` // json body as a string } type ApiLogResponse struct { Headers map[string]string `json:"headers,omitempty"` - BodySize int `json:"body_size"` //set even when body is truncated/omitted - Body string `json:"body,omitempty"` //json content as a string + BodySize int `json:"body_size"` // set even when body is truncated/omitted + Body string `json:"body,omitempty"` // json content as a string }