server: respect X-B3-Sampled header when X-B3-TraceId is not present

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9009
GitOrigin-RevId: 7a4565bcada4f6249927ed0cbfbe42401a9a7968
This commit is contained in:
awjchen 2023-05-02 01:21:08 -06:00 committed by hasura-bot
parent ee006b45a2
commit 650137dc00

View File

@ -317,20 +317,26 @@ mkSpockAction appStateRef qErrEncoder qErrModifier apiHandler = do
Tracing.traceIdFromHex $ Char8.replicate 16 '0' <> rawTraceId
| otherwise ->
Nothing
for traceIdMaybe $ \traceId -> do
freshSpanId <- Tracing.randomSpanId
let parentSpanId = Tracing.spanIdFromHex =<< lookup "X-B3-SpanId" headers
samplingState = Tracing.samplingStateFromHeader $ lookup "X-B3-Sampled" headers
pure $ Tracing.TraceContext traceId freshSpanId parentSpanId samplingState
case traceIdMaybe of
Just traceId -> do
freshSpanId <- Tracing.randomSpanId
let parentSpanId = Tracing.spanIdFromHex =<< lookup "X-B3-SpanId" headers
samplingState = Tracing.samplingStateFromHeader $ lookup "X-B3-Sampled" headers
pure $ Tracing.TraceContext traceId freshSpanId parentSpanId samplingState
Nothing -> do
freshTraceId <- Tracing.randomTraceId
freshSpanId <- Tracing.randomSpanId
let samplingState = Tracing.samplingStateFromHeader $ lookup "X-B3-Sampled" headers
pure $ Tracing.TraceContext freshTraceId freshSpanId Nothing samplingState
let runTrace ::
forall m1 a1.
(MonadIO m1, MonadTrace m1) =>
(MonadTrace m1) =>
m1 a1 ->
m1 a1
runTrace = case tracingCtx of
Nothing -> Tracing.newTrace appEnvTraceSamplingPolicy (fromString (B8.unpack pathInfo))
Just ctx -> Tracing.newTraceWith ctx appEnvTraceSamplingPolicy (fromString (B8.unpack pathInfo))
runTrace =
Tracing.newTraceWith tracingCtx appEnvTraceSamplingPolicy (fromString (B8.unpack pathInfo))
let getInfo parsedRequest = do
authenticationResp <- lift (resolveUserInfo (_lsLogger appEnvLoggers) appEnvManager headers acAuthMode parsedRequest)