HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulewai-middleware-prometheus-1.0.0.1Haskell2010

Network.Wai.Middleware.Prometheus

This module provides Network.Wai middlware for exporting Prometheus metrics and for instrumenting WAI applications.

  • 1 type
  • 8 values
datadata PrometheusSettings
#

Settings that control the behavior of the Prometheus middleware.

Constructors

Instances1Default
methoddef :: a
#

The default value for this type.

valueinstrumentHandlerValue
  1. :: (Request -> Text)

    The function used to derive the "handler" value in Prometheus

  2. -> Application

    The app to instrument

  3. -> Application

    The instrumented app

#

This function is used to populate the handler label of all Prometheus metrics recorded by this library.

If you use this function you will likely want to override the default value of prometheusInstrumentApp to be false so that your app does not get double instrumented.

WARNING: If you have ResponseRaw values in your API, consider using instrumentHandlerValueWithFilter ignoreRawResponses instead.

ResponseRaw values have two parts: an action that can be executed to construct a Response, and a pure "backup" Response in case the computation fails. Since the pure selectors like responseStatus are pure and it makes no sense for them to call the action, they just go to the backup response and pull the value from that:

responseStatus (ResponseRaw ...
  (ResponseBuilder (Status 500 "blargh") ... ...))
== Status {statusCode = 500, statusMessage = "blargh"}

This is often not what you want. For example, if you have an end-point for establishing websocket connections that has a backup response with status 5xx, every websocket connection request, whether successful or not, will register as an internal server error.

This helper therefore filters out all raw requests so they won't create any metrics. Use together with instrumentHandlerValueWithFilter.

valueinstrumentApp
  1. :: Text

    The label used to identify this app

  2. -> Application

    The app to instrument

  3. -> Application

    The instrumented app

#

Instrument a WAI app with the default WAI metrics.

If you use this function you will likely want to override the default value of prometheusInstrumentApp to be false so that your app does not get double instrumented.

valueinstrumentIO
  1. :: Text

    The label used to identify this IO operation

  2. -> IO a

    The IO action to instrument

  3. -> IO a

    The instrumented app

#

Instrument an IO action with timing metrics. This function can be used if you would like to get more fine grained metrics, for instance this can be used to instrument individual end points.

If you use this function you will likely want to override the default value of prometheusInstrumentApp to be false so that your app does not get double instrumented.

WAI Application that serves the Prometheus metrics page regardless of what the request is.