Skip to content

transport-metrics

Comprehensive, cardinality-safe Prometheus instrumentation for Go services.

Expose a scrapeable Prometheus /metrics endpoint — pre-wired with Go runtime, process, and build-info collectors — from a single Register call, with zero external infrastructure. Watch heap, goroutines, GC and uptime; catch leaks with go tool pprof.

mux := http.NewServeMux()
// mount your API handlers…
_ = metrics.Register(mux, metrics.WithMiddleware(authMiddleware))

Prometheus, complementing OTel

This is the pull/scrape (Prometheus) counterpart to the push (OTel) go/observability modules. It complements them — use Prometheus for local, single-binary tools and classic scrape stacks; OTel when you have an OTLP pipeline; both if you like. See Pull vs push.

Highlights

  • Zero infra. Scrape or curl /metrics locally — no collector required.
  • Runtime out of the box. Go + process + build_info collectors on a private registry by default.
  • Guarded posture. Pass your auth middleware, or bind to loopback — never an open port. Mounting unguarded logs a warning.
  • Lean core, opt-in weight. Core is prometheus/client_golang + stdlib only; go/transport (standalone server), gRPC and OTel live in opt-in subpackages.

What this does not do

No push — no OTLP exporter, no remote write, no Pushgateway. No configuration file, environment variables or flags; it is configured in Go. No instrumentation of outbound HTTP or gRPC calls. The full inventory, marked deliberate or not-yet-built, is What transport-metrics does not do.

Where next


Part of the phpboyscout Go toolkit.

Further reading

The blog carries a curated route through this subject: Building a web service in Go collects everything written about it, ordered so you can start at the beginning rather than newest-first.

Ask phpbotscout

phpbotscout

He answers questions about the projects over on the Discord, citing the docs where they already cover it, and offering to raise an issue where they don't. Bring a bug, an idea, or a questionable engineering decision.

Join the Discord