| Copyright | (c) Ian Duncan 2021 |
|---|---|
| License | BSD-3 |
| Maintainer | Ian Duncan |
| Stability | experimental |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | None |
| Language | Haskell2010 |
OpenTelemetry.Util
Description
Synopsis
- constructorName :: (HasConstructor (Rep a), Generic a) => a -> String
- class HasConstructor (f :: Type -> Type)
- getThreadId :: ThreadId -> Int
- bracketError :: MonadUnliftIO m => m a -> (Maybe SomeException -> a -> m b) -> (a -> m c) -> m c
- casModifyIORef_ :: IORef a -> (a -> a) -> IO ()
- casReadModifyIORef_ :: IORef a -> (a -> a) -> IO a
- data AppendOnlyBoundedCollection a
- emptyAppendOnlyBoundedCollection :: Int -> AppendOnlyBoundedCollection a
- appendToBoundedCollection :: AppendOnlyBoundedCollection a -> a -> AppendOnlyBoundedCollection a
- appendOnlyBoundedCollectionSize :: AppendOnlyBoundedCollection a -> Int
- appendOnlyBoundedCollectionValues :: AppendOnlyBoundedCollection a -> Vector a
- appendOnlyBoundedCollectionDroppedElementCount :: AppendOnlyBoundedCollection a -> Int
- chunksOfV :: Int -> Vector a -> [Vector a]
Documentation
constructorName :: (HasConstructor (Rep a), Generic a) => a -> String Source #
Useful for annotating which constructor in an ADT was chosen
Since: 0.1.0.0
class HasConstructor (f :: Type -> Type) Source #
Detect a constructor from any datatype which derives Generic
Since: 0.0.1.0
Minimal complete definition
genericConstrName
Instances
| (HasConstructor x, HasConstructor y) => HasConstructor (x :+: y) Source # | |
Defined in OpenTelemetry.Util Methods genericConstrName :: (x :+: y) x0 -> String | |
| Constructor c => HasConstructor (C1 c f) Source # | |
Defined in OpenTelemetry.Util Methods genericConstrName :: C1 c f x -> String | |
| HasConstructor f => HasConstructor (D1 c f) Source # | |
Defined in OpenTelemetry.Util Methods genericConstrName :: D1 c f x -> String | |
getThreadId :: ThreadId -> Int Source #
Get an int representation of a thread id
Since: 0.0.1.0
bracketError :: MonadUnliftIO m => m a -> (Maybe SomeException -> a -> m b) -> (a -> m c) -> m c Source #
Like bracket, but provides the after function with information about
uncaught exceptions.
Since: 0.1.0.0
Lock-free IORef modification
casModifyIORef_ :: IORef a -> (a -> a) -> IO () Source #
CAS-based strict IORef modification that avoids the closure and pair
allocation of atomicModifyIORef'.
atomicModifyIORef' ref (old -> (f old, ())) allocates a closure capturing
the modification function, a (new, ()) pair, and (in the GHC RTS) a thunk
indirection that is CAS'd into the MutVar.
This function instead reads the current value, applies f strictly, and
performs a compare-and-swap. On success (the common, uncontended case), zero
intermediate heap objects are allocated beyond the new value itself. On CAS
failure (concurrent modification), it retries. Safe because f is pure.
Use for hot-path span operations (addAttribute, addEvent, setStatus, etc.) where the IORef is rarely contended and the modification is a cheap record update.
Since: 0.0.1.0
casReadModifyIORef_ :: IORef a -> (a -> a) -> IO a Source #
CAS-based IORef modification that also reads the old value before the swap.
Performs a strict read, applies f to decide both the new value and a
pre-swap result, then CAS's the new value in. Returns the old value (before
modification) on success. Retries on CAS failure.
Used by endSpan where we need to atomically set spanEnd and also read the
(unchanged) Tracer field to obtain the processor vector, all without
navigating the Tracer inside an atomicModifyIORef' closure.
Since: 0.0.1.0
Data structures
data AppendOnlyBoundedCollection a Source #
Bounded append-only collection.
Two constructors: EmptyBounded carries only the capacity (2 words: info
pointer + unboxed Int), avoiding all allocation for the common case of spans
with 0 events or 0 links. BoundedCollection uses a difference list for
O(1) pure append and O(n) materialization at export time.
Safe with atomicModifyIORef' because all operations are pure.
Since: 0.0.1.0
Instances
| Show a => Show (AppendOnlyBoundedCollection a) Source # | |
Defined in OpenTelemetry.Util Methods showsPrec :: Int -> AppendOnlyBoundedCollection a -> ShowS # show :: AppendOnlyBoundedCollection a -> String # showList :: [AppendOnlyBoundedCollection a] -> ShowS # | |
emptyAppendOnlyBoundedCollection Source #
Arguments
| :: Int | Maximum size |
| -> AppendOnlyBoundedCollection a |
Initialize a bounded collection that admits a maximum size
Since: 0.0.1.0
appendToBoundedCollection :: AppendOnlyBoundedCollection a -> a -> AppendOnlyBoundedCollection a Source #
Append an element. O(1): transitions from EmptyBounded to
BoundedCollection on first append, then difference-list composition.
Returns the collection unchanged (with incremented drop count) when full.
Since: 0.0.1.0
appendOnlyBoundedCollectionSize :: AppendOnlyBoundedCollection a -> Int Source #
Since: 0.0.1.0
appendOnlyBoundedCollectionValues :: AppendOnlyBoundedCollection a -> Vector a Source #
appendOnlyBoundedCollectionDroppedElementCount :: AppendOnlyBoundedCollection a -> Int Source #
Since: 0.0.1.0