Automatically wrap a Plumber API app, adding metrics for HTTP request count and duration, and then expose them on a /metrics endpoint.

The endpoint will check the METRICS_HTTP_AUTHORIZATION environment variable, and if present will use it as the expected Authorization header of the request to the /metrics endpoint. This can be used to implement basic HTTP authentication for access to runtime metrics.

register_plumber_metrics(app, registry = global_registry())

Arguments

app

A Plumber router object.

registry

A Registry object. See registry().

Value

A modified Plumber router.

Examples

if (requireNamespace("plumber", quietly = TRUE)) { app <- plumber::plumber$new() # Normally this is plumber::plumb(). app <- register_plumber_metrics(app) if (FALSE) { app$run() } }
#> Warning: `plumber` is deprecated as of plumber 1.0.0. #> Please use `Plumber` instead.