server: Log action and event names (close #1603)

- add name fields to log output in several spots:
  - action logs get the action name in detail.action_name
  - events (triggered and scheduled) get the trigger name in detail.event_name
  - one-off scheduled events don't have a trigger name; instead, they get the
    comment if it exists
- remove unused event creation timestamp from ExtraLogContext

https://github.com/hasura/graphql-engine-mono/pull/1712

GitOrigin-RevId: 28907340d4e2d9adc0c48cc5d3010eef1fa902e1
This commit is contained in:
Robert 2021-07-05 09:47:45 +02:00 committed by hasura-bot
parent a7a4791b96
commit 5cc91aebc3
6 changed files with 15 additions and 10 deletions

View File

@ -6,6 +6,7 @@
- server: add `query` field to `http-log` and `websocket-log` in non-error cases
- server: Add global limit to BigQuery via the `global_select_limit`
field in the connection configuration
- server: include action and event names in log output
## v2.0.1

View File

@ -409,7 +409,7 @@ processEventQueue logger logBehavior httpMgr getSchemaCache EventEngineCtx{..} L
(headers, logHeaders) = prepareHeaders logBehavior (etiHeaders eti)
ep = createEventPayload retryConf e
payload = encode $ toJSON ep
extraLogCtx = ExtraLogContext Nothing (epId ep) -- avoiding getting current time here to avoid another IO call with each event call
extraLogCtx = ExtraLogContext (epId ep) (Just $ etiName eti)
requestDetails = RequestDetails $ LBS.length payload
-- Track the number of active HTTP workers using EKG.

View File

@ -49,7 +49,6 @@ import qualified Data.TByteString as TBS
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Text.Encoding.Error as TE
import qualified Data.Time.Clock as Time
import qualified Network.HTTP.Client as HTTP
import qualified Network.HTTP.Types as HTTP
@ -150,8 +149,8 @@ data Invocation (a :: TriggerTypes)
data ExtraLogContext
= ExtraLogContext
{ elEventCreatedAt :: Maybe Time.UTCTime
, elEventId :: EventId
{ elEventId :: !EventId
, elEventName :: !(Maybe TriggerName)
} deriving (Show, Eq)
data HTTPResp (a :: TriggerTypes)
@ -229,19 +228,22 @@ data HTTPRespExtra (a :: TriggerTypes)
instance ToJSON (HTTPRespExtra a) where
toJSON (HTTPRespExtra resp ctxt req logResp) =
case resp of
Left errResp -> object
Left errResp -> object $
[ "response" .= toJSON errResp
, "request" .= toJSON req
, "event_id" .= elEventId ctxt
]
Right okResp -> object
] ++ eventName
Right okResp -> object $
[ "response" .= case logResp of
LogEntireResponse -> toJSON okResp
LogSanitisedResponse -> sanitisedRespJSON okResp
, "request" .= toJSON req
, "event_id" .= elEventId ctxt
]
] ++ eventName
where
eventName = case elEventName ctxt of
Just name -> [ "event_name" .= name ]
Nothing -> []
sanitisedRespJSON v
= Object $ HML.fromList
[ "size" .= hrsSize v

View File

@ -347,7 +347,7 @@ processScheduledEvent logBehavior eventId eventHeaders retryCtx payload webhookU
$ strcTimeoutSeconds retryConf
httpTimeout = HTTP.responseTimeoutMicro (timeoutSeconds * 1000000)
(headers, decodedHeaders) = prepareHeaders logBehavior eventHeaders
extraLogCtx = ExtraLogContext (Just currentTime) eventId
extraLogCtx = ExtraLogContext eventId (sewpName payload)
webhookReqBodyJson = J.toJSON payload
webhookReqBody = J.encode webhookReqBodyJson
requestDetails = RequestDetails $ BL.length webhookReqBody

View File

@ -410,6 +410,7 @@ callWebhook env manager outputType outputFields reqHeaders confHeaders
Right responseWreq -> do
let responseBody = responseWreq ^. Wreq.responseBody
responseBodySize = BL.length responseBody
actionName = _acName $ _awpAction actionWebhookPayload
responseStatus = responseWreq ^. Wreq.responseStatus
mkResponseInfo respBody =
ActionResponseInfo (HTTP.statusCode responseStatus) respBody $
@ -417,7 +418,7 @@ callWebhook env manager outputType outputFields reqHeaders confHeaders
-- log the request and response to/from the action handler
logger :: (L.Logger L.Hasura) <- asks getter
L.unLogger logger $ ActionHandlerLog requestBodySize responseBodySize
L.unLogger logger $ ActionHandlerLog requestBodySize responseBodySize actionName
case J.eitherDecode responseBody of
Left e -> do

View File

@ -122,6 +122,7 @@ data ActionHandlerLog
= ActionHandlerLog
{ _ahlRequestSize :: !Int64
, _ahlResponseSize :: !Int64
, _ahlActionName :: !ActionName
} deriving (Show)
$(J.deriveJSON (J.aesonDrop 4 J.snakeCase){J.omitNothingFields=True} ''ActionHandlerLog)