Copyright | Copyright 2022 Shea Levy. |
---|---|
License | Apache-2.0 |
Maintainer | shea@shealevy.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This is the primary module needed to write new EventBackend
s.
Synopsis
- data EventBackend m r s = EventBackend {
- newEventImpl :: !(forall f. s f -> m (EventImpl m r f))
- newOnceFlag :: !(m (OnceFlag m))
- data EventImpl m r f = EventImpl {
- referenceImpl :: !r
- addFieldImpl :: !(f -> m ())
- addParentImpl :: !(r -> m ())
- addProximateImpl :: !(r -> m ())
- finalizeImpl :: !(m ())
- failImpl :: !(Maybe SomeException -> m ())
- newtype OnceFlag m = OnceFlag {
- checkAndSet :: m FlagState
- data FlagState
- runOnce :: Monad m => OnceFlag m -> m () -> m ()
- hoistOnceFlag :: (forall x. f x -> g x) -> OnceFlag f -> OnceFlag g
- alwaysNewOnceFlag :: Applicative m => OnceFlag m
- newOnceFlagIO :: IO (OnceFlag IO)
Documentation
data EventBackend m r s Source #
A backend for creating Event
s.
Different EventBackend
s will be used to emit instrumentation to
different systems. Multiple backends can be combined with
pairEventBackend
.
A simple EventBackend
for logging to a Handle
can be
created with jsonHandleBackend
.
Typically the entrypoint for some eventuo11y-instrumented code will
take an EventBackend
, polymorphic in r
and possibly m
. Calling
code can use subEventBackend
to place the resulting
events in its hierarchy.
From an EventBackend
, new events can be created via selectors
(of type s f
for some field type f
), typically with the
resource-safe allocation functions.
Selectors are values which designate the general category of event
being created, as well as the type of fields that can be added to it.
For example, a web service's selector type may have a ServicingRequest
constructor, whose field type includes a ResponseCode
constructor which
records the HTTP status code.
Selectors are intended to be of a domain specific type per unit of
functionality within an instrumented codebase, implemented as a GADT
(but see DynamicEventSelector
for a generic option).
Implementations must ensure that EventBackend
s and their underlying Event
s
are safe to use across threads.
m
- The monad we're instrumenting in.
r
- The type of event references used in this
EventBackend
. Seereference
. s
- The type of event selectors.
EventBackend | |
|
The internal implementation of an Event
.
All fields have corresponding event manipulation functions,
except that finalizeImpl
and failImpl
can assume that they will only ever be called
once (i.e., EventImpl
implementations do not have to implement locking internally).
EventImpl | |
|
OnceFlags
Generic helper to make operations idempotent.
A flag to ensure only one operation from some class is performed, once.
Typically consumed via runOnce
OnceFlag | |
|
The state of a OnceFlag
NewlySet | The flag was not set, but is now |
AlreadySet | The flag was already set |
runOnce :: Monad m => OnceFlag m -> m () -> m () Source #
Run an operation if no other operations using this
OnceFlag
have run.
Hoist a OnceFlag
along a given natural transformation into a new monad.
alwaysNewOnceFlag :: Applicative m => OnceFlag m Source #