snap-error-collector-1.0.0: Collect errors in batches and dispatch them

Safe HaskellNone
LanguageHaskell2010

Snap.ErrorCollector

Description

snap-error-collector extends a Snap application with the ability to monitor requests for uncaught exceptions. All routes are wrapped with an exception handler, and exceptions are queued (and optionally filtered). Periodically, the exception queue is flushed via an IO computation - you can use this to send emails, notify yourself on Twitter, increment counters, etc.

Example:

import Snap.ErrorCollector

initApp :: Initializer MyApp MyApp
initApp = do
  ...
  collectErrors ErrorCollectorConfig
    { ecFlush = emailOpsTeam
    , ecFlushInterval = 60000000
    , ecFilter = const True
    }

Synopsis

Documentation

collectErrors :: ErrorCollectorConfig -> Initializer b v () Source

Wrap a Snap website to collect errors.

data LoggedException Source

An exception logged by snap-error-collector, tagged with the request that caused the exception, and the time the exception occured.

data ErrorCollectorConfig Source

How snap-error-collector should run.

Constructors

ErrorCollectorConfig 

Fields

ecFlush :: !(UTCTime -> Seq LoggedException -> IO ())

An IO action to perform with the list of exceptions that were thrown during the last collection period. The computation will be executed asynchronously, but subsequent collections will not be flushed until outstanding computations complete.

ecFlushInterval :: !Int

How long (in microseconds) to collect exceptions for until they are sent (via ecFlush). You can pass '0' here, in which case snap-error-collector will idle until an exception happens.

ecFilter :: !(SomeException -> Bool)

A filter on which exceptions should be collected. SomeException's that return true under this predicate will be collected, other errors will be not.

basicConfig :: (UTCTime -> Seq LoggedException -> IO ()) -> ErrorCollectorConfig Source

A convenient constructor for ErrorCollectorConfig that collects all exceptions and flushes the queue every minute. You have to supply the IO action to run when the queue is flushed.