Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: show method and complete URI in traced HTTP calls #5525

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions server/src-lib/Hasura/Tracing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Control.Monad.Trans.Control
import Control.Monad.Morph
import Control.Monad.Unique
import Data.String (fromString)
import Network.URI (URI)

import qualified Data.Aeson as J
import qualified Data.Aeson.Lens as JL
Expand Down Expand Up @@ -237,22 +238,25 @@ extractEventContext e = do
-- | Perform HTTP request which supports Trace headers
tracedHttpRequest
:: MonadTrace m
=> HTTP.Request
=> HTTP.Request
-- ^ http request that needs to be made
-> (HTTP.Request -> m a)
-- ^ a function that takes the traced request and executes it
-> m a
tracedHttpRequest req f = trace (bsToTxt (HTTP.path req)) do
let reqBytes = case HTTP.requestBody req of
HTTP.RequestBodyBS bs -> Just (fromIntegral (BS.length bs))
HTTP.RequestBodyLBS bs -> Just (BL.length bs)
HTTP.RequestBodyBuilder len _ -> Just len
HTTP.RequestBodyStream len _ -> Just len
_ -> Nothing
for_ reqBytes \b ->
attachMetadata [("request_body_bytes", fromString (show b))]
ctx <- currentContext
let req' = req { HTTP.requestHeaders =
injectHttpContext ctx <> HTTP.requestHeaders req
}
f req'
tracedHttpRequest req f = do
let method = bsToTxt (HTTP.method req)
uri = show @URI (HTTP.getUri req)
Naveenaidu marked this conversation as resolved.
Show resolved Hide resolved
trace (method <> " " <> fromString uri) do
let reqBytes = case HTTP.requestBody req of
HTTP.RequestBodyBS bs -> Just (fromIntegral (BS.length bs))
HTTP.RequestBodyLBS bs -> Just (BL.length bs)
HTTP.RequestBodyBuilder len _ -> Just len
HTTP.RequestBodyStream len _ -> Just len
_ -> Nothing
for_ reqBytes \b ->
attachMetadata [("request_body_bytes", fromString (show b))]
ctx <- currentContext
let req' = req { HTTP.requestHeaders =
injectHttpContext ctx <> HTTP.requestHeaders req
}
f req'