Skip to content

Commit

Permalink
server: Include operationName in http-log when `HASURA_GRAPHQL_HTTP…
Browse files Browse the repository at this point in the history
…_LOG_QUERY_ONLY_ON_ERROR` env var set to `true`

PR-URL: hasura/graphql-engine-mono#11031
GitOrigin-RevId: 73091f5826fde006a190bc295b36829906181c2f
  • Loading branch information
rakeshkky authored and hasura-bot committed Sep 18, 2024
1 parent f4aafb2 commit a29101a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions server/src-lib/Hasura/Server/Logging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,17 @@ isQueryIncludedInLogs requestStatus urlPath LoggingSettings {..}
metadataUrlPaths = ["/v1/metadata", "/v1/query"]
isMetadataRequest = urlPath `elem` metadataUrlPaths

-- | Add the 'query' field to the http-log if `MetadataQueryLoggingMode`
-- is set to `MetadataQueryLoggingEnabled` else only adds the `query.type` field.
-- | Add the 'query' field to the http-log
addQuery :: RequestStatus -> Maybe J.Value -> Text -> LoggingSettings -> Maybe J.Value
addQuery requestStatus parsedReq path loggingSettings =
if isQueryIncludedInLogs requestStatus path loggingSettings
then parsedReq
else Just $ J.object ["type" J..= (fmap (^? key "type" . _String)) parsedReq]
addQuery requestStatus parsedReq path loggingSettings
-- Attach parsed request payload to 'query' field as is.
| isQueryIncludedInLogs requestStatus path loggingSettings = parsedReq
-- If the query cannot be included, attach only the 'operationName' when the
-- 'HASURA_GRAPHQL_HTTP_LOG_QUERY_ONLY_ON_ERROR' option is enabled.
| _lsHttpLogQueryOnlyOnError loggingSettings == HttpLogQueryOnlyOnErrorEnabled =
Just $ J.object ["operationName" J..= (fmap (^? key "operationName" . _String)) parsedReq]
-- Otherwise, include only the 'type' field for metadata requests. For other requests, 'type' will be null.
| otherwise = Just $ J.object ["type" J..= (fmap (^? key "type" . _String)) parsedReq]

mkHttpAccessLogContext ::
-- | Maybe because it may not have been resolved
Expand Down

0 comments on commit a29101a

Please sign in to comment.