{-# 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 :: r -> ReaderT r m a -> m a
runOpenTracing = (ReaderT r m a -> r -> m a) -> r -> ReaderT r m a -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT r m a -> r -> m a
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 :: SpanOpts -> (ActiveSpan -> m a) -> m (Traced a)
traced SpanOpts
opt ActiveSpan -> m a
f = Getting Tracer r Tracer -> m Tracer
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Tracer r Tracer
forall a r. HasTracer a => Getting r a Tracer
Tracer.tracer m Tracer -> (Tracer -> m (Traced a)) -> m (Traced a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Tracer
t -> Tracer -> SpanOpts -> (ActiveSpan -> m a) -> m (Traced a)
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_ :: SpanOpts -> (ActiveSpan -> m a) -> m a
traced_ SpanOpts
opt ActiveSpan -> m a
f = Traced a -> a
forall a. Traced a -> a
tracedResult (Traced a -> a) -> m (Traced a) -> m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SpanOpts -> (ActiveSpan -> m a) -> m (Traced a)
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 :: SpanOpts -> m ActiveSpan
startSpan SpanOpts
opt = Getting Tracer r Tracer -> m Tracer
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Tracer r Tracer
forall a r. HasTracer a => Getting r a Tracer
Tracer.tracer m Tracer -> (Tracer -> m ActiveSpan) -> m ActiveSpan
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Tracer -> SpanOpts -> m ActiveSpan)
-> SpanOpts -> Tracer -> m ActiveSpan
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tracer -> SpanOpts -> m ActiveSpan
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 :: ActiveSpan -> m FinishedSpan
finishSpan ActiveSpan
a = Getting Tracer r Tracer -> m Tracer
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Tracer r Tracer
forall a r. HasTracer a => Getting r a Tracer
Tracer.tracer m Tracer -> (Tracer -> m FinishedSpan) -> m FinishedSpan
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Tracer -> ActiveSpan -> m FinishedSpan)
-> ActiveSpan -> Tracer -> m FinishedSpan
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tracer -> ActiveSpan -> m FinishedSpan
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 :: SpanContext -> m c
inject SpanContext
ctx = (Propagation p -> SpanContext -> c)
-> SpanContext -> Propagation p -> c
forall a b c. (a -> b -> c) -> b -> a -> c
flip Propagation p -> SpanContext -> c
forall c r (p :: [*]).
(HasCarrier c p, HasPropagation r p) =>
r -> SpanContext -> c
Propagation.inject SpanContext
ctx (Propagation p -> c) -> m (Propagation p) -> m c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Getting (Propagation p) r (Propagation p) -> m (Propagation p)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Propagation p) r (Propagation p)
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 = (Propagation p -> c -> Maybe SpanContext)
-> c -> Propagation p -> Maybe SpanContext
forall a b c. (a -> b -> c) -> b -> a -> c
flip Propagation p -> c -> Maybe SpanContext
forall c r (p :: [*]).
(HasCarrier c p, HasPropagation r p) =>
r -> c -> Maybe SpanContext
Propagation.extract c
c (Propagation p -> Maybe SpanContext)
-> m (Propagation p) -> m (Maybe SpanContext)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Getting (Propagation p) r (Propagation p) -> m (Propagation p)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Propagation p) r (Propagation p)
forall a (p :: [*]) r.
HasPropagation a p =>
Getting r a (Propagation p)
propagation