Similar to promhttp.InstrumentHandlerCounter, but upper-cases method names instead of lower-casing them. Unlike promhttp.InstrumentHandlerCounter, this assumes a "code" and "method" label is present, and will panic otherwise.
(counter *prometheus.CounterVec, next http.Handler)
| 51 | // Unlike promhttp.InstrumentHandlerCounter, this assumes a "code" and "method" |
| 52 | // label is present, and will panic otherwise. |
| 53 | func instrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler) http.HandlerFunc { |
| 54 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 55 | d := newDelegator(w) |
| 56 | next.ServeHTTP(d, r) |
| 57 | counter.With(prometheus.Labels{ |
| 58 | "code": metrics.SanitizeCode(d.status), |
| 59 | "method": metrics.SanitizeMethod(r.Method), |
| 60 | }).Inc() |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | func newDelegator(w http.ResponseWriter) *delegator { |
| 65 | return &delegator{ |
no test coverage detected