From a29101a3e9fe8c624fb09ec892c21da4b2bdaaba Mon Sep 17 00:00:00 2001 From: Rakesh Emmadi <12475069+rakeshkky@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:07:07 +0530 Subject: [PATCH] server: Include `operationName` in http-log when `HASURA_GRAPHQL_HTTP_LOG_QUERY_ONLY_ON_ERROR` env var set to `true` PR-URL: https://github.com/hasura/graphql-engine-mono/pull/11031 GitOrigin-RevId: 73091f5826fde006a190bc295b36829906181c2f --- server/src-lib/Hasura/Server/Logging.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server/src-lib/Hasura/Server/Logging.hs b/server/src-lib/Hasura/Server/Logging.hs index a07d2d0cb0635..5c03d024b4502 100644 --- a/server/src-lib/Hasura/Server/Logging.hs +++ b/server/src-lib/Hasura/Server/Logging.hs @@ -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