mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
bb8f6a76cc
[PLAT-438](https://hasurahq.atlassian.net/browse/PLAT-438) After this change the top level trace is is annotated with `request_id` and `parameterized_query_hash`. It looks like this, in jeager: ![image](https://user-images.githubusercontent.com/210815/233206107-73682a85-3306-4d1d-8a6c-148890dc1a38.png) bulk queries should output a separate `parameterized_query_hash` for each query span ...after the last two commits, things look like this (remove pointless spans, more attributes): ![image](https://user-images.githubusercontent.com/210815/233476532-47521f35-2cdf-4f7d-af13-39c7ce15c9ec.png) [PLAT-438]: https://hasurahq.atlassian.net/browse/PLAT-438?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8824 GitOrigin-RevId: 0fd105c879161587d41b729b9bac968e92efae95
47 lines
1.6 KiB
Haskell
47 lines
1.6 KiB
Haskell
module Hasura.Tracing.Context
|
|
( TraceContext (..),
|
|
TraceMetadata,
|
|
)
|
|
where
|
|
|
|
import Data.Aeson ((.=))
|
|
import Data.Aeson qualified as J
|
|
import Hasura.Prelude
|
|
import Hasura.Tracing.Sampling
|
|
import Hasura.Tracing.TraceId
|
|
|
|
-- | Any additional human-readable key-value pairs relevant to the execution of
|
|
-- a span.
|
|
--
|
|
-- When the Open Telemetry exporter is in use these become attributes. Where
|
|
-- possible and appropriate, consider using key names from the documented OT
|
|
-- semantic conventions here:
|
|
-- https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/
|
|
-- This can serve to document the metadata, even for users not using open telemetry.
|
|
--
|
|
-- We may make this type more closely align with the OT data model in the future
|
|
-- (e.g. supporting int, etc)
|
|
type TraceMetadata = [(Text, Text)]
|
|
|
|
-- | A trace context records the current active trace, the active span
|
|
-- within that trace, and the span's parent, unless the current span
|
|
-- is the root. This is like a call stack.
|
|
data TraceContext = TraceContext
|
|
{ tcCurrentTrace :: TraceId,
|
|
tcCurrentSpan :: SpanId,
|
|
tcCurrentParent :: Maybe SpanId,
|
|
tcSamplingState :: SamplingState
|
|
}
|
|
|
|
-- Should this be here? This implicitly ties Tracing to the name of fields in HTTP headers.
|
|
instance J.ToJSON TraceContext where
|
|
toJSON TraceContext {..} =
|
|
let idFields =
|
|
[ "trace_id" .= bsToTxt (traceIdToHex tcCurrentTrace),
|
|
"span_id" .= bsToTxt (spanIdToHex tcCurrentSpan)
|
|
]
|
|
samplingFieldMaybe =
|
|
samplingStateToHeader @Text tcSamplingState <&> \t ->
|
|
"sampling_state" .= t
|
|
in J.object $ idFields ++ maybeToList samplingFieldMaybe
|