Metrics and expvar
Use `expvar` for lightweight built-in metrics when simple counters and gauges are enough, and keep metric ownership explicit.
Canonical guidance
- instrument where ownership is clear
- choose stable names and units
- use
expvarwhen simple built-in publishing is enough
Use when
- basic counters and gauges
- debug endpoints
- small services that do not need heavier observability stacks
Avoid
- publishing metrics from arbitrary call sites with no owner
- unstable metric names
- assuming
expvarreplaces logs, traces, and profiles
Preferred pattern
- publish a small set of process and request metrics under one debug surface
Anti-pattern
- adding many unlabeled counters with vague names because metrics might be useful later
Explanation: This is tempting because counters are easy to add, but low-quality metrics create noise without helping operations.
Why
- observability helps only when metric meaning is owned and stable
Related pages
Sources
- expvar package - Go Team
- net/http package - Go Team