{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StrictData #-}
module OpenTelemetry.Internal.Trace.Types where
import Control.Exception (SomeException)
import Control.Monad.IO.Class
import Data.Bits
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as H
import Data.IORef (IORef)
import Data.Text (Text)
import Data.Vector (Vector)
import Data.Word (Word64, Word8)
import OpenTelemetry.Attributes
import OpenTelemetry.Common
import OpenTelemetry.Context.Types
import OpenTelemetry.Internal.Common.Types
import OpenTelemetry.Propagator (TextMapPropagator)
import OpenTelemetry.Resource
import OpenTelemetry.Trace.Id
import OpenTelemetry.Trace.Id.Generator
import OpenTelemetry.Trace.TraceState
import OpenTelemetry.Util
data ExceptionClassification
=
ErrorException
|
RecordedException
|
IgnoredException
deriving (Int -> ExceptionClassification -> ShowS
[ExceptionClassification] -> ShowS
ExceptionClassification -> String
(Int -> ExceptionClassification -> ShowS)
-> (ExceptionClassification -> String)
-> ([ExceptionClassification] -> ShowS)
-> Show ExceptionClassification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExceptionClassification -> ShowS
showsPrec :: Int -> ExceptionClassification -> ShowS
$cshow :: ExceptionClassification -> String
show :: ExceptionClassification -> String
$cshowList :: [ExceptionClassification] -> ShowS
showList :: [ExceptionClassification] -> ShowS
Show, ExceptionClassification -> ExceptionClassification -> Bool
(ExceptionClassification -> ExceptionClassification -> Bool)
-> (ExceptionClassification -> ExceptionClassification -> Bool)
-> Eq ExceptionClassification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExceptionClassification -> ExceptionClassification -> Bool
== :: ExceptionClassification -> ExceptionClassification -> Bool
$c/= :: ExceptionClassification -> ExceptionClassification -> Bool
/= :: ExceptionClassification -> ExceptionClassification -> Bool
Eq, Eq ExceptionClassification
Eq ExceptionClassification =>
(ExceptionClassification -> ExceptionClassification -> Ordering)
-> (ExceptionClassification -> ExceptionClassification -> Bool)
-> (ExceptionClassification -> ExceptionClassification -> Bool)
-> (ExceptionClassification -> ExceptionClassification -> Bool)
-> (ExceptionClassification -> ExceptionClassification -> Bool)
-> (ExceptionClassification
-> ExceptionClassification -> ExceptionClassification)
-> (ExceptionClassification
-> ExceptionClassification -> ExceptionClassification)
-> Ord ExceptionClassification
ExceptionClassification -> ExceptionClassification -> Bool
ExceptionClassification -> ExceptionClassification -> Ordering
ExceptionClassification
-> ExceptionClassification -> ExceptionClassification
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ExceptionClassification -> ExceptionClassification -> Ordering
compare :: ExceptionClassification -> ExceptionClassification -> Ordering
$c< :: ExceptionClassification -> ExceptionClassification -> Bool
< :: ExceptionClassification -> ExceptionClassification -> Bool
$c<= :: ExceptionClassification -> ExceptionClassification -> Bool
<= :: ExceptionClassification -> ExceptionClassification -> Bool
$c> :: ExceptionClassification -> ExceptionClassification -> Bool
> :: ExceptionClassification -> ExceptionClassification -> Bool
$c>= :: ExceptionClassification -> ExceptionClassification -> Bool
>= :: ExceptionClassification -> ExceptionClassification -> Bool
$cmax :: ExceptionClassification
-> ExceptionClassification -> ExceptionClassification
max :: ExceptionClassification
-> ExceptionClassification -> ExceptionClassification
$cmin :: ExceptionClassification
-> ExceptionClassification -> ExceptionClassification
min :: ExceptionClassification
-> ExceptionClassification -> ExceptionClassification
Ord)
data ExceptionResponse = ExceptionResponse
{ ExceptionResponse -> ExceptionClassification
exceptionClassification :: !ExceptionClassification
, ExceptionResponse -> AttributeMap
exceptionAdditionalAttributes :: !AttributeMap
}
type ExceptionHandler = SomeException -> Maybe ExceptionResponse
defaultExceptionResponse :: ExceptionResponse
defaultExceptionResponse :: ExceptionResponse
defaultExceptionResponse = ExceptionClassification -> AttributeMap -> ExceptionResponse
ExceptionResponse ExceptionClassification
ErrorException AttributeMap
forall k v. HashMap k v
H.empty
data SpanExporter = SpanExporter
{ SpanExporter
-> HashMap InstrumentationLibrary (Vector ImmutableSpan)
-> IO ExportResult
spanExporterExport :: HashMap InstrumentationLibrary (Vector ImmutableSpan) -> IO ExportResult
, SpanExporter -> IO ShutdownResult
spanExporterShutdown :: IO ShutdownResult
, SpanExporter -> IO FlushResult
spanExporterForceFlush :: IO FlushResult
}
data SpanProcessor = SpanProcessor
{ SpanProcessor -> ImmutableSpan -> Context -> IO ()
spanProcessorOnStart :: ImmutableSpan -> Context -> IO ()
, SpanProcessor -> ImmutableSpan -> IO ()
spanProcessorOnEnd :: ImmutableSpan -> IO ()
, SpanProcessor -> IO ShutdownResult
spanProcessorShutdown :: IO ShutdownResult
, SpanProcessor -> IO FlushResult
spanProcessorForceFlush :: IO FlushResult
}
data TracerProvider = TracerProvider
{ TracerProvider -> ImmutableSpan -> Context -> IO ()
tracerProviderOnStart :: !(ImmutableSpan -> Context -> IO ())
, TracerProvider -> ImmutableSpan -> IO ()
tracerProviderOnEnd :: !(ImmutableSpan -> IO ())
, TracerProvider -> Vector SpanProcessor
tracerProviderProcessors :: !(Vector SpanProcessor)
, TracerProvider -> Bool
tracerProviderHasProcessor :: !Bool
, TracerProvider -> IdGenerator
tracerProviderIdGenerator :: !IdGenerator
, TracerProvider -> Sampler
tracerProviderSampler :: !Sampler
, TracerProvider -> MaterializedResources
tracerProviderResources :: !MaterializedResources
, TracerProvider -> AttributeLimits
tracerProviderAttributeLimits :: !AttributeLimits
, TracerProvider -> SpanLimits
tracerProviderSpanLimits :: !SpanLimits
, TracerProvider -> TextMapPropagator
tracerProviderPropagators :: !TextMapPropagator
, TracerProvider -> [ExceptionHandler]
tracerProviderExceptionHandlers :: ![ExceptionHandler]
, TracerProvider -> IORef Bool
tracerProviderIsShutdown :: !(IORef Bool)
, TracerProvider -> IORef (HashMap InstrumentationLibrary Tracer)
tracerProviderTracerCache :: !(IORef (HashMap InstrumentationLibrary Tracer))
}
data Tracer = Tracer
{ Tracer -> InstrumentationLibrary
tracerName :: {-# UNPACK #-} !InstrumentationLibrary
, Tracer -> TracerProvider
tracerProvider :: !TracerProvider
, Tracer -> [ExceptionHandler]
tracerExceptionHandlers :: ![ExceptionHandler]
, Tracer -> AttributeLimits
tracerSpanAttributeLimits :: !AttributeLimits
, Tracer -> AttributeLimits
tracerEventAttributeLimits :: !AttributeLimits
, Tracer -> AttributeLimits
tracerLinkAttributeLimits :: !AttributeLimits
, Tracer -> Int
tracerEventCountLimit :: {-# UNPACK #-} !Int
, Tracer -> Int
tracerLinkCountLimit :: {-# UNPACK #-} !Int
}
instance Show Tracer where
showsPrec :: Int -> Tracer -> ShowS
showsPrec Int
d Tracer {tracerName :: Tracer -> InstrumentationLibrary
tracerName = InstrumentationLibrary
name} = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"Tracer {tracerName = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InstrumentationLibrary -> ShowS
forall a. Show a => a -> ShowS
shows InstrumentationLibrary
name ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"}"
resolveException :: Tracer -> SomeException -> ExceptionResponse
resolveException :: Tracer -> SomeException -> ExceptionResponse
resolveException Tracer
t SomeException
ex =
let allHandlers :: [ExceptionHandler]
allHandlers = Tracer -> [ExceptionHandler]
tracerExceptionHandlers Tracer
t [ExceptionHandler] -> [ExceptionHandler] -> [ExceptionHandler]
forall a. Semigroup a => a -> a -> a
<> TracerProvider -> [ExceptionHandler]
tracerProviderExceptionHandlers (Tracer -> TracerProvider
tracerProvider Tracer
t)
in [ExceptionHandler] -> ExceptionResponse
go [ExceptionHandler]
allHandlers
where
go :: [ExceptionHandler] -> ExceptionResponse
go [] = ExceptionResponse
defaultExceptionResponse
go (ExceptionHandler
h : [ExceptionHandler]
hs) = case ExceptionHandler
h SomeException
ex of
Just ExceptionResponse
resp -> ExceptionResponse
resp
Maybe ExceptionResponse
Nothing -> [ExceptionHandler] -> ExceptionResponse
go [ExceptionHandler]
hs
data NewLink = NewLink
{ NewLink -> SpanContext
linkContext :: !SpanContext
, NewLink -> AttributeMap
linkAttributes :: AttributeMap
}
deriving (Int -> NewLink -> ShowS
[NewLink] -> ShowS
NewLink -> String
(Int -> NewLink -> ShowS)
-> (NewLink -> String) -> ([NewLink] -> ShowS) -> Show NewLink
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NewLink -> ShowS
showsPrec :: Int -> NewLink -> ShowS
$cshow :: NewLink -> String
show :: NewLink -> String
$cshowList :: [NewLink] -> ShowS
showList :: [NewLink] -> ShowS
Show)
data Link = Link
{ Link -> SpanContext
frozenLinkContext :: !SpanContext
, Link -> Attributes
frozenLinkAttributes :: Attributes
}
deriving (Int -> Link -> ShowS
[Link] -> ShowS
Link -> String
(Int -> Link -> ShowS)
-> (Link -> String) -> ([Link] -> ShowS) -> Show Link
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Link -> ShowS
showsPrec :: Int -> Link -> ShowS
$cshow :: Link -> String
show :: Link -> String
$cshowList :: [Link] -> ShowS
showList :: [Link] -> ShowS
Show)
data SpanArguments = SpanArguments
{ SpanArguments -> SpanKind
kind :: SpanKind
, SpanArguments -> AttributeMap
attributes :: AttributeMap
,
SpanArguments -> [NewLink]
links :: [NewLink]
, SpanArguments -> Maybe Timestamp
startTime :: Maybe Timestamp
}
data SpanKind
=
Server
|
Client
|
Producer
|
Consumer
|
Internal
deriving (Int -> SpanKind -> ShowS
[SpanKind] -> ShowS
SpanKind -> String
(Int -> SpanKind -> ShowS)
-> (SpanKind -> String) -> ([SpanKind] -> ShowS) -> Show SpanKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SpanKind -> ShowS
showsPrec :: Int -> SpanKind -> ShowS
$cshow :: SpanKind -> String
show :: SpanKind -> String
$cshowList :: [SpanKind] -> ShowS
showList :: [SpanKind] -> ShowS
Show, SpanKind -> SpanKind -> Bool
(SpanKind -> SpanKind -> Bool)
-> (SpanKind -> SpanKind -> Bool) -> Eq SpanKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SpanKind -> SpanKind -> Bool
== :: SpanKind -> SpanKind -> Bool
$c/= :: SpanKind -> SpanKind -> Bool
/= :: SpanKind -> SpanKind -> Bool
Eq)
data SpanStatus
=
Unset
|
Error Text
|
Ok
deriving (Int -> SpanStatus -> ShowS
[SpanStatus] -> ShowS
SpanStatus -> String
(Int -> SpanStatus -> ShowS)
-> (SpanStatus -> String)
-> ([SpanStatus] -> ShowS)
-> Show SpanStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SpanStatus -> ShowS
showsPrec :: Int -> SpanStatus -> ShowS
$cshow :: SpanStatus -> String
show :: SpanStatus -> String
$cshowList :: [SpanStatus] -> ShowS
showList :: [SpanStatus] -> ShowS
Show, SpanStatus -> SpanStatus -> Bool
(SpanStatus -> SpanStatus -> Bool)
-> (SpanStatus -> SpanStatus -> Bool) -> Eq SpanStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SpanStatus -> SpanStatus -> Bool
== :: SpanStatus -> SpanStatus -> Bool
$c/= :: SpanStatus -> SpanStatus -> Bool
/= :: SpanStatus -> SpanStatus -> Bool
Eq)
instance Ord SpanStatus where
compare :: SpanStatus -> SpanStatus -> Ordering
compare SpanStatus
Unset SpanStatus
Unset = Ordering
EQ
compare SpanStatus
Unset (Error Text
_) = Ordering
LT
compare SpanStatus
Unset SpanStatus
Ok = Ordering
LT
compare (Error Text
_) SpanStatus
Unset = Ordering
GT
compare (Error Text
_) (Error Text
_) = Ordering
EQ
compare (Error Text
_) SpanStatus
Ok = Ordering
LT
compare SpanStatus
Ok SpanStatus
Unset = Ordering
GT
compare SpanStatus
Ok (Error Text
_) = Ordering
GT
compare SpanStatus
Ok SpanStatus
Ok = Ordering
EQ
data SpanHot = SpanHot
{ SpanHot -> Text
hotName :: !Text
, SpanHot -> OptionalTimestamp
hotEnd :: !OptionalTimestamp
, SpanHot -> Attributes
hotAttributes :: !Attributes
, SpanHot -> AppendOnlyBoundedCollection Link
hotLinks :: !(AppendOnlyBoundedCollection Link)
, SpanHot -> AppendOnlyBoundedCollection Event
hotEvents :: !(AppendOnlyBoundedCollection Event)
, SpanHot -> SpanStatus
hotStatus :: !SpanStatus
}
deriving (Int -> SpanHot -> ShowS
[SpanHot] -> ShowS
SpanHot -> String
(Int -> SpanHot -> ShowS)
-> (SpanHot -> String) -> ([SpanHot] -> ShowS) -> Show SpanHot
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SpanHot -> ShowS
showsPrec :: Int -> SpanHot -> ShowS
$cshow :: SpanHot -> String
show :: SpanHot -> String
$cshowList :: [SpanHot] -> ShowS
showList :: [SpanHot] -> ShowS
Show)
data ImmutableSpan = ImmutableSpan
{ ImmutableSpan -> SpanContext
spanContext :: !SpanContext
, ImmutableSpan -> SpanKind
spanKind :: !SpanKind
, ImmutableSpan -> Timestamp
spanStart :: !Timestamp
, ImmutableSpan -> Maybe Span
spanParent :: !(Maybe Span)
, ImmutableSpan -> Tracer
spanTracer :: !Tracer
, ImmutableSpan -> IORef SpanHot
spanHot :: {-# UNPACK #-} !(IORef SpanHot)
}
instance Show ImmutableSpan where
showsPrec :: Int -> ImmutableSpan -> ShowS
showsPrec Int
d ImmutableSpan
imm =
Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"ImmutableSpan {spanContext = "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> SpanContext -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 (ImmutableSpan -> SpanContext
spanContext ImmutableSpan
imm)
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
", spanKind = "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> SpanKind -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 (ImmutableSpan -> SpanKind
spanKind ImmutableSpan
imm)
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
", spanStart = "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Timestamp -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 (ImmutableSpan -> Timestamp
spanStart ImmutableSpan
imm)
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
", spanHot = <IORef>}"
data Span
= Span !ImmutableSpan
| FrozenSpan !SpanContext
| Dropped !SpanContext
instance Show Span where
showsPrec :: Int -> Span -> ShowS
showsPrec Int
d (Span ImmutableSpan
imm) = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"Span " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ImmutableSpan -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ImmutableSpan
imm
showsPrec Int
d (FrozenSpan SpanContext
ctx) = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"FrozenSpan " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> SpanContext -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 SpanContext
ctx
showsPrec Int
d (Dropped SpanContext
ctx) = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"Dropped " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> SpanContext -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 SpanContext
ctx
data FrozenOrDropped = SpanFrozen | SpanDropped deriving (Int -> FrozenOrDropped -> ShowS
[FrozenOrDropped] -> ShowS
FrozenOrDropped -> String
(Int -> FrozenOrDropped -> ShowS)
-> (FrozenOrDropped -> String)
-> ([FrozenOrDropped] -> ShowS)
-> Show FrozenOrDropped
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FrozenOrDropped -> ShowS
showsPrec :: Int -> FrozenOrDropped -> ShowS
$cshow :: FrozenOrDropped -> String
show :: FrozenOrDropped -> String
$cshowList :: [FrozenOrDropped] -> ShowS
showList :: [FrozenOrDropped] -> ShowS
Show, FrozenOrDropped -> FrozenOrDropped -> Bool
(FrozenOrDropped -> FrozenOrDropped -> Bool)
-> (FrozenOrDropped -> FrozenOrDropped -> Bool)
-> Eq FrozenOrDropped
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FrozenOrDropped -> FrozenOrDropped -> Bool
== :: FrozenOrDropped -> FrozenOrDropped -> Bool
$c/= :: FrozenOrDropped -> FrozenOrDropped -> Bool
/= :: FrozenOrDropped -> FrozenOrDropped -> Bool
Eq)
toImmutableSpan :: MonadIO m => Span -> m (Either FrozenOrDropped ImmutableSpan)
toImmutableSpan :: forall (m :: * -> *).
MonadIO m =>
Span -> m (Either FrozenOrDropped ImmutableSpan)
toImmutableSpan (Span ImmutableSpan
imm) = Either FrozenOrDropped ImmutableSpan
-> m (Either FrozenOrDropped ImmutableSpan)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ImmutableSpan -> Either FrozenOrDropped ImmutableSpan
forall a b. b -> Either a b
Right ImmutableSpan
imm)
toImmutableSpan (FrozenSpan SpanContext
_ctx) = Either FrozenOrDropped ImmutableSpan
-> m (Either FrozenOrDropped ImmutableSpan)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either FrozenOrDropped ImmutableSpan
-> m (Either FrozenOrDropped ImmutableSpan))
-> Either FrozenOrDropped ImmutableSpan
-> m (Either FrozenOrDropped ImmutableSpan)
forall a b. (a -> b) -> a -> b
$ FrozenOrDropped -> Either FrozenOrDropped ImmutableSpan
forall a b. a -> Either a b
Left FrozenOrDropped
SpanFrozen
toImmutableSpan (Dropped SpanContext
_ctx) = Either FrozenOrDropped ImmutableSpan
-> m (Either FrozenOrDropped ImmutableSpan)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either FrozenOrDropped ImmutableSpan
-> m (Either FrozenOrDropped ImmutableSpan))
-> Either FrozenOrDropped ImmutableSpan
-> m (Either FrozenOrDropped ImmutableSpan)
forall a b. (a -> b) -> a -> b
$ FrozenOrDropped -> Either FrozenOrDropped ImmutableSpan
forall a b. a -> Either a b
Left FrozenOrDropped
SpanDropped
{-# INLINE toImmutableSpan #-}
defaultTraceFlags :: TraceFlags
defaultTraceFlags :: TraceFlags
defaultTraceFlags = Word8 -> TraceFlags
TraceFlags Word8
0
{-# INLINE defaultTraceFlags #-}
isSampled :: TraceFlags -> Bool
isSampled :: TraceFlags -> Bool
isSampled (TraceFlags Word8
flags) = Word8
flags Word8 -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
`testBit` Int
0
{-# INLINE isSampled #-}
setSampled :: TraceFlags -> TraceFlags
setSampled :: TraceFlags -> TraceFlags
setSampled (TraceFlags Word8
flags) = Word8 -> TraceFlags
TraceFlags (Word8
flags Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`setBit` Int
0)
{-# INLINE setSampled #-}
unsetSampled :: TraceFlags -> TraceFlags
unsetSampled :: TraceFlags -> TraceFlags
unsetSampled (TraceFlags Word8
flags) = Word8 -> TraceFlags
TraceFlags (Word8
flags Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`clearBit` Int
0)
isRandom :: TraceFlags -> Bool
isRandom :: TraceFlags -> Bool
isRandom (TraceFlags Word8
flags) = Word8
flags Word8 -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
`testBit` Int
1
{-# INLINE isRandom #-}
setRandom :: TraceFlags -> TraceFlags
setRandom :: TraceFlags -> TraceFlags
setRandom (TraceFlags Word8
flags) = Word8 -> TraceFlags
TraceFlags (Word8
flags Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`setBit` Int
1)
{-# INLINE setRandom #-}
unsetRandom :: TraceFlags -> TraceFlags
unsetRandom :: TraceFlags -> TraceFlags
unsetRandom (TraceFlags Word8
flags) = Word8 -> TraceFlags
TraceFlags (Word8
flags Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`clearBit` Int
1)
{-# INLINE unsetRandom #-}
traceFlagsValue :: TraceFlags -> Word8
traceFlagsValue :: TraceFlags -> Word8
traceFlagsValue (TraceFlags Word8
flags) = Word8
flags
traceFlagsFromWord8 :: Word8 -> TraceFlags
traceFlagsFromWord8 :: Word8 -> TraceFlags
traceFlagsFromWord8 = Word8 -> TraceFlags
TraceFlags
data SpanContext = SpanContext
{ SpanContext -> TraceFlags
traceFlags :: {-# UNPACK #-} !TraceFlags
, SpanContext -> Bool
isRemote :: !Bool
, SpanContext -> TraceId
traceId :: {-# UNPACK #-} !TraceId
, SpanContext -> SpanId
spanId :: {-# UNPACK #-} !SpanId
, SpanContext -> TraceState
traceState :: !TraceState
}
deriving (Int -> SpanContext -> ShowS
[SpanContext] -> ShowS
SpanContext -> String
(Int -> SpanContext -> ShowS)
-> (SpanContext -> String)
-> ([SpanContext] -> ShowS)
-> Show SpanContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SpanContext -> ShowS
showsPrec :: Int -> SpanContext -> ShowS
$cshow :: SpanContext -> String
show :: SpanContext -> String
$cshowList :: [SpanContext] -> ShowS
showList :: [SpanContext] -> ShowS
Show, SpanContext -> SpanContext -> Bool
(SpanContext -> SpanContext -> Bool)
-> (SpanContext -> SpanContext -> Bool) -> Eq SpanContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SpanContext -> SpanContext -> Bool
== :: SpanContext -> SpanContext -> Bool
$c/= :: SpanContext -> SpanContext -> Bool
/= :: SpanContext -> SpanContext -> Bool
Eq)
newtype NonRecordingSpan = NonRecordingSpan SpanContext
data NewEvent = NewEvent
{ NewEvent -> Text
newEventName :: Text
, NewEvent -> AttributeMap
newEventAttributes :: AttributeMap
, NewEvent -> Maybe Timestamp
newEventTimestamp :: Maybe Timestamp
}
data Event = Event
{ Event -> Text
eventName :: Text
, Event -> Attributes
eventAttributes :: Attributes
, Event -> Timestamp
eventTimestamp :: Timestamp
}
deriving (Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Event -> ShowS
showsPrec :: Int -> Event -> ShowS
$cshow :: Event -> String
show :: Event -> String
$cshowList :: [Event] -> ShowS
showList :: [Event] -> ShowS
Show)
class ToEvent a where
toEvent :: a -> Event
data SamplingResult
=
Drop
|
RecordOnly
|
RecordAndSample
deriving (Int -> SamplingResult -> ShowS
[SamplingResult] -> ShowS
SamplingResult -> String
(Int -> SamplingResult -> ShowS)
-> (SamplingResult -> String)
-> ([SamplingResult] -> ShowS)
-> Show SamplingResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SamplingResult -> ShowS
showsPrec :: Int -> SamplingResult -> ShowS
$cshow :: SamplingResult -> String
show :: SamplingResult -> String
$cshowList :: [SamplingResult] -> ShowS
showList :: [SamplingResult] -> ShowS
Show, SamplingResult -> SamplingResult -> Bool
(SamplingResult -> SamplingResult -> Bool)
-> (SamplingResult -> SamplingResult -> Bool) -> Eq SamplingResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SamplingResult -> SamplingResult -> Bool
== :: SamplingResult -> SamplingResult -> Bool
$c/= :: SamplingResult -> SamplingResult -> Bool
/= :: SamplingResult -> SamplingResult -> Bool
Eq)
data SamplingDecision = SamplingDecision
{ SamplingDecision -> SamplingResult
samplingOutcome :: !SamplingResult
, SamplingDecision -> AttributeMap
samplingAttributes :: !AttributeMap
, SamplingDecision -> TraceState
samplingTraceState :: !TraceState
}
data Sampler
=
AlwaysOnSampler
|
AlwaysOffSampler
|
TraceIdRatioSampler !Double !Word64 !Attribute
|
ParentBasedSampler !ParentBasedOptions
|
AlwaysRecordSampler !Sampler
|
CustomSampler !Text !(Context -> TraceId -> Text -> SpanArguments -> InstrumentationLibrary -> IO SamplingDecision)
data ParentBasedOptions = ParentBasedOptions
{ ParentBasedOptions -> Sampler
rootSampler :: Sampler
, ParentBasedOptions -> Sampler
remoteParentSampled :: Sampler
, ParentBasedOptions -> Sampler
remoteParentNotSampled :: Sampler
, ParentBasedOptions -> Sampler
localParentSampled :: Sampler
, ParentBasedOptions -> Sampler
localParentNotSampled :: Sampler
}
data SpanLimits = SpanLimits
{ SpanLimits -> Maybe Int
spanAttributeValueLengthLimit :: Maybe Int
, SpanLimits -> Maybe Int
spanAttributeCountLimit :: Maybe Int
, SpanLimits -> Maybe Int
eventCountLimit :: Maybe Int
, SpanLimits -> Maybe Int
eventAttributeCountLimit :: Maybe Int
, SpanLimits -> Maybe Int
linkCountLimit :: Maybe Int
, SpanLimits -> Maybe Int
linkAttributeCountLimit :: Maybe Int
}
deriving (Int -> SpanLimits -> ShowS
[SpanLimits] -> ShowS
SpanLimits -> String
(Int -> SpanLimits -> ShowS)
-> (SpanLimits -> String)
-> ([SpanLimits] -> ShowS)
-> Show SpanLimits
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SpanLimits -> ShowS
showsPrec :: Int -> SpanLimits -> ShowS
$cshow :: SpanLimits -> String
show :: SpanLimits -> String
$cshowList :: [SpanLimits] -> ShowS
showList :: [SpanLimits] -> ShowS
Show, SpanLimits -> SpanLimits -> Bool
(SpanLimits -> SpanLimits -> Bool)
-> (SpanLimits -> SpanLimits -> Bool) -> Eq SpanLimits
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SpanLimits -> SpanLimits -> Bool
== :: SpanLimits -> SpanLimits -> Bool
$c/= :: SpanLimits -> SpanLimits -> Bool
/= :: SpanLimits -> SpanLimits -> Bool
Eq)
defaultSpanLimits :: SpanLimits
defaultSpanLimits :: SpanLimits
defaultSpanLimits =
Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> SpanLimits
SpanLimits
Maybe Int
forall a. Maybe a
Nothing
Maybe Int
forall a. Maybe a
Nothing
Maybe Int
forall a. Maybe a
Nothing
Maybe Int
forall a. Maybe a
Nothing
Maybe Int
forall a. Maybe a
Nothing
Maybe Int
forall a. Maybe a
Nothing
type Lens s t a b = forall f. (Functor f) => (a -> f b) -> s -> f t
type Lens' s a = Lens s s a a
getSpanContext :: (MonadIO m) => Span -> m SpanContext
getSpanContext :: forall (m :: * -> *). MonadIO m => Span -> m SpanContext
getSpanContext (Span ImmutableSpan
imm) = SpanContext -> m SpanContext
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ImmutableSpan -> SpanContext
spanContext ImmutableSpan
imm)
getSpanContext (FrozenSpan SpanContext
c) = SpanContext -> m SpanContext
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SpanContext
c
getSpanContext (Dropped SpanContext
c) = SpanContext -> m SpanContext
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SpanContext
c
{-# INLINE getSpanContext #-}