Enable pprof¶
net/http/pprof gives you live heap, goroutine, allocation, CPU and trace profiles
— the tools you reach for when a long-running service leaks memory or goroutines.
transport-metrics can mount it behind the same guard as /metrics.
It is off by default — pprof exposes rich internals, so turning it on is a deliberate choice.
Enable it¶
metrics.Register(mux,
metrics.WithMiddleware(authMiddleware), // guards pprof too
metrics.WithPprof(),
)
This mounts, under /debug/pprof/ (override with WithPprofPath):
| Route | Profile |
|---|---|
/debug/pprof/ |
index; also serves the named profiles (heap, goroutine, allocs, block, mutex, threadcreate) |
/debug/pprof/cmdline |
the process command line |
/debug/pprof/profile |
a CPU profile (?seconds=N) |
/debug/pprof/symbol |
symbol lookup |
/debug/pprof/trace |
an execution trace (?seconds=N) |
Every one is wrapped by the middleware you passed — pprof is never exposed unguarded.
Use it¶
Point go tool pprof straight at the live endpoint (with whatever auth your guard
needs, e.g. a bearer token via -H):
# a heap profile
go tool pprof http://localhost:8080/debug/pprof/heap
# 30s of CPU
go tool pprof http://localhost:8080/debug/pprof/profile?seconds=30
# goroutine dump in the browser
go tool pprof -http=: http://localhost:8080/debug/pprof/goroutine
Keep it off the open internet¶
Because pprof can dump memory contents and block the process (CPU/trace profiles), treat the guard as mandatory. For a local debugging aid, prefer a standalone metrics server bound to loopback so the profiles are reachable only from the host.