patrol: Sentry SDK

[ exceptions, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

Patrol is a Sentry SDK.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
pedanticDisabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1, 0.0.2, 0.0.3, 0.0.4, 0.1.0.1, 1.0.0.0, 1.0.0.1, 1.0.0.2, 1.0.0.3, 1.0.0.4, 1.0.0.5, 1.0.0.6, 1.0.0.7, 1.0.0.8, 1.0.0.9, 1.0.0.10, 1.0.0.11, 1.0.1.0, 1.1.0.0, 1.2.0.0, 1.2.0.1, 1.2.0.2, 1.2.0.3, 1.2.0.4, 1.2.0.5 (info)
Change log CHANGELOG.md
Dependencies aeson (>=2.1.2 && <2.2 || >=2.2.2 && <2.3 || >=2.3.0 && <2.4), base (>=4.20 && <4.23), bytestring (>=0.12.0.2 && <0.13), case-insensitive (>=1.2.1 && <1.3), containers (>=0.7 && <0.9), exceptions (>=0.10.7 && <0.11), http-client (>=0.7.17 && <0.8), http-client-tls (>=0.3.6.4 && <0.4 || >=0.4.0 && <0.5), http-types (>=0.12.4 && <0.13), network-uri (>=2.6.4.2 && <2.8), text (>=2.1 && <2.2), time (>=1.12.2 && <1.13 || >=1.14 && <1.16), uuid (>=1.3.15 && <1.4) [details]
License MIT
Author
Maintainer Taylor Fausak
Uploaded by fozworth at 2026-05-22T13:41:00Z
Category Exceptions
Source repo head: git clone https://github.com/tfausak/patrol
Distributions LTSHaskell:1.1.0.0, Stackage:1.2.0.4
Downloads 2037 total (68 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for patrol-1.2.0.5

[back to package description]

Patrol

CI Hackage

Patrol is a Sentry SDK for Haskell.

Usage

Basic exception reporting

The simplest way to report an exception is with captureException. It reads the DSN from the SENTRY_DSN environment variable.

import qualified Patrol

main :: IO ()
main = do
  result <- doSomething
  case result of
    Left err -> do
      _ <- Patrol.captureException err
      pure ()
    Right val -> use val

Customizing the event

Use captureExceptionWith to add tags, set the environment, attach user info, or otherwise modify the event before it is sent.

import qualified Data.Map as Map
import qualified Data.Text as Text
import qualified Patrol
import qualified Patrol.Type.Dsn as Dsn
import qualified Patrol.Type.Event as Event
import qualified Patrol.Type.Level as Level
import qualified Patrol.Type.User as User

reportException :: Dsn.Dsn -> SomeException -> IO ()
reportException dsn err = do
  _ <- Patrol.captureExceptionWith modifyEvent dsn err
  pure ()
  where
    modifyEvent :: Event.Event -> IO Event.Event
    modifyEvent event = pure event
      { Event.tags = Map.fromList
          [ (Text.pack "component", Text.pack "api")
          ]
      , Event.level = Just Level.Warning
      , Event.user = Just User.empty
          { User.id = Text.pack "user-123"
          , User.email = Text.pack "user@example.com"
          }
      , Event.environment = Text.pack "staging"
      }

Warp middleware

Here is an example of a Warp middleware that reports non-success HTTP responses to Sentry.

import qualified Data.Map as Map
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Network.HTTP.Types as Http
import qualified Network.Wai as Wai
import qualified Patrol
import qualified Patrol.Type.Dsn as Dsn
import qualified Patrol.Type.Event as Event

sentryMiddleware :: Dsn.Dsn -> Wai.Middleware
sentryMiddleware dsn app request respond =
  app request $ \response -> do
    let status = Wai.responseStatus response
    Control.Monad.when (Http.statusCode status >= 500) $ do
      let err = userError $ "HTTP " <> show (Http.statusCode status)
      _ <- Patrol.captureExceptionWith (modifyEvent request status) dsn err
      pure ()
    respond response
  where
    modifyEvent :: Wai.Request -> Http.Status -> Event.Event -> IO Event.Event
    modifyEvent request status event = pure event
      { Event.tags = Map.fromList
          [ (Text.pack "path", Text.decodeUtf8 (Wai.rawPathInfo request))
          , (Text.pack "status_code", Text.pack (show (Http.statusCode status)))
          ]
      }