Safe Haskell | None |
---|---|
Language | Haskell2010 |
Non-intrusive distributed tracing
Let's assume for example we are interested in tracing the two following functions and publishing their traces to Zipkin:
listTaskIDs :: MonadIO m => m [Int] -- Returns a list of all task IDs. fetchTasks :: MonadIO m => [Int] -> m [Task] -- Resolves IDs into tasks.
We can do so simply by wrapping them inside a localSpan
call and adding a
MonadTrace
constraint:
listTaskIDs' :: (MonadIO m, MonadTrace m) => m [Int] listTaskIDs' = localSpan "list-task-ids" listTaskIDs fetchTasks' :: (MonadIO m, MonadTrace m) => [Int] -> m [Task] fetchTasks' = localSpan "fetch-tasks" . fetchTasks
Spans will now automatically get generated and published each time these actions are run! Each publication will include various useful pieces of metadata, including lineage. For example, if we wrap the two above functions in a root span, the spans will correctly be nested:
main :: IO () main = do zipkin <- new defaultSettings tasks <- run zipkin $ rootSpan "list-tasks" (listTaskIDs' >>= fetchTasks') publish zipkin print tasks
For clarity the above example imported all functions unqualified. In general, the recommended pattern when using this library is to import this module unqualified and the backend-specific module qualified. For example:
import Monitor.Tracing import qualified Monitor.Tracing.Zipkin as Zipkin
Synopsis
- class Monad m => MonadTrace m
- tracedForkIO :: (MonadTrace m, MonadUnliftIO m) => m () -> m ThreadId
- class Monad m => MonadIO (m :: Type -> Type)
- liftIO :: MonadIO m => IO a -> m a
- class MonadIO m => MonadUnliftIO (m :: Type -> Type)
- withRunInIO :: MonadUnliftIO m => ((forall a. m a -> IO a) -> IO b) -> m b
Overview
class Monad m => MonadTrace m Source #
A monad capable of generating traces.
There are currently two instances of this monad:
Instances
MonadTrace Identity Source # | |
MonadUnliftIO m => MonadTrace (TraceT m) Source # | |
(Monad m, MonadTrace m) => MonadTrace (ExceptT e m) Source # | |
(Monad m, MonadTrace m) => MonadTrace (StateT s m) Source # | |
(Monad m, MonadTrace m) => MonadTrace (StateT s m) Source # | |
(Monad m, MonadTrace m, Monoid w) => MonadTrace (WriterT w m) Source # | |
(Monad m, MonadTrace m, Monoid w) => MonadTrace (WriterT w m) Source # | |
(Monad m, MonadTrace m) => MonadTrace (ReaderT r m) Source # | |
(Monad m, MonadTrace m, Monoid w) => MonadTrace (RWST r w s m) Source # | |
(Monad m, MonadTrace m, Monoid w) => MonadTrace (RWST r w s m) Source # | |
tracedForkIO :: (MonadTrace m, MonadUnliftIO m) => m () -> m ThreadId Source #
Starts a new span inside a new thread, returning the newly created thread's ID.
This convenience method around forkIO
and withRunInIO
is provided since getting insights into
concurrent calls is one of the main benefits of tracing.
Convenience exports
class Monad m => MonadIO (m :: Type -> Type) #
Monads in which IO
computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO
monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Instances
class MonadIO m => MonadUnliftIO (m :: Type -> Type) #
Monads which allow their actions to be run in IO
.
While MonadIO
allows an IO
action to be lifted into another
monad, this class captures the opposite concept: allowing you to
capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic
state, but may have monadic context. This essentially limits
MonadUnliftIO
to ReaderT
and IdentityT
transformers on top of
IO
.
Laws. For any value u
returned by askUnliftIO
, it must meet the
monad transformer laws as reformulated for MonadUnliftIO
:
unliftIO u . return = return
unliftIO u (m >>= f) = unliftIO u m >>= unliftIO u . f
The third is a currently nameless law which ensures that the current context is preserved.
askUnliftIO >>= (u -> liftIO (unliftIO u m)) = m
If you have a name for this, please submit it in a pull request for great glory.
Since: unliftio-core-0.1.0.0
Instances
MonadUnliftIO IO | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (TraceT m) Source # | |
Defined in Control.Monad.Trace | |
MonadUnliftIO m => MonadUnliftIO (IdentityT m) | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (ReaderT r m) | |
Defined in Control.Monad.IO.Unlift |
withRunInIO :: MonadUnliftIO m => ((forall a. m a -> IO a) -> IO b) -> m b #
Convenience function for capturing the monadic context and running an IO
action with a runner function. The runner function is used to run a monadic
action m
in IO
.
Since: unliftio-core-0.1.0.0