Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type TracingMetadata = [(Text, Text)]
- newtype Reporter = Reporter {
- runReporter :: forall io a. MonadIO io => TraceContext -> Text -> io (a, TracingMetadata) -> io a
- noReporter :: Reporter
- class Monad m => HasReporter m where
- askReporter :: m Reporter
- data TraceContext = TraceContext {
- tcCurrentTrace :: !Word64
- tcCurrentSpan :: !Word64
- tcCurrentParent :: !(Maybe Word64)
- newtype TraceT m a = TraceT {
- unTraceT :: ReaderT (TraceContext, Reporter) (WriterT TracingMetadata m) a
- runTraceT :: (HasReporter m, MonadIO m) => Text -> TraceT m a -> m a
- runTraceTWith :: MonadIO m => TraceContext -> Reporter -> Text -> TraceT m a -> m a
- runTraceTInContext :: (MonadIO m, HasReporter m) => TraceContext -> Text -> TraceT m a -> m a
- runTraceTWithReporter :: MonadIO m => Reporter -> Text -> TraceT m a -> m a
- class Monad m => MonadTrace m where
- trace :: Text -> m a -> m a
- currentContext :: m TraceContext
- currentReporter :: m Reporter
- attachMetadata :: TracingMetadata -> m ()
- interpTraceT :: MonadTrace n => (m (a, TracingMetadata) -> n (b, TracingMetadata)) -> TraceT m a -> n b
- word64ToHex :: Word64 -> Text
- hexToWord64 :: Text -> Maybe Word64
- injectHttpContext :: TraceContext -> [Header]
- extractHttpContext :: [Header] -> IO (Maybe TraceContext)
- injectEventContext :: TraceContext -> Value
- extractEventContext :: Value -> IO (Maybe TraceContext)
- tracedHttpRequest :: MonadTrace m => Request -> (Request -> m a) -> m a
Documentation
type TracingMetadata = [(Text, Text)] Source #
Any additional human-readable key-value pairs relevant to the execution of a block of code.
Reporter | |
|
class Monad m => HasReporter m where Source #
A type class for monads which support some way to report execution traces.
See instance Tracing.HasReporter (AppM impl)
in HasuraPro.App
.
Nothing
Instances
HasReporter m => HasReporter (MetadataStorageT m) Source # | |
Defined in Hasura.Metadata.Class | |
Monad m => HasReporter (PGMetadataStorageAppT m) Source # | |
Defined in Hasura.App | |
HasReporter m => HasReporter (ExceptT e m) Source # | |
Defined in Hasura.Tracing askReporter :: ExceptT e m Reporter Source # | |
HasReporter m => HasReporter (ReaderT r m) Source # | |
Defined in Hasura.Tracing askReporter :: ReaderT r m Reporter Source # |
data TraceContext Source #
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.
TraceContext | |
|
The TraceT
monad transformer adds the ability to keep track of
the current trace context.
TraceT | |
|
Instances
runTraceTWith :: MonadIO m => TraceContext -> Reporter -> Text -> TraceT m a -> m a Source #
runTraceTInContext :: (MonadIO m, HasReporter m) => TraceContext -> Text -> TraceT m a -> m a Source #
Run an action in the TraceT
monad transformer in an
existing context.
runTraceTWithReporter :: MonadIO m => Reporter -> Text -> TraceT m a -> m a Source #
Run an action in the TraceT
monad transformer in an
existing context.
class Monad m => MonadTrace m where Source #
Monads which support tracing. TraceT
is the standard example.
trace :: Text -> m a -> m a Source #
Trace the execution of a block of code, attaching a human-readable name.
currentContext :: m TraceContext Source #
Ask for the current tracing context, so that we can provide it to any downstream services, e.g. in HTTP headers.
currentReporter :: m Reporter Source #
Ask for the current tracing reporter
attachMetadata :: TracingMetadata -> m () Source #
Log some metadata to be attached to the current span
Instances
interpTraceT :: MonadTrace n => (m (a, TracingMetadata) -> n (b, TracingMetadata)) -> TraceT m a -> n b Source #
Reinterpret a TraceT
action in another MonadTrace
.
This can be useful when you need to reorganize a monad transformer stack, for
example, to embed an action in some monadic computation, while preserving tracing
metadata and context.
For example, we use this function in various places in BackendExecute
,
where we receive an action to execute in some concrete monad transformer stack.
See the various implementations of runQuery
for examples.
Ideally, the input computation's type would be sufficiently polymorphic that
we would not need to reorder monads inthe transformer stack. However, the monad
transformer stacks must be concrete, because their types are defined by
an associated type family ExecutionMonad
. Hence, we need to use this function
to peel off the outermost TraceT
constructor, and embed the computation in some
other MonadTrace
.
A second example is related to caching. The cacheLookup
function returns an
action in a concrete transformer stack, again because we are constrained by the
usage of a type class. We need to reinterpret the TraceT
component of this
concrete stack in some other abstract monad transformer stack, using this function.
Laws:
interpTraceT id (hoist f (TraceT x)) = interpTraceT f (TraceT x)
word64ToHex :: Word64 -> Text Source #
Encode Word64 to 16 character hex string
hexToWord64 :: Text -> Maybe Word64 Source #
Decode 16 character hex string to Word64
injectHttpContext :: TraceContext -> [Header] Source #
Inject the trace context as a set of HTTP headers.
extractHttpContext :: [Header] -> IO (Maybe TraceContext) Source #
Extract the trace and parent span headers from a HTTP request
and create a new TraceContext
. The new context will contain
a fresh span ID, and the provided span ID will be assigned as
the immediate parent span.
injectEventContext :: TraceContext -> Value Source #
Inject the trace context as a JSON value, appropriate for storing in (e.g.) an event trigger payload.
extractEventContext :: Value -> IO (Maybe TraceContext) Source #
Extract a trace context from an event trigger payload.
:: MonadTrace m | |
=> Request | http request that needs to be made |
-> (Request -> m a) | a function that takes the traced request and executes it |
-> m a |
Perform HTTP request which supports Trace headers using a HTTP.Request value
TODO REFACTOR:
- inline performRequest
so that we can be sure a trace is always logged
- Inline try
here since we always use that at call sites