packages feed

prometheus-wai 0.2.0.1 → 0.2.0.2

raw patch · API changes only · 4 files changed · show whitespace changes · browse prometheus-wai-0.2.0.2

+23/−6 lines, 4 filessetup-changedPVP: minor bump suggested

API changes (from Hackage documentation)

0 removed, 1 added, 0 changed

API additions: PVP suggests at least a minor version bump

+ System.Metrics.Prometheus.Wai.Middleware: instrumentWaiMiddlewareWith :: (Request -> Bool) -> WaiMetrics -> Middleware

Files

CHANGELOG.md view
@@ -1,5 +1,12 @@ # Changelog +## [0.2.0.2] - 2026-05-05++### Changed++* The first metrics sample is now collected lazily on the first request rather+  than eagerly at startup when caching is enabled.+ ## [0.2.0.1] - 2025-12-18  ### Changed
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
prometheus-wai.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.36.1.+-- This file has been generated from package.yaml by hpack version 0.38.3. -- -- see: https://github.com/sol/hpack  name:           prometheus-wai-version:        0.2.0.1+version:        0.2.0.2 description:    Prometheus metrics for WAI applications homepage:       https://github.com/NorfairKing/prometheus-wai#readme bug-reports:    https://github.com/NorfairKing/prometheus-wai/issues
src/System/Metrics/Prometheus/Wai/Middleware.hs view
@@ -6,6 +6,7 @@   ( registerWaiMetrics,     WaiMetrics (..),     instrumentWaiMiddleware,+    instrumentWaiMiddlewareWith,     combineRegistrySample,     MetricsEndpoint (..),     defaultMetricsEndpoint,@@ -81,7 +82,13 @@  -- | Record the given Wai metrics in a middleware. instrumentWaiMiddleware :: WaiMetrics -> Wai.Middleware-instrumentWaiMiddleware WaiMetrics {..} application request sendResponse =+instrumentWaiMiddleware = instrumentWaiMiddlewareWith (const True)++-- | Like 'instrumentWaiMiddleware' but only instruments requests for which the+-- predicate returns 'True'. Requests that return 'False' are passed through+-- without recording any metrics.+instrumentWaiMiddlewareWith :: (Wai.Request -> Bool) -> WaiMetrics -> Wai.Middleware+instrumentWaiMiddlewareWith shouldRecord WaiMetrics {..} application request sendResponse =   let isWebSocketsReq =         lookup "upgrade" (Wai.requestHeaders request) == Just "websocket"       shouldInstrument =@@ -91,6 +98,7 @@         -- Moreover, the 'latency' will be 'how long the connection was open'         -- which is also useless.         not isWebSocketsReq+          && shouldRecord request    in if shouldInstrument         then do           begin <- getMonotonicTimeNSec@@ -158,9 +166,9 @@   -- might as well lift already.   liftIO $ do     mCache <- forM metricsEndpointCacheDurationNanos $ \cacheDurationNanos -> do-      begin <- getMonotonicTimeNSec-      firstSample <- metricsEndpointSample-      var <- newMVar (begin, firstSample)+      -- Use timestamp 0 so the cache is expired on first use, collecting the+      -- first sample lazily on the first request rather than at startup.+      var <- newMVar (0, Prometheus.RegistrySample M.empty)       pure (cacheDurationNanos, var)      let sampleWithCache :: IO Prometheus.RegistrySample