From acf557a71129ca9efa9c52739260e06665bcd4e8 Mon Sep 17 00:00:00 2001 From: brommell <46051666+brommell@users.noreply.github.com> Date: Thu, 29 Oct 2026 01:11:24 +0200 Subject: [PATCH] docs: explain how to drop the client-controlled host label The host label comes from the request Host header, so a server reachable without a filtering proxy gets a new set of series for every Host value a client sends. It is a default label and cannot be removed from the label set, but a LabelFuncs entry returning an empty value drops it in Prometheus. Document that next to LabelFuncs. Co-Authored-By: Claude Opus 5.5 --- prometheus.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/prometheus.go b/prometheus.go index 3e46796..aba99df 100644 --- a/prometheus.go +++ b/prometheus.go @@ -53,6 +53,14 @@ type MiddlewareConfig struct { // LabelFuncs allows adding custom labels in addition to default labels. When key has same name with default label // it replaces default one. + // + // The default `host` label is taken from the request `Host` header, which the client controls. When the server is + // reachable without a proxy that only passes known hosts, every distinct value creates new metrics. To drop the + // label, return an empty value; Prometheus treats a label with an empty value as absent: + // + // LabelFuncs: map[string]echoprometheus.LabelValueFunc{ + // "host": func(c *echo.Context, err error) string { return "" }, + // } LabelFuncs map[string]LabelValueFunc // HistogramOptsFunc allows to change options for metrics of type histogram before metric is registered to Registerer