From 6b043738dd84f00796388f5ce4b450646eaf0404 Mon Sep 17 00:00:00 2001 From: Santhi Prakash Date: Sun, 4 Oct 2026 17:23:25 +0000 Subject: [PATCH] docs(tutorial): fix stale registry prose in instrumenting HTTP server Problem: three sentences in the instrumenting HTTP server tutorial still describe the pre-292bc326 sample that used the default registry, while the code now builds a custom registry (prometheus.NewRegistry() + promauto.With(reg) + promhttp.HandlerFor). Fix: rewrite the three sentences to match the shipped sample code, and use collectors.NewGoCollector() (non-deprecated) for the Go-collector hint, per jan--f's review on #3074. Verification: ran the tutorial's sample code with client_golang v1.24.1; /metrics emits only ping_request_count (no go_*/promhttp_* series). make check passes. Fixes #2815 Signed-off-by: Santhi Prakash --- docs/tutorials/instrumenting_http_server_in_go.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/tutorials/instrumenting_http_server_in_go.md b/docs/tutorials/instrumenting_http_server_in_go.md index 1d6a74ba0..18ea51c8c 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 pingCounter and registers it with the `reg` 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 `reg` registry. The sample code is now: @@ -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 like `go_threads` and `go_goroutines`, register `collectors.NewGoCollector()` (from `github.com/prometheus/client_golang/prometheus/collectors`) with the registry. We have built our first metric exporter. Let’s update our Prometheus config to scrape the metrics from our server.