Skip to content

docs(tutorial): fix stale registry prose in instrumenting HTTP server - #3126

Open
santhiprakash wants to merge 2 commits into
prometheus:mainfrom
santhiprakash:fix-2815-tutorial-instrumenting-server
Open

santhiprakash wants to merge 2 commits into
prometheus:mainfrom
santhiprakash:fix-2815-tutorial-instrumenting-server

Conversation

@santhiprakash

Copy link
Copy Markdown
Contributor

Fixes #2815

Problem

Three statements in docs/tutorials/instrumenting_http_server_in_go.md still describe the pre-292bc326 version of the sample, which used the default registry. The sample code in the same file now builds a custom registry (prometheus.NewRegistry() + promauto.With(reg) + promhttp.HandlerFor(reg, …)), so the prose contradicts the code it explains.

Fix

  • "The prometheus.MustRegister function registers the pingCounter with the default registry." → promauto.With(reg).NewCounter() creates the counter and registers it with reg.
  • "promhttp.Handler() … exposes the metrics registered in the default registry." → promhttp.HandlerFor(reg, promhttp.HandlerOpts{}) exposes the metrics registered in reg.
  • "The default registry comes with a collector for Go runtime metrics…" → the custom registry does not include Go runtime metrics by default; to collect them, register collectors.NewGoCollector() with the registry (the non-deprecated API, per @jan--f's review on docs: fix stale explanation in instrumenting HTTP server tutorial #3074).

Verification

  • Ran the tutorial's exact sample code against client_golang v1.24.1: after three /ping requests, GET /metrics returns only ping_request_count 3 — no go_*, promhttp_*, or process_* series, confirming prometheus.NewRegistry() starts empty.
  • make check (mdox fmt + link validation) passes.
  • The diff is limited to the three sentences; ping_metric.png and the Help string it renders are left unchanged so the text and image stay in sync.

Notes / Risks

  • Docs-only change.
  • The go_*/promhttp_* series visible in ping_metric.png predate the custom-registry switch; happy to regenerate the screenshot in a follow-up if you'd like it to match the current sample.

Assistance

AI-assisted. I wrote and verified this change.

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 prometheus#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 prometheus#2815

Signed-off-by: Santhi Prakash <b.santhiprakash@gmail.com>

@jan--f jan--f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar isses as the previous PR: this change is good but now the screenshots are inconsistent.

And one more request to please not let the maintainers discuss with agents.

The sample uses a custom registry (prometheus.NewRegistry()) which
starts empty, so register collectors.NewGoCollector() explicitly —
the same pattern as docs/guides/go-application.md — and regenerate
ping_metric.png from the tutorial's real output so the prose, code
and screenshot agree again.

Signed-off-by: Santhi Prakash <b.santhiprakash@gmail.com>
@santhiprakash
santhiprakash force-pushed the fix-2815-tutorial-instrumenting-server branch 2 times, most recently from 44203b6 to 37a0145 Compare October 28, 2026 16:03
@santhiprakash

Copy link
Copy Markdown
Contributor Author

Done in 37a0145 — main() now registers collectors.NewGoCollector() on the custom registry (same pattern as docs/guides/go-application.md), so the go_* metrics are what the sample code really emits, and ping_metric.png is regenerated from the tutorial’s actual output (go build + 3× /ping + /metrics on client_golang v1.25.0; the page now ends at ping_request_count 3). make check passes; the zizmor failure is pre-existing on main (upstream workflow findings).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix errors in tutorial/instrumenting HTTP server

2 participants