{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StrictData #-}
module OpenTracing
(
HasOpenTracing
, MonadOpenTracing
, runOpenTracing
, MonadTracer
, Tracer.Tracer(..)
, Tracer.HasTracer(..)
, Tracer.runTracer
, traced
, traced_
, startSpan
, finishSpan
, extract
, inject
, module OpenTracing.Log
, module OpenTracing.Propagation
, module OpenTracing.Sampling
, module OpenTracing.Span
, module OpenTracing.Tags
, module OpenTracing.Types
)
where
import Control.Exception.Safe
import Control.Lens
import Control.Monad.IO.Class
import Control.Monad.Reader
import OpenTracing.Log
import OpenTracing.Propagation hiding (inject, extract)
import qualified OpenTracing.Propagation as Propagation
import OpenTracing.Sampling
import OpenTracing.Span
import OpenTracing.Tags
import qualified OpenTracing.Tracer as Tracer
import OpenTracing.Types
import Prelude hiding (span)
type HasOpenTracing r p = (Tracer.HasTracer r, HasPropagation r p)
type MonadOpenTracing r p m = (HasOpenTracing r p, MonadReader r m)
type MonadTracer r m = (Tracer.HasTracer r, MonadReader r m)
type MonadPropagation r p m = (HasPropagation r p, MonadReader r m)
runOpenTracing :: HasOpenTracing r p => r -> ReaderT r m a -> m a
runOpenTracing :: forall r (p :: [*]) (m :: * -> *) a.
HasOpenTracing r p =>
r -> ReaderT r m a -> m a
runOpenTracing = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT
traced
:: ( MonadTracer r m
, MonadMask m
, MonadIO m
)
=> SpanOpts
-> (ActiveSpan -> m a)
-> m (Traced a)
traced :: forall r (m :: * -> *) a.
(MonadTracer r m, MonadMask m, MonadIO m) =>
SpanOpts -> (ActiveSpan -> m a) -> m (Traced a)
traced SpanOpts
opt ActiveSpan -> m a
f = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall a r. HasTracer a => Getting r a Tracer
Tracer.tracer forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Tracer
t -> forall t (m :: * -> *) a.
(HasTracer t, MonadMask m, MonadIO m) =>
t -> SpanOpts -> (ActiveSpan -> m a) -> m (Traced a)
Tracer.traced Tracer
t SpanOpts
opt ActiveSpan -> m a
f
traced_
:: ( MonadTracer r m
, MonadMask m
, MonadIO m
)
=> SpanOpts
-> (ActiveSpan -> m a)
-> m a
traced_ :: forall r (m :: * -> *) a.
(MonadTracer r m, MonadMask m, MonadIO m) =>
SpanOpts -> (ActiveSpan -> m a) -> m a
traced_ SpanOpts
opt ActiveSpan -> m a
f = forall a. Traced a -> a
tracedResult forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall r (m :: * -> *) a.
(MonadTracer r m, MonadMask m, MonadIO m) =>
SpanOpts -> (ActiveSpan -> m a) -> m (Traced a)
traced SpanOpts
opt ActiveSpan -> m a
f
startSpan
:: ( MonadTracer r m
, MonadIO m
)
=> SpanOpts
-> m ActiveSpan
startSpan :: forall r (m :: * -> *).
(MonadTracer r m, MonadIO m) =>
SpanOpts -> m ActiveSpan
startSpan SpanOpts
opt = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall a r. HasTracer a => Getting r a Tracer
Tracer.tracer forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a b c. (a -> b -> c) -> b -> a -> c
flip forall t (m :: * -> *).
(HasTracer t, MonadIO m) =>
t -> SpanOpts -> m ActiveSpan
Tracer.startSpan SpanOpts
opt
finishSpan
:: ( MonadTracer r m
, MonadIO m
)
=> ActiveSpan
-> m FinishedSpan
finishSpan :: forall r (m :: * -> *).
(MonadTracer r m, MonadIO m) =>
ActiveSpan -> m FinishedSpan
finishSpan ActiveSpan
a = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall a r. HasTracer a => Getting r a Tracer
Tracer.tracer forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a b c. (a -> b -> c) -> b -> a -> c
flip forall t (m :: * -> *).
(HasTracer t, MonadIO m) =>
t -> ActiveSpan -> m FinishedSpan
Tracer.finishSpan ActiveSpan
a
inject
:: forall c r p m.
( MonadPropagation r p m
, HasCarrier c p
)
=> SpanContext
-> m c
inject :: forall c r (p :: [*]) (m :: * -> *).
(MonadPropagation r p m, HasCarrier c p) =>
SpanContext -> m c
inject SpanContext
ctx = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall c r (p :: [*]).
(HasCarrier c p, HasPropagation r p) =>
r -> SpanContext -> c
Propagation.inject SpanContext
ctx forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall a (p :: [*]) r.
HasPropagation a p =>
Getting r a (Propagation p)
propagation
extract
:: forall c r p m.
( MonadPropagation r p m
, HasCarrier c p
)
=> c
-> m (Maybe SpanContext)
c
c = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall c r (p :: [*]).
(HasCarrier c p, HasPropagation r p) =>
r -> c -> Maybe SpanContext
Propagation.extract c
c forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall a (p :: [*]) r.
HasPropagation a p =>
Getting r a (Propagation p)
propagation