snap-error-collector-1.1.1: 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
    , ecUpperBound = 1000
    }

emailOpsTeam :: UTCTime -> Seq LoggedException -> Int -> IO '()'
emailOpsTeam = ...

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 -> Int -> IO ())

An IO action to perform with the list of exceptions that were thrown during the last collection period, and the amount of exceptions that had to be dropped. 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.

ecExceptionUpperBound :: !Int

The maximum amount of exceptions to store within ecFlushInterval. Currently, if more exceptions than this are thrown, subsequent exceptions will be dropped on the floor (and a counter incremented). This allows you to maintain predictable memory usage if something in the rest of your application goes horribly wrong.

If dropping exceptions on the floor doesn't suit your needs, please open a bug report on the issue tracker and we can discuss alternatives.

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

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