hs-opentelemetry-api
Copyright(c) Ian Duncan 2021
LicenseBSD-3
MaintainerIan Duncan
Stabilityexperimental
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

OpenTelemetry.Util

Description

 
Synopsis

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

Instances details
(HasConstructor x, HasConstructor y) => HasConstructor (x :+: y) Source # 
Instance details

Defined in OpenTelemetry.Util

Methods

genericConstrName :: (x :+: y) x0 -> String

Constructor c => HasConstructor (C1 c f) Source # 
Instance details

Defined in OpenTelemetry.Util

Methods

genericConstrName :: C1 c f x -> String

HasConstructor f => HasConstructor (D1 c f) Source # 
Instance details

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

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

appendOnlyBoundedCollectionValues :: AppendOnlyBoundedCollection a -> Vector a Source #

O(n). Materializes the difference list into a Vector via fromListN. Called once per span at export time.

Since: 0.0.1.0

Vectors

chunksOfV :: Int -> Vector a -> [Vector a] Source #

Split a vector into chunks of at most n elements. Used by batch processors.

Since: 0.4.0.0