From f82723848c07216a66f704aca70976a9ba937e3c Mon Sep 17 00:00:00 2001 From: Santhi Prakash Date: Thu, 13 Aug 2026 19:34:45 +0000 Subject: [PATCH] docs: fix stale explanation in instrumenting HTTP server tutorial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Problem: explanation paragraph references MustRegister, promhttp.Handler(), and 'default registry' — none of which are used in the code (changed to custom registry in Nov 2022). Also claims Go runtime metrics appear because of the 'default registry' collector, but the code uses prometheus.NewRegistry() which does not include them. - Fix: update the prose to match the actual code (promauto.With(reg), promhttp.HandlerFor, custom registry). Fix Help text inconsistency ('request' vs 'requests' between code blocks). Replace the misleading Go runtime metrics claim with an accurate note about custom registries. - Verification: diff read against upstream/main (12e2edf8). Fixes #2815. Signed-off-by: Santhi Prakash --- docs/tutorials/instrumenting_http_server_in_go.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/instrumenting_http_server_in_go.md b/docs/tutorials/instrumenting_http_server_in_go.md index 1d6a74ba0..72392cb65 100644 --- a/docs/tutorials/instrumenting_http_server_in_go.md +++ b/docs/tutorials/instrumenting_http_server_in_go.md @@ -84,9 +84,9 @@ func main() { } ``` -The `prometheus.MustRegister` function registers the pingCounter with the default registry. +The `promauto.With(reg).NewCounter()` function creates the counter and registers it with the custom registry. To expose the metrics, the Go Prometheus client library provides the promhttp package. -`promhttp.Handler()` provides an `http.Handler` which exposes the metrics registered in the default registry. +`promhttp.HandlerFor(reg, promhttp.HandlerOpts{})` provides an `http.Handler` which exposes the metrics registered in the given registry. The sample code is now: @@ -111,7 +111,7 @@ func newMetrics(reg prometheus.Registerer) *metrics { pingCounter: promauto.With(reg).NewCounter( prometheus.CounterOpts{ Name: "ping_request_count", - Help: "No of request handled by Ping handler", + Help: "No of requests handled by Ping handler", }), } return m @@ -147,7 +147,7 @@ Now hit the localhost:8090/ping endpoint a couple of times and then send a reque Here, the `ping_request_count` shows that the `/ping` endpoint was called 3 times. -The default registry comes with a collector for Go runtime metrics, and that is why we see other metrics like `go_threads`, `go_goroutines`, etc. +The code above uses a custom registry (`prometheus.NewRegistry()`), which does not include Go runtime metrics by default. To also collect Go runtime metrics, register `prometheus.NewGoCollector()` with the registry. We have built our first metric exporter. Let’s update our Prometheus config to scrape the metrics from our server.