{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module OpenTelemetry.Trace.Monad (
inSpan,
inSpan',
OpenTelemetry.Trace.Monad.inSpan'',
MonadTracer (..),
) where
import Control.Monad.IO.Unlift
import Control.Monad.Identity (IdentityT)
import Control.Monad.Reader (ReaderT)
import Control.Monad.Trans (MonadTrans (lift))
import Data.Text (Text)
import GHC.Stack
import OpenTelemetry.Trace.Core (
Span,
SpanArguments (..),
Tracer,
addAttributesToSpanArguments,
callerAttributes,
inSpan'',
)
class (Monad m) => MonadTracer m where
getTracer :: m Tracer
inSpan
:: (MonadUnliftIO m, MonadTracer m, HasCallStack)
=> Text
-> SpanArguments
-> m a
-> m a
inSpan :: forall (m :: * -> *) a.
(MonadUnliftIO m, MonadTracer m, HasCallStack) =>
Text -> SpanArguments -> m a -> m a
inSpan Text
n SpanArguments
args m a
m = Text -> SpanArguments -> (Span -> m a) -> m a
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadTracer m, HasCallStack) =>
Text -> SpanArguments -> (Span -> m a) -> m a
OpenTelemetry.Trace.Monad.inSpan'' Text
n (HashMap Text Attribute -> SpanArguments -> SpanArguments
addAttributesToSpanArguments HashMap Text Attribute
HasCallStack => HashMap Text Attribute
callerAttributes SpanArguments
args) (m a -> Span -> m a
forall a b. a -> b -> a
const m a
m)
inSpan'
:: (MonadUnliftIO m, MonadTracer m, HasCallStack)
=> Text
-> SpanArguments
-> (Span -> m a)
-> m a
inSpan' :: forall (m :: * -> *) a.
(MonadUnliftIO m, MonadTracer m, HasCallStack) =>
Text -> SpanArguments -> (Span -> m a) -> m a
inSpan' Text
n SpanArguments
args Span -> m a
f = Text -> SpanArguments -> (Span -> m a) -> m a
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadTracer m, HasCallStack) =>
Text -> SpanArguments -> (Span -> m a) -> m a
OpenTelemetry.Trace.Monad.inSpan'' Text
n (HashMap Text Attribute -> SpanArguments -> SpanArguments
addAttributesToSpanArguments HashMap Text Attribute
HasCallStack => HashMap Text Attribute
callerAttributes SpanArguments
args) Span -> m a
f
inSpan''
:: (MonadUnliftIO m, MonadTracer m, HasCallStack)
=> Text
-> SpanArguments
-> (Span -> m a)
-> m a
inSpan'' :: forall (m :: * -> *) a.
(MonadUnliftIO m, MonadTracer m, HasCallStack) =>
Text -> SpanArguments -> (Span -> m a) -> m a
inSpan'' Text
n SpanArguments
args Span -> m a
f = do
Tracer
t <- m Tracer
forall (m :: * -> *). MonadTracer m => m Tracer
getTracer
Tracer -> Text -> SpanArguments -> (Span -> m a) -> m a
forall (m :: * -> *) a.
(MonadUnliftIO m, HasCallStack) =>
Tracer -> Text -> SpanArguments -> (Span -> m a) -> m a
OpenTelemetry.Trace.Core.inSpan'' Tracer
t Text
n SpanArguments
args Span -> m a
f
instance (MonadTracer m) => MonadTracer (IdentityT m) where
getTracer :: IdentityT m Tracer
getTracer = m Tracer -> IdentityT m Tracer
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Tracer
forall (m :: * -> *). MonadTracer m => m Tracer
getTracer
instance {-# OVERLAPPABLE #-} (MonadTracer m) => MonadTracer (ReaderT r m) where
getTracer :: ReaderT r m Tracer
getTracer = m Tracer -> ReaderT r m Tracer
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Tracer
forall (m :: * -> *). MonadTracer m => m Tracer
getTracer